diff --git a/Cartfile b/Cartfile index 0da8ceef..3dd70d0e 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,3 @@ github "sparkle-project/Sparkle" ~> 1.13.1 -github "mstarke/KeePassKit" "32d3bdeb224b5718424b46a5b80c3a66114f6a9b" +github "mstarke/KeePassKit" "aedf5d2c119a710b9e1a1e4323fe43fc6cc542cd" github "mstarke/HNHUi" ~> 1.1 diff --git a/MacPass/Base.lproj/DatabaseSettingsWindow.xib b/MacPass/Base.lproj/DatabaseSettingsWindow.xib index 45b6344d..193a5f0a 100644 --- a/MacPass/Base.lproj/DatabaseSettingsWindow.xib +++ b/MacPass/Base.lproj/DatabaseSettingsWindow.xib @@ -13,6 +13,11 @@ + + + + + @@ -43,7 +48,7 @@ - + @@ -75,7 +80,7 @@ Gw - + @@ -205,11 +210,11 @@ Gw - + - + @@ -217,7 +222,7 @@ Gw - + @@ -225,13 +230,13 @@ Gw - + - + - + @@ -239,7 +244,7 @@ Gw - + @@ -254,7 +259,7 @@ Gw - + @@ -346,7 +351,9 @@ Gw - + + + diff --git a/MacPass/MPDatabaseSettingsWindowController.h b/MacPass/MPDatabaseSettingsWindowController.h index c35a1679..b27d0f95 100644 --- a/MacPass/MPDatabaseSettingsWindowController.h +++ b/MacPass/MPDatabaseSettingsWindowController.h @@ -30,16 +30,16 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) { /* Security Tab */ @property (weak) IBOutlet NSButton *createKeyDerivationParametersButton; -@property (weak) IBOutlet NSPopUpButton *encryptionPopupButton; +@property (weak) IBOutlet NSPopUpButton *cipherPopupButton; @property (weak) IBOutlet NSPopUpButton *keyDerivationPopupButton; @property (weak) IBOutlet NSTabView *keyDerivationSettingsTabView; /* AES */ -@property (weak) IBOutlet NSTextField *AESEncryptionRoundsTextField; +@property (weak) IBOutlet NSTextField *aesEncryptionRoundsTextField; /* Argon2 */ -@property (weak) IBOutlet NSTextField *Argon2ThreadsTextField; -@property (weak) IBOutlet NSTextField *Argon2IterationsTextField; -@property (weak) IBOutlet NSTextField *Argon2MemoryTextField; +@property (weak) IBOutlet NSTextField *argon2ThreadsTextField; +@property (weak) IBOutlet NSTextField *argon2IterationsTextField; +@property (weak) IBOutlet NSTextField *argon2MemoryTextField; /* Advanced Tab*/ @property (weak) IBOutlet NSButton *enableHistoryCheckButton; diff --git a/MacPass/MPDatabaseSettingsWindowController.m b/MacPass/MPDatabaseSettingsWindowController.m index 7cab942c..86347efb 100644 --- a/MacPass/MPDatabaseSettingsWindowController.m +++ b/MacPass/MPDatabaseSettingsWindowController.m @@ -45,7 +45,7 @@ NSAssert(self.document != nil, @"Document needs to be present"); self.sectionTabView.delegate = self; - self.AESEncryptionRoundsTextField.formatter = [[MPNumericalInputFormatter alloc] init]; + self.aesEncryptionRoundsTextField.formatter = [[MPNumericalInputFormatter alloc] init]; NSMenu *kdfMenu = [[NSMenu alloc] init]; NSArray *keyderivations = [KPKKeyDerivation availableKeyDerivations]; @@ -63,7 +63,7 @@ [cipherMenu addItemWithTitle:cipher.name action:NULL keyEquivalent:@""]; cipherMenu.itemArray.lastObject.representedObject = cipher.uuid; } - self.encryptionPopupButton.menu = cipherMenu; + self.cipherPopupButton.menu = cipherMenu; self.keyDerivationSettingsTabView.tabViewItems[0].identifier = [KPKAESKeyDerivation uuid]; self.keyDerivationSettingsTabView.tabViewItems[1].identifier = [KPKArgon2KeyDerivation uuid]; } @@ -116,14 +116,28 @@ metaData.masterKeyChangeEnforcementInterval = enforceMasterKeyChange ? enfoceInterval : -1; metaData.masterKeyChangeRecommendationInterval = recommendMasterKeyChange ? recommendInterval : -1; - /* Security */ - metaData.defaultUserName = self.defaultUsernameTextField.stringValue; - - /* fixme! */ - metaData.keyDerivationParameters = @{ KPKAESRoundsOption : [[KPKNumber alloc] initWithUnsignedInteger64: MAX(0,self.AESEncryptionRoundsTextField.integerValue)]}; - /* Register an action to enable promts when user cloeses without saving */ + /* Security */ + metaData.cipherUUID = self.cipherPopupButton.selectedItem.representedObject; + + KPKAESKeyDerivation *aesKdf = [[KPKAESKeyDerivation alloc] initWithParameters:[KPKAESKeyDerivation defaultParameters]]; + KPKArgon2KeyDerivation *argon2Kdf = [[KPKArgon2KeyDerivation alloc] initWithParameters:[KPKArgon2KeyDerivation defaultParameters]]; + + NSUUID *selectedKdfUUID = self.keyDerivationSettingsTabView.selectedTabViewItem.identifier; + + if([selectedKdfUUID isEqual:aesKdf.uuid]) { + //aesKdf.rounds = self.aesEncryptionRoundsTextField.integerValue; + metaData.keyDerivationParameters = aesKdf.parameters; + } + else if([selectedKdfUUID isEqual:argon2Kdf.uuid]) { + //argon2Kdf.iterations = self.argon2IterationsTextField.integerValue; + //argon2Kdf.memory = self.argon2MemoryTextField.integerValue; + //argon2Kdf.threads = self.argon2ThreadsTextField.integerValue; + metaData.keyDerivationParameters = argon2Kdf.parameters; + } + + /* Changes to metadata aren't backed by undomanager, thus we need to manually set the document dirty */ [self.document updateChangeCount:NSChangeDone]; [self close:nil]; } @@ -135,7 +149,7 @@ - (IBAction)benchmarkRounds:(id)sender { self.createKeyDerivationParametersButton.enabled = NO; [KPKAESKeyDerivation parametersForDelay:1 completionHandler:^(NSDictionary * _Nonnull options) { - self.AESEncryptionRoundsTextField.integerValue = [options[KPKAESRoundsOption] unsignedInteger64Value]; + self.aesEncryptionRoundsTextField.integerValue = [options[KPKAESRoundsOption] unsignedInteger64Value]; self.createKeyDerivationParametersButton.enabled = YES; }]; } @@ -190,41 +204,42 @@ } - (void)_setupSecurityTab:(KPKMetaData *)metaData { - /* Tab 0 AES Tab 1 Argon2 */ + /* + If kdf or cipher is not found, exceptions are thrown. + This should not happen since we should not be able to load a file with unkonw cipher/kdf + */ KPKKeyDerivation *keyDerivation = [KPKKeyDerivation keyDerivationWithParameters:metaData.keyDerivationParameters]; - NSUInteger kdfIndex = [self.keyDerivationPopupButton.menu indexOfItemWithRepresentedObject:keyDerivation.uuid]; [self.keyDerivationPopupButton selectItemAtIndex:kdfIndex]; + [self.keyDerivationSettingsTabView selectTabViewItemWithIdentifier:keyDerivation.uuid]; if([keyDerivation isKindOfClass:[KPKAESKeyDerivation class]]) { - [self.keyDerivationSettingsTabView selectTabViewItemAtIndex:0]; - KPKAESKeyDerivation *aesKDF = (KPKAESKeyDerivation *)keyDerivation; - self.AESEncryptionRoundsTextField.integerValue = aesKDF.rounds; + KPKAESKeyDerivation *aesKdf = (KPKAESKeyDerivation *)keyDerivation; + self.aesEncryptionRoundsTextField.integerValue = aesKdf.rounds; self.createKeyDerivationParametersButton.enabled = YES; - /* fill defautls for Argon2 */ + /* fill defaults for Argon2 */ KPKArgon2KeyDerivation *argon2Kdf = [[KPKArgon2KeyDerivation alloc] initWithParameters:[KPKArgon2KeyDerivation defaultParameters]]; - self.Argon2IterationsTextField.integerValue = argon2Kdf.iterations; - self.Argon2MemoryTextField.integerValue = argon2Kdf.memory; - self.Argon2ThreadsTextField.integerValue = argon2Kdf.threads; + self.argon2IterationsTextField.integerValue = argon2Kdf.iterations; + self.argon2MemoryTextField.integerValue = argon2Kdf.memory; + self.argon2ThreadsTextField.integerValue = argon2Kdf.threads; } else if([keyDerivation isKindOfClass:[KPKArgon2KeyDerivation class]]) { - [self.keyDerivationSettingsTabView selectTabViewItemAtIndex:1]; - KPKArgon2KeyDerivation *argon2KDF = (KPKArgon2KeyDerivation *)keyDerivation; - self.Argon2MemoryTextField.integerValue = argon2KDF.memory; - self.Argon2ThreadsTextField.integerValue = argon2KDF.threads; - self.Argon2IterationsTextField.integerValue = argon2KDF.iterations; + KPKArgon2KeyDerivation *argon2Kdf = (KPKArgon2KeyDerivation *)keyDerivation; + self.argon2MemoryTextField.integerValue = argon2Kdf.memory; + self.argon2ThreadsTextField.integerValue = argon2Kdf.threads; + self.argon2IterationsTextField.integerValue = argon2Kdf.iterations; /* fill defaults for AES */ KPKAESKeyDerivation *aesKdf = [[KPKAESKeyDerivation alloc] initWithParameters:[KPKAESKeyDerivation defaultParameters]]; - self.AESEncryptionRoundsTextField.integerValue = aesKdf.rounds; + self.aesEncryptionRoundsTextField.integerValue = aesKdf.rounds; } else { - + NSAssert(NO, @"Unkown key derivation"); } - NSUInteger cipherIndex = [self.encryptionPopupButton.menu indexOfItemWithRepresentedObject:metaData.cipherUUID]; - [self.encryptionPopupButton selectItemAtIndex:cipherIndex]; + NSUInteger cipherIndex = [self.cipherPopupButton.menu indexOfItemWithRepresentedObject:metaData.cipherUUID]; + [self.cipherPopupButton selectItemAtIndex:cipherIndex]; } - (void)_setupAdvancedTab:(KPKTree *)tree {