From c7b5bdac7475f2cb029eaa35e9a56f911f42f1d4 Mon Sep 17 00:00:00 2001 From: michael starke Date: Sat, 16 Nov 2013 00:07:14 +0100 Subject: [PATCH] Added Autotype stubbs Some changes to handle remebering key files in the password input --- KeePassKit | 2 +- MacPass.xcodeproj/project.pbxproj | 24 ++++++++++++++++-- MacPass/MPAutotypeCommand.h | 4 +++ MacPass/MPAutotypeCommand.m | 4 +++ MacPass/MPAutotypeDaemon.m | 13 ++++++++++ MacPass/MPDocument+Autotype.h | 7 ++++++ MacPass/MPDocument+Autotype.m | 9 +++++++ MacPass/MPDocumentWindowController.m | 4 +++ MacPass/MPPasswordInputController.h | 2 ++ MacPass/MPPasswordInputController.m | 37 +++++++++++++++++++++++++--- 10 files changed, 100 insertions(+), 6 deletions(-) diff --git a/KeePassKit b/KeePassKit index c18eac2c..54365cad 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit c18eac2c9e9be310b888688f349ea583a50891a3 +Subproject commit 54365cad7c0c15305b66c3483ee2bcf7d392db87 diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 1778578c..e8b0c74a 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -186,6 +186,8 @@ 4C888C9016EB6C91003D34A1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C888C8E16EB6C91003D34A1 /* Localizable.strings */; }; 4C888C9316EB6F5E003D34A1 /* MPToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C888C9216EB6F5E003D34A1 /* MPToolbarItem.m */; }; 4C888C9716EB754B003D34A1 /* MPActionHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C888C9616EB754B003D34A1 /* MPActionHelper.m */; }; + 4C89F521182F9FDD0069C73C /* NSString+Commands.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C89F520182F9FDD0069C73C /* NSString+Commands.m */; }; + 4C89F524182FB4740069C73C /* MPAutotypeCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C89F523182FB4740069C73C /* MPAutotypeCommand.m */; }; 4C8A173D1790AA41008B5C17 /* NSData+Keyfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8A173C1790AA41008B5C17 /* NSData+Keyfile.m */; }; 4C8B36AB17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */; }; 4C8FECC816D57E3200BF26CF /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C8FECC716D57E3200BF26CF /* QuartzCore.framework */; }; @@ -602,6 +604,10 @@ 4C888C9216EB6F5E003D34A1 /* MPToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPToolbarItem.m; sourceTree = ""; }; 4C888C9516EB754B003D34A1 /* MPActionHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPActionHelper.h; sourceTree = ""; }; 4C888C9616EB754B003D34A1 /* MPActionHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPActionHelper.m; sourceTree = ""; }; + 4C89F51F182F9FDD0069C73C /* NSString+Commands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Commands.h"; sourceTree = ""; }; + 4C89F520182F9FDD0069C73C /* NSString+Commands.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Commands.m"; sourceTree = ""; }; + 4C89F522182FB4740069C73C /* MPAutotypeCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeCommand.h; sourceTree = ""; }; + 4C89F523182FB4740069C73C /* MPAutotypeCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeCommand.m; sourceTree = ""; }; 4C8A173B1790AA41008B5C17 /* NSData+Keyfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Keyfile.h"; sourceTree = ""; }; 4C8A173C1790AA41008B5C17 /* NSData+Keyfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSData+Keyfile.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 4C8B36A917A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineContextMenuDelegate.h; sourceTree = ""; }; @@ -1057,8 +1063,6 @@ 4C4B7EF717A4B335000234C7 /* MPUniqueCharactersFormatter.m */, 4C224B4017DFCB2300FF6AEE /* MPNumericalInputFormatter.h */, 4C224B4117DFCB2400FF6AEE /* MPNumericalInputFormatter.m */, - 4CEE46DB181C301D006BF1E5 /* MPAutotypeDaemon.h */, - 4CEE46DC181C301D006BF1E5 /* MPAutotypeDaemon.m */, ); name = Helper; sourceTree = ""; @@ -1264,6 +1268,7 @@ 4C217D8E17A32BCF00609FAA /* Common */, 4C104129178CDD26001B5239 /* Categories */, 4C245C11176E22150086100E /* KeepassHttp */, + 4C89F525182FB4C50069C73C /* Autotype */, 4C2E382016D141F700037A9D /* Helper */, 4CE88B9317BA64DB0042E078 /* Icons */, 4C586F9C16D07ABD00E7DB57 /* Database Icons */, @@ -1295,6 +1300,17 @@ name = "Supporting Files"; sourceTree = ""; }; + 4C89F525182FB4C50069C73C /* Autotype */ = { + isa = PBXGroup; + children = ( + 4CEE46DB181C301D006BF1E5 /* MPAutotypeDaemon.h */, + 4CEE46DC181C301D006BF1E5 /* MPAutotypeDaemon.m */, + 4C89F522182FB4740069C73C /* MPAutotypeCommand.h */, + 4C89F523182FB4740069C73C /* MPAutotypeCommand.m */, + ); + name = Autotype; + sourceTree = ""; + }; 4CA0B2F115BCAEE600654E32 /* View Controller */ = { isa = PBXGroup; children = ( @@ -1469,6 +1485,8 @@ 4C6366AB17AF1E0100AAF17D /* NSColor+KeePassKit.m */, 4C6C72C217C01E4200768849 /* NSMutableData+KeePassKit.h */, 4C6C72C317C01E4200768849 /* NSMutableData+KeePassKit.m */, + 4C89F51F182F9FDD0069C73C /* NSString+Commands.h */, + 4C89F520182F9FDD0069C73C /* NSString+Commands.m */, ); path = Categories; sourceTree = ""; @@ -1877,6 +1895,7 @@ 4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */, 4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */, 4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */, + 4C89F524182FB4740069C73C /* MPAutotypeCommand.m in Sources */, 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */, 4C888C9316EB6F5E003D34A1 /* MPToolbarItem.m in Sources */, 4C888C9716EB754B003D34A1 /* MPActionHelper.m in Sources */, @@ -1900,6 +1919,7 @@ 4C79DF2A176685870083708F /* HNHRoundedTextField.m in Sources */, 4C46E09E17673A0A00DA62E8 /* HNHShadowBox.m in Sources */, 4C37A6731769393300AD0A40 /* HNHTableHeaderCell.m in Sources */, + 4C89F521182F9FDD0069C73C /* NSString+Commands.m in Sources */, 4CA2335A176DBFE100F0B6AC /* MPLockDaemon.m in Sources */, 4C80BB6F176DE06F00E5E248 /* HNHScrollDocumentViewAdapter.m in Sources */, 4C245B76176E1E3D0086100E /* DDData.m in Sources */, diff --git a/MacPass/MPAutotypeCommand.h b/MacPass/MPAutotypeCommand.h index 7d97a492..496181b3 100644 --- a/MacPass/MPAutotypeCommand.h +++ b/MacPass/MPAutotypeCommand.h @@ -10,4 +10,8 @@ @interface MPAutotypeCommand : NSObject +@property (copy) NSString *commandString; + +- (void)execute; + @end diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m index 34dca682..aa6444f2 100644 --- a/MacPass/MPAutotypeCommand.m +++ b/MacPass/MPAutotypeCommand.m @@ -10,4 +10,8 @@ @implementation MPAutotypeCommand +- (void)execute { + // todo; +} + @end diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 5d8363eb..0211aaaa 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -10,6 +10,7 @@ #import "DDHotKeyCenter.h" #import "MPPasteBoardController.h" #import "MPDocument.h" +#import "MPDocument+Autotype.h" #import "KPKEntry.h" @@ -103,6 +104,18 @@ NSString *windowTitle = [self _frontMostWindowTitle]; NSLog(@"Looking for entries matching window title:%@", windowTitle); + /* + Query the document to generate a autotype command list for the window title + We do not care where this came form, just get the autotype commands + */ + NSArray *autotypeCandidates = [[currentDocument findEntriesForWindowTitle:windowTitle] lastObject]; + if([autotypeCandidates count] == 0) { + return; // No Entries found. + } + + /* + Implement! + */ return; KPKEntry *selectedEntry = currentDocument.selectedEntry; diff --git a/MacPass/MPDocument+Autotype.h b/MacPass/MPDocument+Autotype.h index 1f6183ed..e6ff72a0 100644 --- a/MacPass/MPDocument+Autotype.h +++ b/MacPass/MPDocument+Autotype.h @@ -9,7 +9,14 @@ #import "MPDocument.h" @interface MPDocument (Autotype) +/* + Problem: + + If matching isn't safe, we need to determine what to do: + Possible selections for the user are Window associations or entries + Hence we need to deliver both - or do something completely different? + */ - (NSArray *)findEntriesForWindowTitle:(NSString *)windowTitle; @end diff --git a/MacPass/MPDocument+Autotype.m b/MacPass/MPDocument+Autotype.m index 68259324..066a6aba 100644 --- a/MacPass/MPDocument+Autotype.m +++ b/MacPass/MPDocument+Autotype.m @@ -8,9 +8,18 @@ #import "MPDocument+Autotype.h" +#import "KPKGroup.h" +#import "KPKEntry.h" +#import "KPKAutotype.h" + @implementation MPDocument (Autotype) - (NSArray *)findEntriesForWindowTitle:(NSString *)windowTitle { + + NSArray *autotypeEntries = [self.root autotypeableChildEntries]; + for(KPKEntry *entry in autotypeEntries) { + //KPKAutotype *autotype = entry.autotype; + } return nil; } diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index e8c277e5..5d48a19b 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -283,6 +283,10 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) { - (void)showPasswordInput { if(!self.passwordInputController) { self.passwordInputController = [[MPPasswordInputController alloc] init]; + self.passwordInputController.showLastUsedKeyFile = YES; + } + else { + self.passwordInputController.showLastUsedKeyFile = NO; } [self _setContentViewController:self.passwordInputController]; [self.passwordInputController requestPassword]; diff --git a/MacPass/MPPasswordInputController.h b/MacPass/MPPasswordInputController.h index 732fff81..d78531d1 100644 --- a/MacPass/MPPasswordInputController.h +++ b/MacPass/MPPasswordInputController.h @@ -10,6 +10,8 @@ @interface MPPasswordInputController : MPViewController +@property (nonatomic, assign) BOOL showLastUsedKeyFile; + - (void)requestPassword; @end diff --git a/MacPass/MPPasswordInputController.m b/MacPass/MPPasswordInputController.m index b58eb0ff..1d1593cf 100644 --- a/MacPass/MPPasswordInputController.m +++ b/MacPass/MPPasswordInputController.m @@ -9,6 +9,7 @@ #import "MPPasswordInputController.h" #import "MPDocumentWindowController.h" #import "MPDocument.h" +#import "MPSettingsHelper.h" #import "MPKeyfilePathControlDelegate.h" #import "HNHRoundedSecureTextField.h" @@ -23,6 +24,7 @@ @property (weak) IBOutlet NSTextField *errorInfoTextField; @property (weak) IBOutlet NSButton *togglePasswordButton; +@property (nonatomic, assign) BOOL shouldSelectKeyFile; @property (assign) BOOL showPassword; - (IBAction)_decrypt:(id)sender; @@ -33,15 +35,28 @@ @implementation MPPasswordInputController - (id)init { - return [[MPPasswordInputController alloc] initWithNibName:@"PasswordInputView" bundle:nil]; + self = [self initWithNibName:@"PasswordInputView" bundle:nil]; + return self; } +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if(self) { + _showLastUsedKeyFile = NO; + _shouldSelectKeyFile = NO; + } + return self; +} - (void)didLoadView { + NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; + [self bind:@"shouldSelectKeyFile" toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyRememberKeyFilesForDatabases ] options:nil]; + [self.keyPathControl setDelegate:self.pathControlDelegate]; [self.errorImageView setImage:[NSImage imageNamed:NSImageNameCaution]]; [self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil]; [self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil]; + [self _reset]; } @@ -52,8 +67,17 @@ - (void)requestPassword { // show Warnign if read-only mode! [self _reset]; + if(self.showLastUsedKeyFile) { + [self _selectRecentKeyFile]; + } +} + +#pragma mark Properties +- (void)setShouldSelectKeyFile:(BOOL)shouldSelectKeyFile { + if(_shouldSelectKeyFile != shouldSelectKeyFile) { + _shouldSelectKeyFile = shouldSelectKeyFile; + } } -#pragma mark NSTextViewDelegate #pragma mark - #pragma mark Private @@ -80,7 +104,14 @@ [self.keyPathControl setURL:nil]; [self.errorInfoTextField setHidden:YES]; [self.errorImageView setHidden:YES]; - +} + +- (void)_selectRecentKeyFile { + if(!self.shouldSelectKeyFile) { + [self.keyPathControl setURL:nil]; + return; // If we aren't supposed to preselect paths, clear them! + } + } - (void)_showError:(NSError *)error {