Skip to content

Commit

Permalink
Enables TouchID unlock for multiple Database files.
Browse files Browse the repository at this point in the history
This changeset adds the optional fileURL parameter to the
requestPasswordWithMessage function in MPPasswordInputController.
The controller uses this URL as a key to store the encrypted
masterpassword in a dictionary.

In my opinion edge cases like when a file is moved or replaced
do not have to get special handling since the worst case scenario
is that TouchID unlock does not work and users have still the
option to unlock with the masterpassword.

Also this changeset removes the unused
requestPasswordWithCompletionHandler function
  • Loading branch information
Julius Zint committed Feb 14, 2021
1 parent 94956a6 commit 5157ec8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MacPass/MPDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ - (void)_mergeWithContentsFromURL:(NSURL *)url key:(KPKCompositeKey *)key option
}
// just return yes regardless since we will display the sheet again if needed!
return YES;
}];
} forFile:nil];
sheet.contentViewController = passwordInputController;
[self.windowForSheet beginSheet:sheet completionHandler:^(NSModalResponse returnCode) { /* nothing to do, rest is done in other handler! */ }];
}
Expand Down
6 changes: 5 additions & 1 deletion MacPass/MPDocumentWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,17 @@ - (void)showPasswordInputWithMessage:(NSString *)message {
self.passwordInputController = [[MPPasswordInputController alloc] init];
}
self.contentViewController = self.passwordInputController;
NSURL* fileURL = nil;
if(self.document != nil) {
fileURL = [self.document fileURL];
}
[self.passwordInputController requestPasswordWithMessage:message cancelLabel:nil completionHandler:^BOOL(NSString *password, NSURL *keyURL, BOOL didCancel, NSError *__autoreleasing *error) {
if(didCancel) {
return NO;
}
return [((MPDocument *)self.document) unlockWithPassword:password keyFileURL:keyURL error:error];

}];
} forFile:fileURL];
}

- (void)editPassword:(id)sender {
Expand Down
3 changes: 1 addition & 2 deletions MacPass/MPPasswordInputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

typedef BOOL (^passwordInputCompletionBlock)(NSString *password, NSURL *keyURL, BOOL didCancel, NSError *__autoreleasing*error);

- (void)requestPasswordWithCompletionHandler:(passwordInputCompletionBlock)completionHandler;
- (void)requestPasswordWithMessage:(NSString *)message cancelLabel:(NSString *)cancelLabel completionHandler:(passwordInputCompletionBlock)completionHandler;
- (void)requestPasswordWithMessage:(NSString *)message cancelLabel:(NSString *)cancelLabel completionHandler:(passwordInputCompletionBlock)completionHandler forFile:(NSURL*) fileURL;


@end
17 changes: 12 additions & 5 deletions MacPass/MPPasswordInputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ @interface MPPasswordInputController ()

@property (copy) NSString *message;
@property (copy) NSString *cancelLabel;
@property (copy) NSString *absoluteURLString;

@property (assign) BOOL showPassword;
@property (nonatomic, assign) BOOL enablePassword;
Expand Down Expand Up @@ -94,15 +95,21 @@ - (NSResponder *)reconmendedFirstResponder {
return self.passwordTextField;
}

- (void)requestPasswordWithMessage:(NSString *)message cancelLabel:(NSString *)cancelLabel completionHandler:(passwordInputCompletionBlock)completionHandler {
- (void)requestPasswordWithMessage:(NSString *)message cancelLabel:(NSString *)cancelLabel completionHandler:(passwordInputCompletionBlock)completionHandler forFile:(NSURL*) fileURL{
self.completionHandler = completionHandler;
self.message = message;
self.cancelLabel = cancelLabel;
if(fileURL) {
self.absoluteURLString = [fileURL absoluteString];
}
else {
self.absoluteURLString = nil;
}
[self _reset];
}

- (void)requestPasswordWithCompletionHandler:(passwordInputCompletionBlock)completionHandler {
[self requestPasswordWithMessage:nil cancelLabel:nil completionHandler:completionHandler];
[self requestPasswordWithMessage:nil cancelLabel:nil completionHandler:completionHandler forFile:nil];
}

#pragma mark Properties
Expand Down Expand Up @@ -136,7 +143,7 @@ - (IBAction)_submit:(id)sender {
BOOL result = self.completionHandler(password, self.keyPathControl.URL, cancel, &error);
if(cancel || result) {
if(result && self.keyPathControl.URL == nil) {
[self _storePasswordForTouchIDUnlock:password forDatabase:@"DatabaseID"];
[self _storePasswordForTouchIDUnlock:password forDatabase:self.absoluteURLString];
}
return;
}
Expand Down Expand Up @@ -306,7 +313,7 @@ - (void)_reset {
self.enablePassword = YES;
self.passwordTextField.stringValue = @"";
self.messageInfoTextField.hidden = (nil == self.message);
self.touchIdButton.hidden = [touchIDSecuredPasswords valueForKey:@"DatabaseID"] == nil;
self.touchIdButton.hidden = [touchIDSecuredPasswords valueForKey:self.absoluteURLString] == nil;

if(self.message) {
self.messageInfoTextField.stringValue = self.message;
Expand Down Expand Up @@ -392,7 +399,7 @@ - (void)_didSetKeyURL:(NSNotification *)notification {
}

- (IBAction)unlockWithTouchID:(id)sender {
NSString* password = [self _loadPasswordForTochIDUnlock:@"DatabaseID"];
NSString* password = [self _loadPasswordForTochIDUnlock:self.absoluteURLString];
if(password != nil) {
NSError* error;
self.completionHandler(password, nil, false, &error);
Expand Down

0 comments on commit 5157ec8

Please sign in to comment.