Locking a db now requests a password/key if none is set

This commit is contained in:
michael starke
2017-11-21 12:32:41 +01:00
parent 547e61fc4b
commit 775dbd07ee
2 changed files with 19 additions and 16 deletions

View File

@@ -358,7 +358,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
- (void)mergeWithContentsFromURL:(NSURL *)url key:(KPKCompositeKey *)key { - (void)mergeWithContentsFromURL:(NSURL *)url key:(KPKCompositeKey *)key {
NSError *error; NSError *error;
KPKTree *otherTree; KPKTree *otherTree;
if(key) { if(key) {
otherTree = [[KPKTree alloc] initWithContentsOfUrl:url key:key error:&error]; 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!") [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!") 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(NSString *password, NSURL *keyURL, BOOL didCancel, NSError *__autoreleasing *error) {
[self.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)]; [self.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)];
if(!didCancel) { if(!didCancel) {
KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password key:keyURL]; KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password key:keyURL];
[self mergeWithContentsFromURL:url key:compositeKey]; [self mergeWithContentsFromURL:url key:compositeKey];
} }
// just return yes regardless since we will display the sheet again if needed! // just return yes regardless since we will display the sheet again if needed!
return YES; return YES;
}]; }];
sheet.contentViewController = passwordInputController; sheet.contentViewController = passwordInputController;
[self.windowForSheet beginSheet:sheet completionHandler:^(NSModalResponse returnCode) { /* nothing to do, rest is done in other handler! */ }]; [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 addToGroup:parent];
[newEntry.undoManager setActionName:NSLocalizedString(@"NEW_ENTRY", "")]; [newEntry.undoManager setActionName:NSLocalizedString(@"NEW_ENTRY", "")];
[NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidAddEntryNotification [NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidAddEntryNotification
object:self object:self
userInfo:@{ MPDocumentEntryKey: newEntry }]; userInfo:@{ MPDocumentEntryKey: newEntry }];
return newEntry; return newEntry;
} }
@@ -856,10 +856,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
break; break;
case MPActionDatabaseSettings: case MPActionDatabaseSettings:
case MPActionEditPassword: case MPActionEditPassword:
valid &= !self.encrypted;
break;
case MPActionLock: case MPActionLock:
valid &= self.compositeKey.hasPasswordOrKeyFile; valid &= !self.encrypted;
break; break;
case MPActionShowEntryHistory: case MPActionShowEntryHistory:
valid &= (nil != targetEntry); valid &= (nil != targetEntry);

View File

@@ -343,8 +343,13 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
- (IBAction)lock:(id)sender { - (IBAction)lock:(id)sender {
MPDocument *document = [self document]; MPDocument *document = [self document];
if(!document.compositeKey.hasPasswordOrKeyFile) { if(!document.compositeKey) {
return; // Document needs a password/keyfile to be lockable [self editPasswordWithCompetionHandler:^(NSInteger result) {
if(result == NSModalResponseOK) {
[self lock:sender];
}
}];
return;
} }
if(document.encrypted) { if(document.encrypted) {
return; // Document already locked return; // Document already locked