OTP setup dialog now updates and stores attributes to entries

This commit is contained in:
Michael Starke
2021-10-20 16:32:16 +02:00
parent a34c0eed4e
commit f0e530bda5
5 changed files with 56 additions and 13 deletions

View File

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

View File

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

View File

@@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface MPTOTPSetupViewController : NSViewController
@interface MPTOTPSetupViewController : NSViewController <NSTextFieldDelegate>
@end

View File

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

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment version="101304" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -22,7 +22,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="324" height="362"/>
<subviews>
<gridView horizontalHuggingPriority="251" xPlacement="leading" yPlacement="center" rowAlignment="firstBaseline" rowSpacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="4gl-4p-0WY">
@@ -98,7 +98,7 @@
</gridCell>
<gridCell row="leK-j9-Cah" column="aZO-dP-SsW" id="gOO-ed-C7I"/>
<gridCell row="J7I-Uw-OQv" column="Ar1-qh-iHT" id="LYj-ea-Ou9">
<textField key="contentView" horizontalHuggingPriority="252" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="W8L-ah-Kdc">
<textField key="contentView" hidden="YES" horizontalHuggingPriority="252" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="W8L-ah-Kdc">
<rect key="frame" x="71" y="121" width="34" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Type" id="fNC-fH-sYi">
<font key="font" usesAppearanceFont="YES"/>
@@ -108,16 +108,13 @@
</textField>
</gridCell>
<gridCell row="J7I-Uw-OQv" column="Ecc-pj-MX9" id="fOz-RA-6LG">
<popUpButton key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ku7-YD-kkV">
<popUpButton key="contentView" hidden="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ku7-YD-kkV">
<rect key="frame" x="106" y="114" width="157" height="25"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="WbA-Ie-Txj">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="ger-Fr-8BF"/>
</popUpButtonCell>
<connections>
<action selector="changeType:" target="-2" id="0cg-oY-afM"/>
</connections>
</popUpButton>
</gridCell>
<gridCell row="J7I-Uw-OQv" column="aZO-dP-SsW" id="mka-sc-dDD"/>