diff --git a/Cartfile b/Cartfile index 23afaa22..ff13dacc 100644 --- a/Cartfile +++ b/Cartfile @@ -1,4 +1,4 @@ github "sparkle-project/Sparkle" ~> 1.22 github "MacPass/TransformerKit" "a8b5bb73cc327ec6798569b865c32fec5eb2289f" -github "MacPass/KeePassKit" "61bcb5718ea6f09725595f7e1f1b31ded0bb704e" +github "MacPass/KeePassKit" "17429dfde8addad400d3b17ce2d7cb2504051779" github "mstarke/HNHUi" ~> 4.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 342aaff0..f3cad5f8 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,4 +1,4 @@ -github "MacPass/KeePassKit" "61bcb5718ea6f09725595f7e1f1b31ded0bb704e" +github "MacPass/KeePassKit" "17429dfde8addad400d3b17ce2d7cb2504051779" github "MacPass/KissXML" "933f04fe5ad95c2be07ec0c2f801e140007f20fa" github "MacPass/TransformerKit" "a8b5bb73cc327ec6798569b865c32fec5eb2289f" github "mstarke/HNHUi" "4.0.4" diff --git a/MacPass/MPTOTPSetupViewController.h b/MacPass/MPTOTPSetupViewController.h index a0f9ea0e..dc310880 100644 --- a/MacPass/MPTOTPSetupViewController.h +++ b/MacPass/MPTOTPSetupViewController.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface MPTOTPSetupViewController : NSViewController +@interface MPTOTPSetupViewController : NSViewController @end diff --git a/MacPass/MPTOTPSetupViewController.m b/MacPass/MPTOTPSetupViewController.m index 02b1b9e3..414ae3ac 100644 --- a/MacPass/MPTOTPSetupViewController.m +++ b/MacPass/MPTOTPSetupViewController.m @@ -35,6 +35,7 @@ typedef NS_ENUM(NSUInteger, MPOTPUpdateSource) { MPOTPUpdateSourceAlgorithm, MPOTPUpdateSourceTimeSlice, MPOTPUpdateSourceType, + MPOTPUpdateSourceDigits, MPOTPUpdateSourceEntry }; @@ -60,6 +61,7 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { } - (IBAction)changeType:(id)sender { + /* if(sender != self.typePopUpButton) { return; // wrong sender } @@ -77,6 +79,15 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { self.timeStepStepper.enabled = YES; } [self _updateView:MPOTPUpdateSourceType]; + */ +} + +- (IBAction)changeHashAlgorithm:(id)sender { + [self _updateView:MPOTPUpdateSourceAlgorithm]; +} + +- (IBAction)changeDigits:(id)sender { + [self _updateView:MPOTPUpdateSourceDigits]; } - (IBAction)parseQRCode:(id)sender { @@ -92,10 +103,21 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { - (IBAction)save:(id)sender { // Update entry settings! - // adhere to change observation for history? + // FIXME: add model observing to ensure correct history recording + [self.generator saveToEntry:self.representedEntry]; [self.presentingViewController dismissViewController:self]; } +- (void)controlTextDidEndEditing:(NSNotification *)notification { + NSControl *control = notification.object; + if(control == self.secretTextField) { + [self _updateView:MPOTPUpdateSourceSecret]; + } + else if(control == self.urlTextField) { + [self _updateView:MPOTPUpdateSourceURL]; + } +} + - (void)_setupView { /* algorithm */ NSMenuItem *sha1Item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"HASH_SHA1", "SHA 1 hash algoritm menu item") action:NULL keyEquivalent:@""]; @@ -110,6 +132,9 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { [self.algorithmPopUpButton.menu addItem:sha256Item]; [self.algorithmPopUpButton.menu addItem:sha512Item]; + self.algorithmPopUpButton.action = @selector(changeHashAlgorithm:); + self.algorithmPopUpButton.target = self; + /* digits */ NSAssert(self.digitCountPopUpButton.menu.numberOfItems == 0, @"Digit menu needs to be empty"); for(NSUInteger digit = 6; digit <= 8; digit++) { @@ -118,6 +143,10 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { [self.digitCountPopUpButton.menu addItem:item]; } + self.digitCountPopUpButton.action = @selector(changeDigits:); + self.digitCountPopUpButton.target = self; + + NSAssert(self.typePopUpButton.menu.numberOfItems == 0, @"Type menu needs to be empty!"); NSMenuItem *rfcItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"OTP_RFC", @"OTP type RFC ") action:NULL keyEquivalent:@""]; rfcItem.tag = MPOTPTypeRFC; @@ -130,9 +159,16 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { [self.typePopUpButton.menu addItem:steamItem]; [self.typePopUpButton.menu addItem:customItem]; + self.typePopUpButton.action = @selector(changeType:); + self.typePopUpButton.target = self; + + [self.timeStepTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(timeSlice)) options:nil]; [self.timeStepStepper bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(timeSlice)) options:nil]; + self.secretTextField.delegate = self; + self.urlTextField.delegate = self; + KPKEntry *entry = self.representedEntry; if(entry.hasTimeOTP) { self.generator = [[KPKTimeOTPGenerator alloc] initWithAttributes:self.representedEntry.attributes]; @@ -184,8 +220,11 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { case MPOTPUpdateSourceTimeSlice: self.generator.timeSlice = self.timeStepTextField.integerValue; break; + case MPOTPUpdateSourceDigits: + self.generator.numberOfDigits = self.digitCountPopUpButton.selectedTag; + break; default: - return; + break; } /* @@ -212,6 +251,13 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { [self.algorithmPopUpButton selectItemWithTag:self.generator.hashAlgorithm]; [self.digitCountPopUpButton selectItemWithTag:self.generator.numberOfDigits]; self.timeSlice = self.generator.timeSlice; + + if(self.generator.isRFC6238) { + [self.typePopUpButton selectItemWithTag:MPOTPTypeRFC]; + } + else { + [self.typePopUpButton selectItemWithTag:MPOTPTypeCustom]; + } } @end diff --git a/MacPass/MPTOTPSetupViewController.xib b/MacPass/MPTOTPSetupViewController.xib index e8ea84f2..af884f52 100644 --- a/MacPass/MPTOTPSetupViewController.xib +++ b/MacPass/MPTOTPSetupViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -22,7 +22,7 @@ - + @@ -98,7 +98,7 @@ - + - +