mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 21:13:35 +00:00
The initial password input now can remember the keys used for any files. This is fragile as it just maps files to keys. Migth as well work hash based. Also password edit doesn't preselect the key file
This commit is contained in:
@@ -235,6 +235,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
[self.URLTextField bind:NSValueBinding toObject:self.entry withKeyPath:@"url" options:nil];
|
||||
[self.notesTextView bind:NSValueBinding toObject:self.entry withKeyPath:@"notes" options:nil];
|
||||
[self.expiresCheckButton bind:NSValueBinding toObject:self.entry.timeInfo withKeyPath:@"expires" options:nil];
|
||||
[self.tagsTokenField bind:NSValueBinding toObject:self.entry withKeyPath:@"tags" options:nil];
|
||||
}
|
||||
else {
|
||||
[self.titleTextField unbind:NSValueBinding];
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
@property (weak) IBOutlet NSTextField *errorInfoTextField;
|
||||
@property (weak) IBOutlet NSButton *togglePasswordButton;
|
||||
|
||||
@property (nonatomic, assign) BOOL shouldSelectKeyFile;
|
||||
@property (nonatomic, assign) BOOL shouldRememberKeyURL;
|
||||
@property (assign) BOOL showPassword;
|
||||
|
||||
- (IBAction)_decrypt:(id)sender;
|
||||
@@ -43,15 +43,15 @@
|
||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||
if(self) {
|
||||
_showLastUsedKeyFile = NO;
|
||||
_shouldSelectKeyFile = NO;
|
||||
_shouldRememberKeyURL = NO;
|
||||
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
|
||||
[self bind:@"shouldRememberKeyURL" toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyRememberKeyFilesForDatabases ] options:nil];
|
||||
|
||||
}
|
||||
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];
|
||||
@@ -73,22 +73,27 @@
|
||||
}
|
||||
|
||||
#pragma mark Properties
|
||||
- (void)setShouldSelectKeyFile:(BOOL)shouldSelectKeyFile {
|
||||
if(_shouldSelectKeyFile != shouldSelectKeyFile) {
|
||||
_shouldSelectKeyFile = shouldSelectKeyFile;
|
||||
- (void)setShouldRememberKeyURL:(BOOL)shouldSelectKeyFile {
|
||||
if(_shouldRememberKeyURL != shouldSelectKeyFile) {
|
||||
_shouldRememberKeyURL = shouldSelectKeyFile;
|
||||
if(!self.shouldRememberKeyURL) {
|
||||
/* Remove any old settings to clean them up */
|
||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kMPSettingsKeyRememeberdKeysForDatabases];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Private
|
||||
- (IBAction)_decrypt:(id)sender {
|
||||
id windowController = [[[self view] window] windowController];
|
||||
MPDocument *document = [windowController document];
|
||||
MPDocument *document = [[self windowController] document];
|
||||
if(document) {
|
||||
NSError *error = nil;
|
||||
if(![document unlockWithPassword:[self.passwordTextField stringValue]
|
||||
keyFileURL:[self.keyPathControl URL]
|
||||
error:&error]) {
|
||||
NSURL *keyURL = [self.keyPathControl URL];
|
||||
if([document unlockWithPassword:[self.passwordTextField stringValue] keyFileURL:keyURL error:&error]) {
|
||||
[self _setUsedKeyURL:keyURL forDocument:document];
|
||||
}
|
||||
else {
|
||||
[self _showError:error];
|
||||
}
|
||||
}
|
||||
@@ -107,11 +112,30 @@
|
||||
}
|
||||
|
||||
- (void)_selectRecentKeyFile {
|
||||
if(!self.shouldSelectKeyFile) {
|
||||
if(!self.shouldRememberKeyURL) {
|
||||
[self.keyPathControl setURL:nil];
|
||||
return; // If we aren't supposed to preselect paths, clear them!
|
||||
}
|
||||
NSDictionary *keysForFiles = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases];
|
||||
MPDocument *document = [[self windowController] document];
|
||||
if(document) {
|
||||
NSString *keyPath = keysForFiles[[[document fileURL] path]];
|
||||
NSURL *keyURL = keyPath != nil ? [NSURL fileURLWithPath:keyPath] : nil;
|
||||
[self.keyPathControl setURL:keyURL];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setUsedKeyURL:(NSURL *)keyURL forDocument:(NSDocument *)document {
|
||||
if(!self.shouldRememberKeyURL) {
|
||||
return;
|
||||
}
|
||||
NSMutableDictionary *keysForFiles = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases] mutableCopy];
|
||||
if(nil == keysForFiles) {
|
||||
keysForFiles = [[NSMutableDictionary alloc] initWithCapacity:1];
|
||||
}
|
||||
NSLog(@"remembering keyfile %@ for document %@ at URL %@", keyURL, [document displayName], [document fileURL]);
|
||||
keysForFiles[[[document fileURL] path]] = [keyURL path];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases];
|
||||
}
|
||||
|
||||
- (void)_showError:(NSError *)error {
|
||||
|
||||
@@ -39,7 +39,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideURL;
|
||||
|
||||
/* Document/Key Location store */
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyLastDatabasePath;
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyFilesForDatabases;
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyRememeberdKeysForDatabases;
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases;
|
||||
/*
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyLastKeyURL;
|
||||
|
||||
@@ -26,9 +26,9 @@ NSString *const kMPSettingsKeyLegacyHidePassword = @"LegacyHidePassword";
|
||||
NSString *const kMPSettingsKeyLegacyHideNotes = @"LegacyHideNotes";
|
||||
NSString *const kMPSettingsKeyLegacyHideURL = @"LegacyHideURL";
|
||||
|
||||
NSString *const kMPSettingsKeyLastDatabasePath = @"MPLastDatabasePath";
|
||||
NSString *const kMPSettingsKeyFilesForDatabases = @"MPKeyFilesForDatabases";
|
||||
NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"kMPSettingsKeyRememberKeyFilesForDatabases";
|
||||
NSString *const kMPSettingsKeyLastDatabasePath = @"LastDatabasePath";
|
||||
NSString *const kMPSettingsKeyRememeberdKeysForDatabases = @"RememeberdKeysForDatabases";
|
||||
NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"RememberKeyFilesForDatabases";
|
||||
|
||||
@implementation MPSettingsHelper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user