mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-19 00:19:22 +00:00
Code refactoring to implement suggestions from the code review.
Renamed touchIdEnabled outlet to touchIdEnabledButton in preparation to bind a variable to the state value. Used SecKeyCreateRandomKey instead of SecKeyGeneratePair as suggested by the headers.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
@@ -17,7 +16,7 @@
|
||||
<outlet property="passwordTextField" destination="338" id="495"/>
|
||||
<outlet property="togglePasswordButton" destination="408" id="493"/>
|
||||
<outlet property="touchIdButton" destination="mQA-C0-JyU" id="fM3-PG-1OB"/>
|
||||
<outlet property="touchIdEnabled" destination="Hs8-Tc-ezo" id="9Go-LQ-mSw"/>
|
||||
<outlet property="touchIdEnabledButton" destination="Hs8-Tc-ezo" id="9Go-LQ-mSw"/>
|
||||
<outlet property="unlockButton" destination="2" id="ZRr-Ui-ExP"/>
|
||||
<outlet property="view" destination="1" id="143"/>
|
||||
</connections>
|
||||
|
||||
@@ -49,7 +49,7 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
@property (weak) IBOutlet NSButton *unlockButton;
|
||||
@property (weak) IBOutlet NSButton *cancelButton;
|
||||
@property (weak) IBOutlet NSButton *touchIdButton;
|
||||
@property (weak) IBOutlet NSButton *touchIdEnabled;
|
||||
@property (weak) IBOutlet NSButton *touchIdEnabledButton;
|
||||
|
||||
@property (copy) NSString *message;
|
||||
@property (copy) NSString *cancelLabel;
|
||||
@@ -90,10 +90,10 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
[self.enablePasswordCheckBox bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil];
|
||||
[self.togglePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil];
|
||||
[self.passwordTextField bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil];
|
||||
self.touchIdEnabled.hidden = true;
|
||||
self.touchIdEnabledButton.hidden = true;
|
||||
if (@available(macOS 10.13.4, *)) {
|
||||
self.touchIdEnabled.hidden = false;
|
||||
self.touchIdEnabled.state = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyEntryTouchIdEnabled];
|
||||
self.touchIdEnabledButton.hidden = false;
|
||||
self.touchIdEnabledButton.state = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyEntryTouchIdEnabled];
|
||||
[self _touchIdUpdateToolTip];
|
||||
}
|
||||
[self _reset];
|
||||
@@ -167,13 +167,13 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
|
||||
- (void) _touchIdUpdateKeyForCurrentDocument: (KPKCompositeKey*)compositeKey forDocumentKey: (NSString*) documentKey{
|
||||
NSData* encryptedKey = [self _touchIdEncryptCompositeKey:compositeKey];
|
||||
if (self.touchIdEnabled.state == NSControlStateValueMixed) {
|
||||
if (self.touchIdEnabledButton.state == NSControlStateValueMixed) {
|
||||
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey];
|
||||
if(encryptedKey != NULL) {
|
||||
[touchIDSecuredPasswords setObject:encryptedKey forKey:documentKey];
|
||||
}
|
||||
}
|
||||
else if(self.touchIdEnabled.state == NSControlStateValueOn) {
|
||||
else if(self.touchIdEnabledButton.state == NSControlStateValueOn) {
|
||||
[touchIDSecuredPasswords removeObjectForKey:documentKey];
|
||||
if(encryptedKey != NULL) {
|
||||
[NSUserDefaults.standardUserDefaults setObject:encryptedKey forKey:documentKey];
|
||||
@@ -222,16 +222,13 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
(id)kSecAttrLabel: publicKeyLabel,
|
||||
},
|
||||
};
|
||||
SecKeyRef privateKey = NULL;
|
||||
SecKeyRef publicKey = NULL;
|
||||
OSStatus result = SecKeyGeneratePair((__bridge CFDictionaryRef)attributes, &privateKey, &publicKey);
|
||||
if(result == errSecSuccess) {
|
||||
CFRelease(publicKey);
|
||||
CFRelease(privateKey);
|
||||
SecKeyRef result = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes, &error);
|
||||
if(result == NULL) {
|
||||
NSError *err = CFBridgingRelease(error);
|
||||
NSLog(@"Error while trying to create a RSA keypair for TouchID unlock feature: %@", [err description]);
|
||||
}
|
||||
else {
|
||||
NSString* description = (__bridge NSString*)SecCopyErrorMessageString(result, NULL);
|
||||
NSLog(@"Error while trying to create a RSA keypair for TouchID unlock feature: %@", description);
|
||||
CFRelease(result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -350,7 +347,7 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
*result = transientKey == NULL ? persistentKey : transientKey;
|
||||
return true;
|
||||
}
|
||||
if(self.touchIdEnabled.state == NSControlStateValueOn) {
|
||||
if(self.touchIdEnabledButton.state == NSControlStateValueOn) {
|
||||
*result = persistentKey;
|
||||
return true;
|
||||
}
|
||||
@@ -370,24 +367,28 @@ static NSMutableDictionary* touchIDSecuredPasswords;
|
||||
return;
|
||||
}
|
||||
NSError* error;
|
||||
self.completionHandler(compositeKey, NULL, false, &error);
|
||||
bool success = self.completionHandler(compositeKey, NULL, false, &error);
|
||||
if(success) {
|
||||
return;
|
||||
}
|
||||
[self.touchIdEnabledButton setEnabled:false];
|
||||
[self _showError:error];
|
||||
}
|
||||
|
||||
- (IBAction)touchIdEnabledChanged:(id)sender {
|
||||
[NSUserDefaults.standardUserDefaults setInteger: self.touchIdEnabled.state forKey:kMPSettingsKeyEntryTouchIdEnabled];
|
||||
[NSUserDefaults.standardUserDefaults setInteger: self.touchIdEnabledButton.state forKey:kMPSettingsKeyEntryTouchIdEnabled];
|
||||
[self _touchIdUpdateToolTip];
|
||||
}
|
||||
|
||||
- (void) _touchIdUpdateToolTip {
|
||||
if(self.touchIdEnabled.state == NSControlStateValueOn) {
|
||||
self.touchIdEnabled.toolTip = @"Unlocking via TouchID is enabled";
|
||||
if(self.touchIdEnabledButton.state == NSControlStateValueOn) {
|
||||
self.touchIdEnabledButton.toolTip = @"Unlocking via TouchID is enabled";
|
||||
}
|
||||
else if(self.touchIdEnabled.state == NSControlStateValueOff) {
|
||||
self.touchIdEnabled.toolTip = @"Unlocking via TouchID is disabled";
|
||||
else if(self.touchIdEnabledButton.state == NSControlStateValueOff) {
|
||||
self.touchIdEnabledButton.toolTip = @"Unlocking via TouchID is disabled";
|
||||
}
|
||||
else {
|
||||
self.touchIdEnabled.toolTip = @"Unlocking via TouchID is possible until MacPass is restarted";
|
||||
self.touchIdEnabledButton.toolTip = @"Unlocking via TouchID is possible until MacPass is restarted";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user