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.URLTextField bind:NSValueBinding toObject:self.entry withKeyPath:@"url" options:nil];
|
||||||
[self.notesTextView bind:NSValueBinding toObject:self.entry withKeyPath:@"notes" 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.expiresCheckButton bind:NSValueBinding toObject:self.entry.timeInfo withKeyPath:@"expires" options:nil];
|
||||||
|
[self.tagsTokenField bind:NSValueBinding toObject:self.entry withKeyPath:@"tags" options:nil];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[self.titleTextField unbind:NSValueBinding];
|
[self.titleTextField unbind:NSValueBinding];
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
@property (weak) IBOutlet NSTextField *errorInfoTextField;
|
@property (weak) IBOutlet NSTextField *errorInfoTextField;
|
||||||
@property (weak) IBOutlet NSButton *togglePasswordButton;
|
@property (weak) IBOutlet NSButton *togglePasswordButton;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL shouldSelectKeyFile;
|
@property (nonatomic, assign) BOOL shouldRememberKeyURL;
|
||||||
@property (assign) BOOL showPassword;
|
@property (assign) BOOL showPassword;
|
||||||
|
|
||||||
- (IBAction)_decrypt:(id)sender;
|
- (IBAction)_decrypt:(id)sender;
|
||||||
@@ -43,20 +43,20 @@
|
|||||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||||
if(self) {
|
if(self) {
|
||||||
_showLastUsedKeyFile = NO;
|
_showLastUsedKeyFile = NO;
|
||||||
_shouldSelectKeyFile = NO;
|
_shouldRememberKeyURL = NO;
|
||||||
|
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
|
||||||
|
[self bind:@"shouldRememberKeyURL" toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyRememberKeyFilesForDatabases ] options:nil];
|
||||||
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didLoadView {
|
- (void)didLoadView {
|
||||||
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
|
|
||||||
[self bind:@"shouldSelectKeyFile" toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyRememberKeyFilesForDatabases ] options:nil];
|
|
||||||
|
|
||||||
[self.keyPathControl setDelegate:self.pathControlDelegate];
|
[self.keyPathControl setDelegate:self.pathControlDelegate];
|
||||||
[self.errorImageView setImage:[NSImage imageNamed:NSImageNameCaution]];
|
[self.errorImageView setImage:[NSImage imageNamed:NSImageNameCaution]];
|
||||||
[self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil];
|
[self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil];
|
||||||
[self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil];
|
[self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil];
|
||||||
|
|
||||||
[self _reset];
|
[self _reset];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,22 +73,27 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Properties
|
#pragma mark Properties
|
||||||
- (void)setShouldSelectKeyFile:(BOOL)shouldSelectKeyFile {
|
- (void)setShouldRememberKeyURL:(BOOL)shouldSelectKeyFile {
|
||||||
if(_shouldSelectKeyFile != shouldSelectKeyFile) {
|
if(_shouldRememberKeyURL != shouldSelectKeyFile) {
|
||||||
_shouldSelectKeyFile = shouldSelectKeyFile;
|
_shouldRememberKeyURL = shouldSelectKeyFile;
|
||||||
|
if(!self.shouldRememberKeyURL) {
|
||||||
|
/* Remove any old settings to clean them up */
|
||||||
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kMPSettingsKeyRememeberdKeysForDatabases];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark Private
|
#pragma mark Private
|
||||||
- (IBAction)_decrypt:(id)sender {
|
- (IBAction)_decrypt:(id)sender {
|
||||||
id windowController = [[[self view] window] windowController];
|
MPDocument *document = [[self windowController] document];
|
||||||
MPDocument *document = [windowController document];
|
|
||||||
if(document) {
|
if(document) {
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
if(![document unlockWithPassword:[self.passwordTextField stringValue]
|
NSURL *keyURL = [self.keyPathControl URL];
|
||||||
keyFileURL:[self.keyPathControl URL]
|
if([document unlockWithPassword:[self.passwordTextField stringValue] keyFileURL:keyURL error:&error]) {
|
||||||
error:&error]) {
|
[self _setUsedKeyURL:keyURL forDocument:document];
|
||||||
|
}
|
||||||
|
else {
|
||||||
[self _showError:error];
|
[self _showError:error];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,11 +112,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)_selectRecentKeyFile {
|
- (void)_selectRecentKeyFile {
|
||||||
if(!self.shouldSelectKeyFile) {
|
if(!self.shouldRememberKeyURL) {
|
||||||
[self.keyPathControl setURL:nil];
|
[self.keyPathControl setURL:nil];
|
||||||
return; // If we aren't supposed to preselect paths, clear them!
|
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 {
|
- (void)_showError:(NSError *)error {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideURL;
|
|||||||
|
|
||||||
/* Document/Key Location store */
|
/* Document/Key Location store */
|
||||||
APPKIT_EXTERN NSString *const kMPSettingsKeyLastDatabasePath;
|
APPKIT_EXTERN NSString *const kMPSettingsKeyLastDatabasePath;
|
||||||
APPKIT_EXTERN NSString *const kMPSettingsKeyFilesForDatabases;
|
APPKIT_EXTERN NSString *const kMPSettingsKeyRememeberdKeysForDatabases;
|
||||||
APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases;
|
APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases;
|
||||||
/*
|
/*
|
||||||
APPKIT_EXTERN NSString *const kMPSettingsKeyLastKeyURL;
|
APPKIT_EXTERN NSString *const kMPSettingsKeyLastKeyURL;
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ NSString *const kMPSettingsKeyLegacyHidePassword = @"LegacyHidePassword";
|
|||||||
NSString *const kMPSettingsKeyLegacyHideNotes = @"LegacyHideNotes";
|
NSString *const kMPSettingsKeyLegacyHideNotes = @"LegacyHideNotes";
|
||||||
NSString *const kMPSettingsKeyLegacyHideURL = @"LegacyHideURL";
|
NSString *const kMPSettingsKeyLegacyHideURL = @"LegacyHideURL";
|
||||||
|
|
||||||
NSString *const kMPSettingsKeyLastDatabasePath = @"MPLastDatabasePath";
|
NSString *const kMPSettingsKeyLastDatabasePath = @"LastDatabasePath";
|
||||||
NSString *const kMPSettingsKeyFilesForDatabases = @"MPKeyFilesForDatabases";
|
NSString *const kMPSettingsKeyRememeberdKeysForDatabases = @"RememeberdKeysForDatabases";
|
||||||
NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"kMPSettingsKeyRememberKeyFilesForDatabases";
|
NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"RememberKeyFilesForDatabases";
|
||||||
|
|
||||||
@implementation MPSettingsHelper
|
@implementation MPSettingsHelper
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user