mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-15 18:42:23 +00:00
MPPasswordInputController completion callback refactoring
Changed the completion callback definition to take a KPKCompositeKey pointer instead of a password string and keyfile URL. This is a intermedate step to support key files with TouchID unlock. The next step is to make KPKCompositeKey conform to the NSCoding protocol. The serialized data can then be stored instead of the password.
This commit is contained in:
@@ -108,13 +108,13 @@ FOUNDATION_EXPORT NSString *const MPDocumentGroupKey;
|
||||
/**
|
||||
* Decrypts the database with the given password and keyfile
|
||||
*
|
||||
* @param password The password to unlock the db with, can be nil. This is not the same as an empty string @""
|
||||
* @param keyFileURL URL for the keyfile to use, can be nil
|
||||
* @param compositeKey The CompositeKey to unlock the db.
|
||||
* @param keyFileURL URL for the keyfile that was used to create the compositeKey. Can be nil.
|
||||
* @param error Pointer to an NSError pointer of error reporting.
|
||||
*
|
||||
* @return YES if the document was unlocked sucessfully, NO otherwise. Consult the error object for details
|
||||
*/
|
||||
- (BOOL)unlockWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error;
|
||||
- (BOOL)unlockWithPassword:(KPKCompositeKey *)compositeKey keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error;
|
||||
/**
|
||||
* Changes the password of the database. Some sanity checks are applied and the change is aborted if the new values aren't valid
|
||||
*
|
||||
|
||||
@@ -429,7 +429,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
|
||||
MPPasswordInputController *passwordInputController = [[MPPasswordInputController alloc] init];
|
||||
[passwordInputController requestPasswordWithMessage:NSLocalizedString(@"EXTERN_CHANGE_OF_MASTERKEY", @"The master key was changed by an external program!")
|
||||
cancelLabel:NSLocalizedString(@"ABORT_MERGE_KEEP_MINE", @"Button label to abort a merge on a file with changed master key!")
|
||||
completionHandler:^BOOL(NSString *password, NSURL *keyURL, BOOL didCancel, NSError *__autoreleasing *error) {
|
||||
completionHandler:^BOOL(KPKCompositeKey *compositeKey, NSURL* keyURL, BOOL didCancel, NSError *__autoreleasing *error) {
|
||||
[self.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)];
|
||||
if(!didCancel) {
|
||||
NSData *keyFileData = keyURL ? [NSData dataWithContentsOfURL:keyURL] : nil;
|
||||
@@ -501,7 +501,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)unlockWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error{
|
||||
- (BOOL)unlockWithPassword:(KPKCompositeKey *)compositeKey keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error{
|
||||
// TODO: Make this API asynchronous
|
||||
NSData *keyFileData = keyFileURL ? [NSData dataWithContentsOfURL:keyFileURL] : nil;
|
||||
|
||||
|
||||
@@ -329,12 +329,11 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
|
||||
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) {
|
||||
[self.passwordInputController requestPasswordWithMessage:message cancelLabel:nil completionHandler:^BOOL(KPKCompositeKey* compositeKey, NSURL* keyURL, BOOL didCancel, NSError *__autoreleasing *error) {
|
||||
if(didCancel) {
|
||||
return NO;
|
||||
}
|
||||
return [((MPDocument *)self.document) unlockWithPassword:password keyFileURL:keyURL error:error];
|
||||
|
||||
return [((MPDocument *)self.document) unlockWithPassword:compositeKey keyFileURL:keyURL error:error ];
|
||||
} forFile:fileURL];
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,13 @@
|
||||
//
|
||||
|
||||
#import "MPViewController.h"
|
||||
#import "KeePassKit/KeePassKit.h"
|
||||
|
||||
@class KPKCompositeKey;
|
||||
|
||||
@interface MPPasswordInputController : MPViewController <NSTouchBarDelegate>
|
||||
|
||||
typedef BOOL (^passwordInputCompletionBlock)(NSString *password, NSURL *keyURL, BOOL didCancel, NSError *__autoreleasing*error);
|
||||
typedef BOOL (^passwordInputCompletionBlock)(KPKCompositeKey *key, NSURL* keyFileURL, BOOL didCancel, NSError *__autoreleasing*error);
|
||||
|
||||
- (void)requestPasswordWithMessage:(NSString *)message cancelLabel:(NSString *)cancelLabel completionHandler:(passwordInputCompletionBlock)completionHandler forFile:(NSURL*) fileURL;
|
||||
|
||||
|
||||
@@ -115,10 +115,6 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
[self _reset];
|
||||
}
|
||||
|
||||
- (void)requestPasswordWithCompletionHandler:(passwordInputCompletionBlock)completionHandler {
|
||||
[self requestPasswordWithMessage:nil cancelLabel:nil completionHandler:completionHandler forFile:nil];
|
||||
}
|
||||
|
||||
#pragma mark Properties
|
||||
- (void)setEnablePassword:(BOOL)enablePassword {
|
||||
if(_enablePassword != enablePassword) {
|
||||
@@ -147,7 +143,10 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
NSString *password = self.enablePassword ? self.passwordTextField.stringValue : nil;
|
||||
|
||||
BOOL cancel = (sender == self.cancelButton);
|
||||
BOOL result = self.completionHandler(password, self.keyPathControl.URL, cancel, &error);
|
||||
NSURL* keyURL = self.keyPathControl.URL;
|
||||
NSData *keyFileData = keyURL ? [NSData dataWithContentsOfURL:keyURL] : nil;
|
||||
KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password keyFileData:keyFileData];
|
||||
BOOL result = self.completionHandler(compositeKey, keyURL, cancel, &error);
|
||||
if(cancel || result) {
|
||||
if(result && self.keyPathControl.URL == nil && self.touchIdEnabled.state) {
|
||||
[self _storePasswordForTouchIDUnlock:password forDatabase:self.absoluteURLString];
|
||||
@@ -412,10 +411,10 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
NSString* password = [self _loadPasswordForTochIDUnlock:self.absoluteURLString];
|
||||
if(password != nil) {
|
||||
NSError* error;
|
||||
self.completionHandler(password, nil, false, &error);
|
||||
KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password keyFileData:nil];
|
||||
self.completionHandler(compositeKey, nil, false, &error);
|
||||
[self _showError:error];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user