Refactored naming. Added better handling of settings for touchID

This commit is contained in:
Michael Starke 2022-09-01 23:45:03 +02:00
parent 76adcf74d4
commit 49326013fb
4 changed files with 32 additions and 6 deletions

View File

@ -108,11 +108,11 @@
self.touchIdModeButton.menu = touchIDMenu;
[self.touchIdModeButton bind:NSSelectedTagBinding
toObject:NSUserDefaultsController.sharedUserDefaultsController
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEntryTouchIdEnabled]
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyTouchIdEnabled]
options:nil];
[self.touchIdEnabledButton bind:NSValueBinding
toObject:NSUserDefaultsController.sharedUserDefaultsController
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEntryTouchIdEnabled]
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyTouchIdEnabled]
options:nil];
self.touchIdEnabledButton.hidden = YES;
if (@available(macOS 10.13.4, *)) {

View File

@ -23,7 +23,8 @@
#import <Cocoa/Cocoa.h>
/* TouchID */
APPKIT_EXTERN NSString *const kMPSettingsKeyEntryTouchIdEnabled;
APPKIT_EXTERN NSString *const kMPSettingsKeyTouchIdEnabled;
APPKIT_EXTERN NSString *const kMPSettingsKeyTouchIdEncryptedKeyStore; // NSDictionary with hased file names mapped to keys
APPKIT_EXTERN NSString *const kMPSettingsKeyEntryTouchIdDatabaseEncryptedKeyFormat;
/* Clipboard */

View File

@ -67,7 +67,8 @@ NSString *const kMPSettingsKeyAutotypeMatchHost = @"Au
NSString *const kMPSettingsKeyAutotypeMatchTags = @"AutotypeMatchTags";
NSString *const kMPSettingsKeyGloablAutotypeAlwaysShowCandidateSelection = @"GloablAutotypeAlwaysShowCandidateSelection";
NSString *const kMPSettingsKeyEntryTouchIdEnabled = @"EnableSubsequentUnlocksWithTouchID";
NSString *const kMPSettingsKeyTouchIdEnabled = @"EnableSubsequentUnlocksWithTouchID";
NSString *const kMPSettingsKeyTouchIdEncryptedKeyStore = @"TouchIdEncryptedKeyStore";
NSString *const kMPSettingsKeyEntryTouchIdDatabaseEncryptedKeyFormat = @"EncryptedDatabaseKeyForTouchID-%@";
NSString *const kMPSettingsKeyEntrySearchFilterContext = @"EntrySearchFilterContext";

View File

@ -13,6 +13,7 @@
@interface MPTouchIdCompositeKeyStore ()
@property (readonly, strong) NSMutableDictionary* keys;
@property (nonatomic) NSInteger touchIdEnabledState;
@end
@implementation MPTouchIdCompositeKeyStore
@ -30,10 +31,31 @@
self = [super init];
if(self) {
_keys = [[NSMutableDictionary alloc] init];
[self bind:NSStringFromSelector(@selector(touchIdEnabledState))
toObject:NSUserDefaultsController.sharedUserDefaultsController
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyTouchIdEnabled]
options:nil];
}
return self;
}
- (void)setTouchIdEnabledState:(NSInteger)touchIdEnabledState {
switch(touchIdEnabledState) {
case NSControlStateValueMixed:
// clear persistent store
[NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyTouchIdEncryptedKeyStore];
break;
case NSControlStateValueOn:
// clear transient store
[self.keys removeAllObjects];
break;
default:
// clear persitent and transient store
[NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyTouchIdEncryptedKeyStore];
[self.keys removeAllObjects];
}
}
- (void)saveCompositeKey:(KPKCompositeKey *)compositeKey forDocumentKey:(NSString *)documentKey {
NSError *error;
NSData *encryptedCompositeKey = [self encryptedDataForCompositeKey:compositeKey error:&error];
@ -42,7 +64,9 @@
return;
}
NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyEntryTouchIdEnabled];
/* FIXME this behavour is wrong. Old keys do not get cleared so this leaves a lot of data behind that should be cleaned up*/
NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled];
switch(touchIdMode) {
case NSControlStateValueMixed:
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey];
@ -62,7 +86,7 @@
}
}
- (NSData *)loadEncryptedCompositeKeyForDocumentKey:(NSString *)documentKey {
NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyEntryTouchIdEnabled];
NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled];
NSData* transientKey = self.keys[documentKey];
NSData* persistentKey =[NSUserDefaults.standardUserDefaults dataForKey:documentKey];
if(nil == transientKey && nil == persistentKey) {