Skip to content

Commit

Permalink
reduced code complexity
Browse files Browse the repository at this point in the history
added usage of storage typdef instead of AppKit values
  • Loading branch information
mstarke committed Oct 11, 2022
1 parent 24164d5 commit 289a27c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
6 changes: 3 additions & 3 deletions MacPass/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
16 changes: 8 additions & 8 deletions MacPass/Base.lproj/PasswordInputView.xib
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand All @@ -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"/>
Expand All @@ -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"/>
Expand Down Expand Up @@ -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>
Expand Down
10 changes: 3 additions & 7 deletions MacPass/MPPasswordInputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,12 @@ - (bool) _touchIdIsUnlockAvailable {
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;
Expand Down
23 changes: 14 additions & 9 deletions MacPass/MPTouchIdCompositeKeyStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,13 +40,13 @@ - (instancetype)init {
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;
Expand All @@ -66,29 +67,33 @@ - (void)saveCompositeKey:(KPKCompositeKey *)compositeKey forDocumentKey:(NSStrin

/* 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;
}
Expand Down

0 comments on commit 289a27c

Please sign in to comment.