forked from MacPass/MacPass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted the logic for storing the encrypted compositekey into a
seperate class
- Loading branch information
Julius Zint
committed
Mar 14, 2021
1 parent
3c54cd9
commit d1690d7
Showing
4 changed files
with
94 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// MPTouchIdCompositeKeyStore.h | ||
// MacPass | ||
// | ||
// Created by Julius Zint on 14.03.21. | ||
// Copyright © 2021 HicknHack Software GmbH. All rights reserved. | ||
// | ||
|
||
#ifndef MPTouchIdCompositeKeyStore_h | ||
#define MPTouchIdCompositeKeyStore_h | ||
|
||
static NSMutableDictionary* touchIDSecuredPasswords; | ||
|
||
@interface MPTouchIdCompositeKeyStore : NSObject | ||
@property (class, strong, readonly) MPTouchIdCompositeKeyStore *defaultStore; | ||
|
||
- (void) save:(NSData*) encryptedCompositeKey forDocumentKey:(NSString*) documentKey; | ||
- (bool) load:(NSData**) encryptedCompositeKey forDocumentKey:(NSString*) documentKey; | ||
@end | ||
|
||
#endif /* MPTouchIdCompositeKeyStore_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// MPTouchIdCompositeKeyStore.m | ||
// MacPass | ||
// | ||
// Created by Julius Zint on 14.03.21. | ||
// Copyright © 2021 HicknHack Software GmbH. All rights reserved. | ||
// | ||
#import "MPSettingsHelper.h" | ||
#import "MPTouchIdCompositeKeyStore.h" | ||
|
||
@implementation MPTouchIdCompositeKeyStore | ||
|
||
+ (instancetype)defaultStore { | ||
static MPTouchIdCompositeKeyStore *instance; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
instance = [[MPTouchIdCompositeKeyStore alloc] init]; | ||
if(touchIDSecuredPasswords == NULL) { | ||
touchIDSecuredPasswords = [[NSMutableDictionary alloc]init]; | ||
} | ||
}); | ||
return instance; | ||
} | ||
|
||
- (void) save: (NSData*) encryptedCompositeKey forDocumentKey:(NSString*) documentKey { | ||
long touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyEntryTouchIdEnabled]; | ||
if (touchIdMode == NSControlStateValueMixed) { | ||
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey]; | ||
if(encryptedCompositeKey != NULL) { | ||
[touchIDSecuredPasswords setObject:encryptedCompositeKey forKey:documentKey]; | ||
} | ||
} | ||
else if(touchIdMode == NSControlStateValueOn) { | ||
[touchIDSecuredPasswords removeObjectForKey:documentKey]; | ||
if(encryptedCompositeKey != NULL) { | ||
[NSUserDefaults.standardUserDefaults setObject:encryptedCompositeKey forKey:documentKey]; | ||
} | ||
} | ||
else { | ||
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey]; | ||
[touchIDSecuredPasswords removeObjectForKey:documentKey]; | ||
} | ||
} | ||
|
||
- (bool) load: (NSData**) encryptedCompositeKey forDocumentKey: (NSString*) documentKey { | ||
long touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyEntryTouchIdEnabled]; | ||
NSData* transientKey = [touchIDSecuredPasswords valueForKey:documentKey]; | ||
NSData* persistentKey =[NSUserDefaults.standardUserDefaults dataForKey:documentKey]; | ||
if(transientKey == NULL && persistentKey == NULL) { | ||
return false; | ||
} | ||
if(transientKey == NULL || persistentKey == NULL) { | ||
*encryptedCompositeKey = transientKey == NULL ? persistentKey : transientKey; | ||
return true; | ||
} | ||
if(touchIdMode == NSControlStateValueOn) { | ||
*encryptedCompositeKey = persistentKey; | ||
return true; | ||
} | ||
*encryptedCompositeKey = transientKey; | ||
return true; | ||
} | ||
|
||
@end |