Skip to content

Commit

Permalink
add settings nsuser default may need tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesnow committed Oct 3, 2019
1 parent 76d3861 commit 9eae38f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
5 changes: 3 additions & 2 deletions MacPass/MPPasswordEditWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#import "SAMKeychain.h"
#import "SAMKeychainQuery.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "MPSettingsHelper.h"

@interface MPPasswordEditWindowController ()

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions MacPass/MPSettingsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
31 changes: 30 additions & 1 deletion MacPass/MPSettingsHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
NSString *const kMPDeprecatedSettingsKeyDefaultPasswordRounds = @"KeyDefaultPasswordRounds";
NSString *const kMPDepricatedSettingsKeyLoadUnsecurePlugins = @"MPLoadUnsecurePlugins";
NSString *const kMPDepricatedSettingsKeyAutotypeHideAccessibiltyWarning = @"AutotypeHideAccessibiltyWarning";
NSString *const kMPSettingsKeyDatabasesUsingTouchID = @"DatabasesUsingTouchID";

@implementation MPSettingsHelper

Expand Down Expand Up @@ -162,7 +163,8 @@ + (NSDictionary *)_standardDefaults {
kMPSettingsKeyLoadIncompatiblePlugins: @NO,
kMPSettingsKeyQuitOnLastWindowClose: @NO,
kMPSettingsKeyEnableAutosave: @YES,
kMPSettingsKeyHideAfterCopyToClipboard: @NO
kMPSettingsKeyHideAfterCopyToClipboard: @NO,
kMPSettingsKeyDatabasesUsingTouchID: [NSMutableArray new]
};
});
return standardDefaults;
Expand Down Expand Up @@ -284,4 +286,31 @@ + (void)_migrateLoadUnsecurePlugins {

}

+(NSArray*)touchIdEnabledDatabases {
NSArray<NSString *> *touchIdDatabases = [[NSUserDefaults standardUserDefaults] arrayForKey:kMPSettingsKeyDatabasesUsingTouchID];
return touchIdDatabases;
}

+ (void)addTouchIdEnabledDatabaseWithName: (NSString*)name {
NSMutableArray<NSString *> *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<NSString *> *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
5 changes: 5 additions & 0 deletions MacPass/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 9eae38f

Please sign in to comment.