From d5f6317cca540a9995223e2014bf90eee49c26ee Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 20 Dec 2016 11:31:30 +0100 Subject: [PATCH] keyfile storage now gets updated if the keyfile is removed --- MacPass/MPDocument.m | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index c95f40e9..af0786f4 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -361,11 +361,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou self.encryptedData = nil; self.unlockCount += 1; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidUnlockDatabaseNotification object:self]; - /* Make sure to only store */ - MPAppDelegate *delegate = (MPAppDelegate *)[NSApp delegate]; - if(self.compositeKey.hasKeyFile && self.compositeKey.hasPassword && delegate.isAllowedToStoreKeyFile) { - [self _storeKeyURL:keyFileURL]; - } + [self _storeKeyURL:keyFileURL]; } else { self.compositeKey = nil; // clear the key? @@ -768,17 +764,21 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou } - (void)_storeKeyURL:(NSURL *)keyURL { - if(nil == keyURL) { - return; // no URL to store in the first place - } - MPAppDelegate *delegate = (MPAppDelegate *)[NSApp delegate]; - NSAssert(delegate.isAllowedToStoreKeyFile, @"We can only store if we are allowed to do so!"); NSMutableDictionary *keysForFiles = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases] mutableCopy]; - if(nil == keysForFiles) { - keysForFiles = [[NSMutableDictionary alloc] initWithCapacity:1]; + MPAppDelegate *delegate = (MPAppDelegate *)[NSApp delegate]; + if(!delegate.isAllowedToStoreKeyFile || nil == keyURL) { + /* user has removed the keyfile or we should not safe it so remove it */ + [keysForFiles removeObjectForKey:self.fileURL.path.sha1HexDigest]; + } + else if(self.compositeKey.hasPassword && self.compositeKey.hasKeyFile) { + if(nil == keysForFiles) { + keysForFiles = [[NSMutableDictionary alloc] initWithCapacity:1]; + } + keysForFiles[self.fileURL.path.sha1HexDigest] = keyURL.path; + } + if(keysForFiles) { + [[NSUserDefaults standardUserDefaults] setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases]; } - keysForFiles[self.fileURL.path.sha1HexDigest] = keyURL.path; - [[NSUserDefaults standardUserDefaults] setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases]; } - (void)_cleanupLock {