CryptoPassphrase  Diff

Differences From Artifact [71047772f8]:

To Artifact [ff4cbf141f]:


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#import "SiteStorage.h"
#import "PasswordGenerator.h"
#import "NewPasswordGenerator.h"
#import "LegacyPasswordGenerator.h"

@interface ShowDetailsController ()
- (NSMutableString*)_generate;
- (void)_generateAndCopy;
- (void)_generateAndShow;
@end

static void
clearNSMutableString(NSMutableString *string)
{







|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#import "SiteStorage.h"
#import "PasswordGenerator.h"
#import "NewPasswordGenerator.h"
#import "LegacyPasswordGenerator.h"

@interface ShowDetailsController ()
- (void)_generateWithCallback: (void(^)(NSMutableString*))block;
- (void)_generateAndCopy;
- (void)_generateAndShow;
@end

static void
clearNSMutableString(NSMutableString *string)
{
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158

159
160
161
162
163









164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191

192
193
194
195
196
197
198
			break;
		}
	}
}

- (void)_generateAndCopy
{
	NSMutableString *password = [self _generate];

	UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
	pasteBoard.string = password;

	clearNSMutableString(password);

	UIAlertController *alert = [UIAlertController
	    alertControllerWithTitle: @"Password Generated"
			     message: @"The password has been copied into the "
				      @"clipboard."
		      preferredStyle: UIAlertControllerStyleAlert];
	[alert addAction:
	    [UIAlertAction actionWithTitle: @"OK"
				     style: UIAlertActionStyleDefault
				   handler: ^ (UIAlertAction *action) {
		[self.navigationController popViewControllerAnimated: YES];
	}]];

	[self presentViewController: alert
			   animated: YES
			 completion: nil];

}

- (void)_generateAndShow
{
	NSMutableString *password = [self _generate];

	UIAlertController *alert = [UIAlertController
	    alertControllerWithTitle: @"Generated Passphrase"
			     message: password
		      preferredStyle: UIAlertControllerStyleAlert];
	[alert addAction:
	    [UIAlertAction actionWithTitle: @"OK"
				     style: UIAlertActionStyleDefault
				   handler: ^ (UIAlertAction *action) {
		[self.navigationController popViewControllerAnimated: YES];

	}]];

	[self presentViewController: alert
			   animated: YES
			 completion: ^ {
		clearNSMutableString(password);

	}];
}

- (NSMutableString*)_generate
{









	id <PasswordGenerator> generator;
	char *passphrase;

	if (_legacy)
		generator = [LegacyPasswordGenerator generator];
	else
		generator = [NewPasswordGenerator generator];

	generator.site = _name;
	generator.length = _length;

	passphrase = of_strdup([self.passphraseField.text UTF8String]);
	@try {
		self.passphraseField.text = @"";
		generator.passphrase = passphrase;

		[generator derivePassword];
	} @finally {
		of_explicit_memset(passphrase, 0, strlen(passphrase));
		free(passphrase);
	}

	NSMutableString *password = [NSMutableString
	    stringWithUTF8String: (char*)generator.output];
	of_explicit_memset(generator.output, 0,
	    strlen((char*)generator.output));


	return password;

}

- (IBAction)remove: (id)sender
{
	UIAlertController *alert = [UIAlertController
	    alertControllerWithTitle: @"Remove Site?"
			     message: @"Do you want to remove this site?"







|
<
|
|

|

|
|
|
|
|
|
|
|
|
|
|

|
|
|
>




|
<
|
|
|
|
|
|
|
|
|
>
|

|
|
|
|
>



|

>
>
>
>
>
>
>
>
>
|
|

|
|
|
|

|
|

|
|
|
|

|
|
|
|
|

|
|
|
|

>
|
>







109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
			break;
		}
	}
}

- (void)_generateAndCopy
{
	[self _generateWithCallback: ^ (NSMutableString *password) {

		UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
		pasteBoard.string = password;

		clearNSMutableString(password);

		UIAlertController *alert = [UIAlertController
		    alertControllerWithTitle: @"Password Generated"
				     message: @"The password has been copied "
					      @"into the clipboard."
			      preferredStyle: UIAlertControllerStyleAlert];
		[alert addAction:
		    [UIAlertAction actionWithTitle: @"OK"
					     style: UIAlertActionStyleDefault
					   handler: ^ (UIAlertAction *action) {
			[self.navigationController popViewControllerAnimated: YES];
		}]];

		[self presentViewController: alert
				   animated: YES
				 completion: nil];
	}];
}

- (void)_generateAndShow
{
	[self _generateWithCallback: ^ (NSMutableString *password) {

		UIAlertController *alert = [UIAlertController
		    alertControllerWithTitle: @"Generated Passphrase"
				     message: password
			      preferredStyle: UIAlertControllerStyleAlert];
		[alert addAction:
		    [UIAlertAction actionWithTitle: @"OK"
					     style: UIAlertActionStyleDefault
					   handler: ^ (UIAlertAction *action) {
			[self.navigationController
			    popViewControllerAnimated: YES];
		}]];

		[self presentViewController: alert
				   animated: YES
				 completion: ^ {
			clearNSMutableString(password);
		}];
	}];
}

- (void)_generateWithCallback: (void(^)(NSMutableString*))block
{
	UIStoryboard *mainStoryboard =
	[UIStoryboard storyboardWithName: @"Main"
				  bundle: nil];
	UIViewController *activityController = [mainStoryboard
	    instantiateViewControllerWithIdentifier: @"activityIndicator"];
	[self.navigationController.view addSubview: activityController.view];

	dispatch_async(dispatch_get_global_queue(
	    DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
		id <PasswordGenerator> generator;
		char *passphrase;

		if (_legacy)
			generator = [LegacyPasswordGenerator generator];
		else
			generator = [NewPasswordGenerator generator];

		generator.site = _name;
		generator.length = _length;

		passphrase = of_strdup([self.passphraseField.text UTF8String]);
		@try {
			self.passphraseField.text = @"";
			generator.passphrase = passphrase;

			[generator derivePassword];
		} @finally {
			of_explicit_memset(passphrase, 0, strlen(passphrase));
			free(passphrase);
		}

		NSMutableString *password = [NSMutableString
		    stringWithUTF8String: (char*)generator.output];
		of_explicit_memset(generator.output, 0,
		    strlen((char*)generator.output));

		activityController.view.hidden = YES;
		block(password);
	});
}

- (IBAction)remove: (id)sender
{
	UIAlertController *alert = [UIAlertController
	    alertControllerWithTitle: @"Remove Site?"
			     message: @"Do you want to remove this site?"