From 775dbd07eed5ae6ba17000597540590ac4f5de69 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 21 Nov 2017 12:32:41 +0100 Subject: [PATCH] Locking a db now requests a password/key if none is set --- MacPass/MPDocument.m | 26 ++++++++++++-------------- MacPass/MPDocumentWindowController.m | 9 +++++++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 2444393e..fe11d10b 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -358,7 +358,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou - (void)mergeWithContentsFromURL:(NSURL *)url key:(KPKCompositeKey *)key { NSError *error; KPKTree *otherTree; - + if(key) { otherTree = [[KPKTree alloc] initWithContentsOfUrl:url key:key error:&error]; } @@ -383,14 +383,14 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou [passwordInputController requestPasswordWithMessage:NSLocalizedString(@"EXTERN_CHANGE_OF_MASTERKEY", @"The master key was changed by an extrenal programm!") 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) { - [self.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)]; - if(!didCancel) { - KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password key:keyURL]; - [self mergeWithContentsFromURL:url key:compositeKey]; - } - // just return yes regardless since we will display the sheet again if needed! - return YES; - }]; + [self.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)]; + if(!didCancel) { + KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password key:keyURL]; + [self mergeWithContentsFromURL:url key:compositeKey]; + } + // just return yes regardless since we will display the sheet again if needed! + return YES; + }]; sheet.contentViewController = passwordInputController; [self.windowForSheet beginSheet:sheet completionHandler:^(NSModalResponse returnCode) { /* nothing to do, rest is done in other handler! */ }]; } @@ -640,8 +640,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou [newEntry addToGroup:parent]; [newEntry.undoManager setActionName:NSLocalizedString(@"NEW_ENTRY", "")]; [NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidAddEntryNotification - object:self - userInfo:@{ MPDocumentEntryKey: newEntry }]; + object:self + userInfo:@{ MPDocumentEntryKey: newEntry }]; return newEntry; } @@ -856,10 +856,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou break; case MPActionDatabaseSettings: case MPActionEditPassword: - valid &= !self.encrypted; - break; case MPActionLock: - valid &= self.compositeKey.hasPasswordOrKeyFile; + valid &= !self.encrypted; break; case MPActionShowEntryHistory: valid &= (nil != targetEntry); diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index dc042a73..072fd208 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -343,8 +343,13 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); - (IBAction)lock:(id)sender { MPDocument *document = [self document]; - if(!document.compositeKey.hasPasswordOrKeyFile) { - return; // Document needs a password/keyfile to be lockable + if(!document.compositeKey) { + [self editPasswordWithCompetionHandler:^(NSInteger result) { + if(result == NSModalResponseOK) { + [self lock:sender]; + } + }]; + return; } if(document.encrypted) { return; // Document already locked