diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index b32a8a07..3c612176 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -286,6 +286,8 @@ 4CE5B54B173AFBA700207B39 /* MPDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE5B549173AFBA700207B39 /* MPDocument.m */; }; 4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */; }; 4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8247416E2F2B900573141 /* MPOverlayView.m */; }; + 4CE84903271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE84901271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.m */; }; + 4CE84904271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CE84902271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.xib */; }; 4CE88B9717BA651C0042E078 /* contextTriangleTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CE88B9617BA651C0042E078 /* contextTriangleTemplate.pdf */; }; 4CEE46DD181C301D006BF1E5 /* MPAutotypeDaemon.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE46DC181C301D006BF1E5 /* MPAutotypeDaemon.m */; }; 4CEED1C617D7BD0E007180F1 /* NSError+Messages.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CEED1C517D7BD0E007180F1 /* NSError+Messages.m */; }; @@ -880,6 +882,9 @@ 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayWindowController.m; sourceTree = ""; }; 4CE8247316E2F2B900573141 /* MPOverlayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOverlayView.h; sourceTree = ""; }; 4CE8247416E2F2B900573141 /* MPOverlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayView.m; sourceTree = ""; }; + 4CE84900271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPEntryPasswordAttributeViewController.h; sourceTree = ""; }; + 4CE84901271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPEntryPasswordAttributeViewController.m; sourceTree = ""; }; + 4CE84902271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MPEntryPasswordAttributeViewController.xib; sourceTree = ""; }; 4CE88B9617BA651C0042E078 /* contextTriangleTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = contextTriangleTemplate.pdf; sourceTree = ""; }; 4CE88C2417C163FE00BFD195 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; 4CE88C3317C1647400BFD195 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -1442,6 +1447,9 @@ 4CC0192B271836CD00459789 /* MPEntryAttributeViewController.h */, 4CC0192C271836CD00459789 /* MPEntryAttributeViewController.m */, 4CC0192D271836CD00459789 /* MPEntryAttributeViewController.xib */, + 4CE84900271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.h */, + 4CE84901271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.m */, + 4CE84902271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.xib */, ); name = Inspector; sourceTree = ""; @@ -2073,6 +2081,7 @@ 4C701CBC178618A000581B88 /* 12_RemoteTemplate.pdf in Resources */, 4CF29BF417879D0000851B60 /* 26_FileSaveTemplate.pdf in Resources */, 4C7BD07619FE94C900C7AA5C /* Assets.xcassets in Resources */, + 4CE84904271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.xib in Resources */, 4CA182781F96523600DD4A4A /* DuplicateEntryOptionsWindow.xib in Resources */, 4C52A88E1788628B00868229 /* 06_BlockDeviceTemplate.pdf in Resources */, 4C52A88F1788628B00868229 /* 13_KeysTemplate.pdf in Resources */, @@ -2270,6 +2279,7 @@ 4CCEDE2A179F203B008402BE /* MPOutlineView.m in Sources */, 4CB33F861EAF54A000C9341E /* KPKNode+MPIsHistory.m in Sources */, 4CCEDE2E179F213B008402BE /* MPNotifications.m in Sources */, + 4CE84903271E10AC00EBAB0C /* MPEntryPasswordAttributeViewController.m in Sources */, 4C17D8E517A1C780006C8C1E /* MPDocumentWindowDelegate.m in Sources */, 4C63B8FB17A3154D0091BD72 /* MPContextButton.m in Sources */, 4C1E9885185F71A800943563 /* MPContextBarViewController.m in Sources */, diff --git a/MacPass/Base.lproj/EntryInspectorView.xib b/MacPass/Base.lproj/EntryInspectorView.xib index 53210d39..769ce386 100644 --- a/MacPass/Base.lproj/EntryInspectorView.xib +++ b/MacPass/Base.lproj/EntryInspectorView.xib @@ -1,8 +1,8 @@ - + - + @@ -97,7 +97,7 @@ - + @@ -792,7 +792,7 @@ - + diff --git a/MacPass/Base.lproj/InspectorView.xib b/MacPass/Base.lproj/InspectorView.xib index 30cf8163..f1d576d0 100644 --- a/MacPass/Base.lproj/InspectorView.xib +++ b/MacPass/Base.lproj/InspectorView.xib @@ -1,8 +1,8 @@ - + - + @@ -83,7 +83,7 @@ - + diff --git a/MacPass/MPEntryAttributeViewController.h b/MacPass/MPEntryAttributeViewController.h index b0df58c3..2d99e70c 100644 --- a/MacPass/MPEntryAttributeViewController.h +++ b/MacPass/MPEntryAttributeViewController.h @@ -19,6 +19,13 @@ NS_ASSUME_NONNULL_BEGIN /// The editor can be set to edit or view @interface MPEntryAttributeViewController : NSViewController +@property (strong) IBOutlet NSTextField *keyTextField; +@property (strong) IBOutlet HNHUITextField *valueTextField; + +- (void)updateValues; +- (void)updateEditing; + + @end NS_ASSUME_NONNULL_END diff --git a/MacPass/MPEntryAttributeViewController.m b/MacPass/MPEntryAttributeViewController.m index bcce6f88..42110e77 100644 --- a/MacPass/MPEntryAttributeViewController.m +++ b/MacPass/MPEntryAttributeViewController.m @@ -14,8 +14,6 @@ @interface MPEntryAttributeViewController () { BOOL _isDefaultAttribute; } -@property (strong) IBOutlet NSTextField *keyTextField; -@property (strong) IBOutlet HNHUITextField *valueTextField; @property (readonly, nullable, strong) KPKAttribute *representedAttribute; @end @@ -45,8 +43,8 @@ self.valueTextField.placeholderString = placeHolder; [super viewDidLoad]; - [self _updateValues]; - [self _updateEditing]; + [self updateValues]; + [self updateEditing]; __weak MPEntryAttributeViewController *welf = self; self.valueTextField.copyActionBlock = ^void(NSTextField *tf) { @@ -66,7 +64,7 @@ - (void)setIsEditor:(BOOL)isEditor { _isEditor = isEditor; - [self _updateEditing]; + [self updateEditing]; } - (void)setRepresentedObject:(id)representedObject { @@ -87,7 +85,7 @@ } _isDefaultAttribute = self.representedAttribute.isDefault; - [self _updateValues]; + [self updateValues]; } - (BOOL)textField:(NSTextField *)textField textView:(NSTextView *)textView performAction:(SEL)action { @@ -95,7 +93,6 @@ return YES; } - // Only copy action MPPasteboardOverlayInfoType info = MPPasteboardOverlayInfoCustom; NSMutableString *selectedValue = [[NSMutableString alloc] init]; @@ -109,9 +106,10 @@ if([self.representedAttribute.key isEqual:kKPKUsernameKey]) { info = MPPasteboardOverlayInfoUsername; } - else if([self.representedAttribute.key isEqual:kKPKPasswordKey]) { + /*else if([self.representedAttribute.key isEqual:kKPKPasswordKey]) { info = MPPasteboardOverlayInfoPassword; } + */ else if([self.representedAttribute.key isEqual:kKPKURLKey]) { info = MPPasteboardOverlayInfoURL; } @@ -131,16 +129,16 @@ } - (void)_didChangeAttribute:(NSNotification *)notification { - [self _updateValues]; + [self updateValues]; } -- (void)_updateValues { +- (void)updateValues { self.view.hidden = (!self.isEditor && self.representedAttribute.value.length == 0); self.keyTextField.stringValue = self.representedAttribute.key ? self.representedAttribute.key : @""; self.valueTextField.stringValue = self.representedAttribute.value ? self.representedAttribute.value : @""; } -- (void)_updateEditing { +- (void)updateEditing { self.keyTextField.editable = !_isDefaultAttribute && self.isEditor; self.valueTextField.editable = self.isEditor; self.keyTextField.selectable = YES; diff --git a/MacPass/MPEntryPasswordAttributeViewController.h b/MacPass/MPEntryPasswordAttributeViewController.h new file mode 100644 index 00000000..a748e5fc --- /dev/null +++ b/MacPass/MPEntryPasswordAttributeViewController.h @@ -0,0 +1,18 @@ +// +// MPEntryPasswordAttributeViewController.h +// MacPass +// +// Created by Michael Starke on 18.10.21. +// Copyright © 2021 HicknHack Software GmbH. All rights reserved. +// + +#import +#import "MPEntryAttributeViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MPEntryPasswordAttributeViewController : MPEntryAttributeViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/MacPass/MPEntryPasswordAttributeViewController.m b/MacPass/MPEntryPasswordAttributeViewController.m new file mode 100644 index 00000000..1666fe8a --- /dev/null +++ b/MacPass/MPEntryPasswordAttributeViewController.m @@ -0,0 +1,37 @@ +// +// MPEntryPasswordAttributeViewController.m +// MacPass +// +// Created by Michael Starke on 18.10.21. +// Copyright © 2021 HicknHack Software GmbH. All rights reserved. +// + +#import "MPEntryPasswordAttributeViewController.h" +#import +#import + +@interface MPEntryPasswordAttributeViewController () + +@property (strong) IBOutlet HNHUISecureTextField *passwordTextField; +@property (strong) IBOutlet NSButton *togglePasswordButton; +@property (strong) IBOutlet NSButton *generatePasswordButton; + +@property (strong, nullable, readonly) KPKAttribute *representedAttribute; + +@end + +@implementation MPEntryPasswordAttributeViewController + +- (void)updateValues { + self.view.hidden = (!self.isEditor && self.representedAttribute.value.length == 0); + self.passwordTextField.stringValue = self.representedAttribute.value ? self.representedAttribute.value : @""; +} + +- (void)updateEditing { + self.generatePasswordButton.hidden = !self.isEditor; + self.passwordTextField.editable = self.isEditor; + self.passwordTextField.selectable = YES; +} + + +@end diff --git a/MacPass/MPEntryPasswordAttributeViewController.xib b/MacPass/MPEntryPasswordAttributeViewController.xib new file mode 100644 index 00000000..b59eb637 --- /dev/null +++ b/MacPass/MPEntryPasswordAttributeViewController.xib @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MacPass/MPTOTPSetupViewController.m b/MacPass/MPTOTPSetupViewController.m index d24eb2ef..9cc9a5f7 100644 --- a/MacPass/MPTOTPSetupViewController.m +++ b/MacPass/MPTOTPSetupViewController.m @@ -22,6 +22,7 @@ @property (strong) IBOutlet NSPopUpButton *typePopUpButton; @property (nonatomic, readonly) KPKEntry *representedEntry; +@property (copy) KPKTimeOTPGenerator *generator; @property NSInteger timeSlice; @@ -134,8 +135,8 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { KPKEntry *entry = self.representedEntry; if(entry.hasTimeOTP) { - KPKTimeOTPGenerator *generator = [[KPKTimeOTPGenerator alloc] initWithAttributes:self.representedEntry.attributes]; - if(generator.isRFC6238) { + self.generator = [[KPKTimeOTPGenerator alloc] initWithAttributes:self.representedEntry.attributes]; + if(self.generator.isRFC6238) { [self.typePopUpButton selectItemWithTag:MPOTPTypeRFC]; } } @@ -152,26 +153,30 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { MPOTPUpdateSourceEntry */ - KPKTimeOTPGenerator *generator = [[KPKTimeOTPGenerator alloc] initWithAttributes:((KPKEntry *)self.representedObject).attributes]; + if(!self.generator) { + self.generator = [[KPKTimeOTPGenerator alloc] initWithAttributes:((KPKEntry *)self.representedObject).attributes]; + } switch(source) { case MPOTPUpdateSourceQRImage: { NSString *qrCodeString = self.qrCodeImageView.image.QRCodeString; NSURL *otpURL = [NSURL URLWithString:qrCodeString]; self.urlTextField.stringValue = otpURL.absoluteString; - generator = [[KPKTimeOTPGenerator alloc] initWithURL:self.urlTextField.stringValue]; + self.generator = [[KPKTimeOTPGenerator alloc] initWithURL:self.urlTextField.stringValue]; break; } case MPOTPUpdateSourceURL: - generator = [[KPKTimeOTPGenerator alloc] initWithURL:self.urlTextField.stringValue]; + self.generator = [[KPKTimeOTPGenerator alloc] initWithURL:self.urlTextField.stringValue]; break; case MPOTPUpdateSourceSecret: - generator.key = [NSData dataWithBase32EncodedString:self.secretTextField.stringValue]; + self.generator.key = [NSData dataWithBase32EncodedString:self.secretTextField.stringValue]; break; case MPOTPUpdateSourceAlgorithm: + //self.generator.hashAlgorithm = break; case MPOTPUpdateSourceTimeSlice: + //self.generator.timeSlice = break; case MPOTPUpdateSourceEntry: break; @@ -194,16 +199,16 @@ typedef NS_ENUM(NSUInteger, MPOTPType) { self.qrCodeImageView.image = [NSImage QRCodeImageWithString:authURL.absoluteString]; } } + else { + // generate the URL + } /* secret */ - NSString *secret = [generator.key base32EncodedStringWithOptions:0]; + NSString *secret = [self.generator.key base32EncodedStringWithOptions:0]; self.secretTextField.stringValue = secret ? secret : @""; - - [self.algorithmPopUpButton selectItemWithTag:generator.hashAlgorithm]; - - [self.digitCountPopUpButton selectItemWithTag:generator.numberOfDigits]; - - self.timeSlice = generator.timeSlice; + [self.algorithmPopUpButton selectItemWithTag:self.generator.hashAlgorithm]; + [self.digitCountPopUpButton selectItemWithTag:self.generator.numberOfDigits]; + self.timeSlice = self.generator.timeSlice; }