saving key derivation settings for database stubbed

This commit is contained in:
michael starke
2016-11-16 11:02:22 +01:00
parent 7e86984efa
commit e16c99d2ff
4 changed files with 66 additions and 44 deletions

View File

@@ -1,3 +1,3 @@
github "sparkle-project/Sparkle" ~> 1.13.1
github "mstarke/KeePassKit" "32d3bdeb224b5718424b46a5b80c3a66114f6a9b"
github "mstarke/KeePassKit" "aedf5d2c119a710b9e1a1e4323fe43fc6cc542cd"
github "mstarke/HNHUi" ~> 1.1

View File

@@ -13,6 +13,11 @@
<outlet property="Argon2IterationsTextField" destination="39N-8Q-J8b" id="pnH-Mf-x5c"/>
<outlet property="Argon2MemoryTextField" destination="eEW-oa-V7U" id="iDH-eW-4TE"/>
<outlet property="Argon2ThreadsTextField" destination="178-0f-guB" id="ATl-km-DSX"/>
<outlet property="aesEncryptionRoundsTextField" destination="8aq-34-rcd" id="WoJ-Kc-d8q"/>
<outlet property="argon2IterationsTextField" destination="39N-8Q-J8b" id="af4-Ft-aDX"/>
<outlet property="argon2MemoryTextField" destination="eEW-oa-V7U" id="Wig-Rk-lm0"/>
<outlet property="argon2ThreadsTextField" destination="178-0f-guB" id="dHa-L6-gOs"/>
<outlet property="cipherPopupButton" destination="3ek-Rg-w82" id="LbB-Fd-rqC"/>
<outlet property="createKeyDerivationParametersButton" destination="P98-Cu-Tha" id="UQ0-eg-rdx"/>
<outlet property="databaseColorColorWell" destination="1439" id="Fqq-2P-vbf"/>
<outlet property="databaseCompressionPopupButton" destination="1394" id="L9g-c4-dJp"/>
@@ -43,7 +48,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="548" height="411"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<view key="contentView" misplaced="YES" id="2">
<rect key="frame" x="0.0" y="0.0" width="548" height="411"/>
<autoresizingMask key="autoresizingMask"/>
@@ -75,7 +80,7 @@ Gw
</connections>
</button>
<tabView translatesAutoresizingMaskIntoConstraints="NO" id="357">
<rect key="frame" x="13" y="41" width="522" height="282"/>
<rect key="frame" x="13" y="41" width="522" height="346"/>
<font key="font" metaFont="system"/>
<tabViewItems>
<tabViewItem label="General" identifier="1" id="358">
@@ -205,11 +210,11 @@ Gw
</tabViewItem>
<tabViewItem label="Security" identifier="" id="370">
<view key="view" id="371">
<rect key="frame" x="10" y="33" width="502" height="236"/>
<rect key="frame" x="10" y="33" width="502" height="300"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3ek-Rg-w82">
<rect key="frame" x="233" y="192" width="37" height="26"/>
<rect key="frame" x="233" y="256" width="37" height="26"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="e3h-dG-ekU">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
@@ -217,7 +222,7 @@ Gw
</popUpButtonCell>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vH7-5a-52C">
<rect key="frame" x="160" y="199" width="69" height="17"/>
<rect key="frame" x="160" y="263" width="69" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Encryption" id="gxY-UL-bEG">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -225,13 +230,13 @@ Gw
</textFieldCell>
</textField>
<box title="Key derivation" translatesAutoresizingMaskIntoConstraints="NO" id="pbl-Mb-r8V">
<rect key="frame" x="17" y="16" width="468" height="171"/>
<rect key="frame" x="17" y="16" width="468" height="235"/>
<view key="contentView" id="hkT-SX-Te1">
<rect key="frame" x="2" y="2" width="464" height="154"/>
<rect key="frame" x="2" y="2" width="464" height="218"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cqu-Og-bZH">
<rect key="frame" x="147" y="117" width="63" height="17"/>
<rect key="frame" x="147" y="181" width="63" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Algorithm" id="U4f-lN-oxi">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -239,7 +244,7 @@ Gw
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5D9-bT-JAr">
<rect key="frame" x="214" y="110" width="37" height="26"/>
<rect key="frame" x="214" y="174" width="37" height="26"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="rf4-V3-tPC">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
@@ -254,7 +259,7 @@ Gw
</buttonCell>
</button>
<tabView drawsBackground="NO" type="noTabsNoBorder" translatesAutoresizingMaskIntoConstraints="NO" id="2MY-PW-kzL">
<rect key="frame" x="13" y="50" width="438" height="62"/>
<rect key="frame" x="13" y="50" width="438" height="126"/>
<font key="font" metaFont="system"/>
<tabViewItems>
<tabViewItem label="Aes" identifier="1" id="ft1-pl-lpO">
@@ -346,7 +351,9 @@ Gw
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eEW-oa-V7U">
<rect key="frame" x="179" y="20" width="80" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="M1E-89-YVm">
<byteCountFormatter key="formatter" id="zX5-n0-r94"/>
<numberFormatter key="formatter" formatterBehavior="default10_4" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="42" id="nQR-dh-won">
<real key="minimum" value="8192"/>
</numberFormatter>
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>

View File

@@ -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;

View File

@@ -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 {