mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 08:52:20 +00:00
reduced code complexity
added usage of storage typdef instead of AppKit values
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
|
||||
<capability name="Image references" minToolsVersion="12.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
@@ -29,7 +29,7 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="508" height="526"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2">
|
||||
<rect key="frame" x="323" y="169" width="78" height="32"/>
|
||||
<rect key="frame" x="325" y="169" width="77" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Unlock" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -89,14 +89,14 @@ DQ
|
||||
</connections>
|
||||
</secureTextField>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="408">
|
||||
<rect key="frame" x="351" y="246" width="50" height="32"/>
|
||||
<rect key="frame" x="351" y="246" width="51" height="32"/>
|
||||
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSQuickLookTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="409">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="486">
|
||||
<rect key="frame" x="351" y="216" width="50" height="32"/>
|
||||
<rect key="frame" x="351" y="216" width="51" height="32"/>
|
||||
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSStopProgressTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="487">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -113,7 +113,7 @@ DQ
|
||||
</buttonCell>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2pb-ZG-spA">
|
||||
<rect key="frame" x="249" y="169" width="76" height="32"/>
|
||||
<rect key="frame" x="251" y="169" width="76" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="erj-mR-UyO">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -134,7 +134,7 @@ Gw
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZpI-L9-oFW">
|
||||
<rect key="frame" x="153" y="130" width="247" height="40"/>
|
||||
<rect key="frame" x="153" y="130" width="248" height="40"/>
|
||||
<buttonCell key="cell" type="push" bezelStyle="rounded" imagePosition="overlaps" alignment="center" controlSize="large" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="H68-pk-x95">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -198,7 +198,7 @@ Gw
|
||||
<constraint firstItem="2" firstAttribute="leading" secondItem="2pb-ZG-spA" secondAttribute="trailing" constant="12" id="ytJ-5Z-5rT"/>
|
||||
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="ZpI-L9-oFW" secondAttribute="bottom" constant="1" id="zhU-C3-jab"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-25" y="11"/>
|
||||
<point key="canvasLocation" x="100" y="-94"/>
|
||||
</customView>
|
||||
</objects>
|
||||
<resources>
|
||||
|
||||
@@ -202,16 +202,12 @@
|
||||
return (nil != currentDocument.encryptedKeyData);
|
||||
}
|
||||
|
||||
- (NSData * _Nullable)_touchIdEncryptedCompositeKeyForCurrentDocutmen {
|
||||
- (IBAction)unlockWithTouchID:(id)sender {
|
||||
NSString* documentKey = [self biometricKeyForCurrentDocument];
|
||||
if(nil == documentKey) {
|
||||
return nil;
|
||||
return;
|
||||
}
|
||||
return [MPTouchIdCompositeKeyStore.defaultStore loadEncryptedCompositeKeyForDocumentKey:documentKey];
|
||||
}
|
||||
|
||||
- (IBAction)unlockWithTouchID:(id)sender {
|
||||
NSData* encryptedKey = [self _touchIdEncryptedCompositeKeyForCurrentDocutmen];
|
||||
NSData* encryptedKey = [MPTouchIdCompositeKeyStore.defaultStore loadEncryptedCompositeKeyForDocumentKey:documentKey];
|
||||
if(!encryptedKey) {
|
||||
self.touchIdButton.enabled = NO;
|
||||
return;
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
#import "MPSettingsHelper.h"
|
||||
#import "MPTouchIdCompositeKeyStore.h"
|
||||
#import "MPConstants.h"
|
||||
#import "MPSettingsHelper.h"
|
||||
|
||||
#import "NSError+Messages.h"
|
||||
|
||||
@interface MPTouchIdCompositeKeyStore ()
|
||||
@property (readonly, strong) NSMutableDictionary* keys;
|
||||
@property (nonatomic) NSInteger touchIdEnabledState;
|
||||
@property (nonatomic) MPTouchIDKeyStorage touchIdEnabledState;
|
||||
@end
|
||||
|
||||
@implementation MPTouchIdCompositeKeyStore
|
||||
@@ -39,13 +40,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setTouchIdEnabledState:(NSInteger)touchIdEnabledState {
|
||||
- (void)setTouchIdEnabledState:(MPTouchIDKeyStorage)touchIdEnabledState {
|
||||
switch(touchIdEnabledState) {
|
||||
case NSControlStateValueMixed:
|
||||
case MPTouchIDKeyStorageTransient:
|
||||
// clear persistent store
|
||||
[NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyTouchIdEncryptedKeyStore];
|
||||
break;
|
||||
case NSControlStateValueOn:
|
||||
case MPTouchIDKeyStoragePersistent:
|
||||
// clear transient store
|
||||
[self.keys removeAllObjects];
|
||||
break;
|
||||
@@ -66,29 +67,33 @@
|
||||
|
||||
/* 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];
|
||||
MPTouchIDKeyStorage touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled];
|
||||
switch(touchIdMode) {
|
||||
case NSControlStateValueMixed:
|
||||
case MPTouchIDKeyStorageTransient:
|
||||
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey];
|
||||
if(nil != encryptedCompositeKey) {
|
||||
self.keys[documentKey] = encryptedCompositeKey;
|
||||
}
|
||||
break;
|
||||
case NSControlStateValueOn:
|
||||
case MPTouchIDKeyStoragePersistent:
|
||||
self.keys[documentKey] = nil;
|
||||
if(nil != encryptedCompositeKey) {
|
||||
[NSUserDefaults.standardUserDefaults setObject:encryptedCompositeKey forKey:documentKey];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case MPTouchIDKeyStorageDisabled:
|
||||
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey];
|
||||
self.keys[documentKey] = nil;
|
||||
break;
|
||||
default:
|
||||
NSAssert(NO,@"Unsupported internal touchID preferences value.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
- (NSData *)loadEncryptedCompositeKeyForDocumentKey:(NSString *)documentKey {
|
||||
NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled];
|
||||
NSData* transientKey = self.keys[documentKey];
|
||||
NSData* persistentKey =[NSUserDefaults.standardUserDefaults dataForKey:documentKey];
|
||||
NSData* persistentKey = [NSUserDefaults.standardUserDefaults dataForKey:documentKey];
|
||||
if(nil == transientKey && nil == persistentKey) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user