From 9eae38fe5ccba65c07ff5e958f5644b6a4df5881 Mon Sep 17 00:00:00 2001 From: georgesnow Date: Thu, 3 Oct 2019 16:56:27 -0400 Subject: [PATCH] add settings nsuser default may need tweaking --- MacPass/MPPasswordEditWindowController.m | 5 ++-- MacPass/MPSettingsHelper.h | 16 ++++++++++++ MacPass/MPSettingsHelper.m | 31 +++++++++++++++++++++++- MacPass/en.lproj/Localizable.strings | 5 ++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/MacPass/MPPasswordEditWindowController.m b/MacPass/MPPasswordEditWindowController.m index df36a2305..5708d8724 100644 --- a/MacPass/MPPasswordEditWindowController.m +++ b/MacPass/MPPasswordEditWindowController.m @@ -30,6 +30,7 @@ #import "SAMKeychain.h" #import "SAMKeychainQuery.h" #import +#import "MPSettingsHelper.h" @interface MPPasswordEditWindowController () @@ -191,7 +192,7 @@ - (void) _savePasswordInKeychain:(NSString*)password { if (error == nil) { -// [MPSettingsHelper addTouchIdEnabledDatabaseWithName:dbName]; //Add DB name in the list of Touch ID enabled databases + [MPSettingsHelper addTouchIdEnabledDatabaseWithName:dbName]; //Add DB name in the list of Touch ID enabled databases NSLog(@"Saved DB (%@) password in the keychain.", dbName); } else { NSLog(@"Error updating keychain with DB password: %@", error.localizedDescription); @@ -209,7 +210,7 @@ - (void) _deletePasswordFromKeychain { if (error == nil) { [SAMKeychain deletePasswordForService:@"MacPass" account:dbName]; // [passwordItem deleteItemAndReturnError:&error]; //Delete the password from the keychain -// [MPSettingsHelper removeTouchIdEnabledDatabaseWithName:dbName]; //Remove DB name from the list of Touch ID enabled databases + [MPSettingsHelper removeTouchIdEnabledDatabaseWithName:dbName]; //Remove DB name from the list of Touch ID enabled databases NSLog(@"DB (%@) password deleted from keychain.", dbName); } else { NSLog(@"Error deleting DB password from the keychain: %@", error.localizedDescription); diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index 9c366a877..badd35afb 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -89,6 +89,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyLoadIncompatiblePlugins; // I APPKIT_EXTERN NSString *const kMPSettingsKeyHideIncopatiblePluginsWarning; // Do not show an alert, when MacPass encounteres incompatible plugins APPKIT_EXTERN NSString *const kMPSettingsKeyAllowRemoteFetchOfPluginRepository; // Allow the download of the plugin repository file APPKIT_EXTERN NSString *const kMPSettingsKeyPluginHideAksForRemoveConnectionPermission; +APPKIT_EXTERN NSString *const kMPSettingsKeyDatabasesUsingTouchID; typedef NS_ENUM(NSUInteger, MPFileChangeStrategy) { MPFileChangeStrategyAsk, @@ -138,4 +139,19 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyPasswordDefaultsForEntry; */ + (NSString *)defaultControllerPathForKey:(NSString *)key; +/** + * Returns the names of the databases with enabled Touch ID unlocking. + */ ++ (NSArray*)touchIdEnabledDatabases; + +/** + * Adds a new database to the list of Touch ID enabled databases. + */ ++ (void)addTouchIdEnabledDatabaseWithName: (NSString*)name; + +/** + * Removes a new database to the list of Touch ID enabled databases. + */ ++ (void)removeTouchIdEnabledDatabaseWithName: (NSString*)name; + @end diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 336e001bd..16ad29693 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -98,6 +98,7 @@ NSString *const kMPDeprecatedSettingsKeyDefaultPasswordRounds = @"KeyDefaultPasswordRounds"; NSString *const kMPDepricatedSettingsKeyLoadUnsecurePlugins = @"MPLoadUnsecurePlugins"; NSString *const kMPDepricatedSettingsKeyAutotypeHideAccessibiltyWarning = @"AutotypeHideAccessibiltyWarning"; +NSString *const kMPSettingsKeyDatabasesUsingTouchID = @"DatabasesUsingTouchID"; @implementation MPSettingsHelper @@ -162,7 +163,8 @@ + (NSDictionary *)_standardDefaults { kMPSettingsKeyLoadIncompatiblePlugins: @NO, kMPSettingsKeyQuitOnLastWindowClose: @NO, kMPSettingsKeyEnableAutosave: @YES, - kMPSettingsKeyHideAfterCopyToClipboard: @NO + kMPSettingsKeyHideAfterCopyToClipboard: @NO, + kMPSettingsKeyDatabasesUsingTouchID: [NSMutableArray new] }; }); return standardDefaults; @@ -284,4 +286,31 @@ + (void)_migrateLoadUnsecurePlugins { } ++(NSArray*)touchIdEnabledDatabases { + NSArray *touchIdDatabases = [[NSUserDefaults standardUserDefaults] arrayForKey:kMPSettingsKeyDatabasesUsingTouchID]; + return touchIdDatabases; +} + ++ (void)addTouchIdEnabledDatabaseWithName: (NSString*)name { + NSMutableArray *touchIdDatabases = [[[NSUserDefaults standardUserDefaults] arrayForKey:kMPSettingsKeyDatabasesUsingTouchID] mutableCopy]; + if (touchIdDatabases == nil) { + touchIdDatabases = [NSMutableArray new]; + } + + if (![touchIdDatabases containsObject:name]) { + [touchIdDatabases addObject:name]; + [[NSUserDefaults standardUserDefaults] setObject:touchIdDatabases forKey:kMPSettingsKeyDatabasesUsingTouchID]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } + NSLog(@"Saved DB %@ to the list of TouchID enabled databases.", name); +} + ++ (void)removeTouchIdEnabledDatabaseWithName: (NSString*)name { + NSMutableArray *touchIdDatabases = [[[NSUserDefaults standardUserDefaults] arrayForKey:kMPSettingsKeyDatabasesUsingTouchID] mutableCopy]; + [touchIdDatabases removeObject:name]; + [[NSUserDefaults standardUserDefaults] setObject:touchIdDatabases forKey:kMPSettingsKeyDatabasesUsingTouchID]; + [[NSUserDefaults standardUserDefaults] synchronize]; + NSLog(@"Removed DB %@ from the list of TouchID enabled databases.", name); +} + @end diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index f34cb98bc..472f7cfeb 100644 --- a/MacPass/en.lproj/Localizable.strings +++ b/MacPass/en.lproj/Localizable.strings @@ -346,6 +346,11 @@ /* Keyfile not valid */ "ERROR_INVALID_KEYFILE" = "Keyfile is invalid!"; +/* TouchID Messages */ +"ALERT_TOUCH_ID_MESSAGE" = "Use TouchID for unlocking this database?"; +"ALERT_TOUCH_ID_DESCRIPTION" = "If you select Yes, your database password will be saved in the Keychain and you will be able to unlock this database with your fingertip."; +"TOUCHBAR_TOUCH_ID_MESSAGE" = "unlock this database"; + /* Error description given when adding an invalid plugin */ "ERROR_INVALID_PLUGIN" = "Invalid plugin";