Skip to content

Commit

Permalink
toggle for touchid
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesnow committed Oct 22, 2019
1 parent 612a77f commit 8ceb5b7
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 26 deletions.
61 changes: 37 additions & 24 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="14868" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14868"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -15,6 +15,8 @@
<outlet property="messageInfoTextField" destination="268" id="ahE-sq-QzR"/>
<outlet property="passwordTextField" destination="338" id="495"/>
<outlet property="togglePasswordButton" destination="408" id="493"/>
<outlet property="touchidEnable" destination="1kC-WG-zEx" id="fJ1-V1-Hy3"/>
<outlet property="touchidEnabled" destination="j4Y-Si-3zB" id="KU9-Kd-G6I"/>
<outlet property="unlockButton" destination="2" id="ZRr-Ui-ExP"/>
<outlet property="useTouchIdButton" destination="yiJ-jb-FPV" id="ba2-8d-hCU"/>
<outlet property="view" destination="1" id="143"/>
Expand All @@ -23,13 +25,13 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView horizontalCompressionResistancePriority="751" translatesAutoresizingMaskIntoConstraints="NO" id="1">
<rect key="frame" x="0.0" y="0.0" width="527" height="390"/>
<rect key="frame" x="0.0" y="0.0" width="527" height="396"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2">
<rect key="frame" x="319" y="105" width="83" height="32"/>
<rect key="frame" x="319" y="108" width="83" 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"/>
<font key="font" metaFont="message"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
Expand All @@ -39,37 +41,37 @@ DQ
</connections>
</button>
<textField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="17">
<rect key="frame" x="117" y="158" width="45" height="16"/>
<rect key="frame" x="117" y="159" width="45" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Keyfile" id="18">
<font key="font" metaFont="system"/>
<font key="font" metaFont="message"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<pathControl verticalHuggingPriority="750" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="241" customClass="MPPathControl">
<rect key="frame" x="165" y="154" width="197" height="25"/>
<rect key="frame" x="165" y="155" width="197" height="25"/>
<pathCell key="cell" selectable="YES" editable="YES" alignment="left" pathStyle="popUp" id="242">
<font key="font" metaFont="system"/>
<font key="font" metaFont="message"/>
</pathCell>
</pathControl>
<imageView translatesAutoresizingMaskIntoConstraints="NO" id="262">
<rect key="frame" x="240" y="237" width="48" height="48"/>
<rect key="frame" x="240" y="243" width="48" height="48"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="273"/>
<constraint firstAttribute="width" constant="48" id="456"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="02_MessageBoxWarningTemplate" id="263"/>
</imageView>
<textField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="268">
<rect key="frame" x="209" y="213" width="110" height="16"/>
<rect key="frame" x="209" y="218" width="110" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Wrong password!" id="269">
<font key="font" metaFont="system"/>
<font key="font" metaFont="message"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<secureTextField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="338" customClass="HNHUISecureTextField">
<rect key="frame" x="168" y="185" width="191" height="20"/>
<rect key="frame" x="168" y="186" width="191" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="191" id="389"/>
</constraints>
Expand All @@ -86,34 +88,34 @@ DQ
</connections>
</secureTextField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="408">
<rect key="frame" x="367" y="182" width="29" height="23"/>
<rect key="frame" x="367" y="187" width="29" height="23"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSQuickLookTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="409">
<behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
<font key="font" metaFont="message"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="486">
<rect key="frame" x="367" y="152" width="29" height="23"/>
<rect key="frame" x="367" y="155" width="29" height="23"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" 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"/>
<font key="font" metaFont="message"/>
</buttonCell>
<connections>
<action selector="resetKeyFile:" target="-2" id="2Zh-0g-L0i"/>
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="d8O-Ha-rrS">
<rect key="frame" x="81" y="186" width="81" height="18"/>
<rect key="frame" x="81" y="189" width="81" height="18"/>
<buttonCell key="cell" type="check" title="Password" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="IU9-5u-jn9">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
<font key="font" metaFont="message"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2pb-ZG-spA">
<rect key="frame" x="237" y="105" width="82" height="32"/>
<rect key="frame" x="237" y="108" width="82" 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"/>
<font key="font" metaFont="message"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
Expand All @@ -123,13 +125,24 @@ Gw
</connections>
</button>
<button verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yiJ-jb-FPV">
<rect key="frame" x="319" y="72" width="83" height="32"/>
<rect key="frame" x="319" y="78" width="83" height="32"/>
<buttonCell key="cell" type="push" title="Touch ID" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="q5e-8s-SGL">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<font key="font" metaFont="message"/>
</buttonCell>
<connections>
<action selector="showTouchIdDialog:" target="-2" id="tJA-VM-Ci1"/>
<action selector="unlockTrigger:" target="-2" id="xXQ-oN-9ol"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="j4Y-Si-3zB">
<rect key="frame" x="241" y="87" width="76" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Touch ID" bezelStyle="regularSquare" imagePosition="left" inset="2" id="1kC-WG-zEx">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="message"/>
</buttonCell>
<connections>
<action selector="turnOnTouchID:" target="-2" id="7f2-5T-a4G"/>
</connections>
</button>
</subviews>
Expand Down
7 changes: 7 additions & 0 deletions MacPass/Keychain/MPOSHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@

#import <Cocoa/Cocoa.h>
@import LocalAuthentication;
#import "MPOSHelper.h"
#import "MPDocument.h"
#import "SAMKeychain.h"
#import "SAMKeychainQuery.h"
#import "MPSettingsHelper.h"

@interface MPOSHelper : NSObject

+(BOOL)supportsTouchID;
-(void)askForTouchID:(NSString*)password document:(NSString *)doc;
-(void)deletePasswordFromKeychain:(NSString *)doc;

@end
84 changes: 84 additions & 0 deletions MacPass/Keychain/MPOSHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
//

#import "MPOSHelper.h"
#import "MPDocument.h"
#import "SAMKeychain.h"
#import "SAMKeychainQuery.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "MPSettingsHelper.h"

@implementation MPOSHelper

Expand Down Expand Up @@ -38,4 +43,83 @@ +(BOOL)supportsTouchID {
return NO;
}

-(void) askForTouchID:(NSString*)password document:(NSString *)doc {
NSError *authError = nil;
LAContext *myContext = [LAContext new];
if (@available(macOS 10.12.2, *)) {
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {

NSAlert *alert = [NSAlert new];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
alert.messageText = NSLocalizedString(@"ALERT_TOUCH_ID_MESSAGE", @"");
alert.informativeText = NSLocalizedString(@"ALERT_TOUCH_ID_DESCRIPTION", @"");
[alert setAlertStyle:NSAlertStyleInformational];

if ([alert runModal] == NSAlertFirstButtonReturn) {
// Yes clicked, use TouchID
[self _savePasswordInKeychain:password document:doc];
} else {
NSLog(@"User denied Touch ID. Deleting password from keychain.");
[self deletePasswordFromKeychain:doc];
}
}
else {
NSAlert *alert = [NSAlert new];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
alert.messageText = NSLocalizedString(@"ALERT_TOUCH_ID_MESSAGE", @"");
alert.informativeText = NSLocalizedString(@"ALERT_TOUCH_ID_DESCRIPTION", @"");
[alert setAlertStyle:NSAlertStyleInformational];

if ([alert runModal] == NSAlertFirstButtonReturn) {
// Yes clicked, use TouchID
[self _savePasswordInKeychain:password document:doc];
} else {
NSLog(@"User denied Touch ID. Deleting password from keychain.");
[self deletePasswordFromKeychain:doc];
}
}
}
else {
// Fallback on earlier versions

}
}
- (void) _savePasswordInKeychain:(NSString*)password document:(NSString *)dbName {
// MPDocument *document = doc;
// Uses document name -- could also attach file path
// However, if the file is move and/or filename is changes it will fail
// NSString *dbName = document.displayName;
NSError *error = nil;

[SAMKeychain setPassword:password forService:@"MacPass" account:dbName];


if (error == nil) {
[MPSettingsHelper addTouchIdEnabledDatabaseWithName:dbName]; //Add DB name in the list of Touch ID enabled databases
NSLog(@"Saved DB (%@) password in the keychain.", dbName);
} else {
NSLog(@"Error updating keychain with DB password: %@", error.localizedDescription);
}
}

- (void) deletePasswordFromKeychain:(NSString *)dbName {
// MPDocument *document = doc;
// Uses document name -- could also attach file path
// However, if the file is moved and/or the filename is changed it will fail
// NSString *dbName = document.displayName;
NSError *error = nil;



if (error == nil) {
[SAMKeychain deletePasswordForService:@"MacPass" account:dbName];
[MPSettingsHelper removeTouchIdEnabledDatabaseWithName:dbName]; //Remove DB name from the list of Touch ID enabled databases
NSLog(@"DB (%@) password deleted from keychain.", dbName);
} else {
NSLog(@"Error deleting DB password from the keychain: %@", error.localizedDescription);
}
}

@end
1 change: 0 additions & 1 deletion MacPass/MPPasswordInputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ typedef BOOL (^passwordInputCompletionBlock)(NSString *password, NSURL *keyURL,
- (void)requestPasswordWithCompletionHandler:(passwordInputCompletionBlock)completionHandler;
- (void)requestPasswordWithMessage:(NSString *)message cancelLabel:(NSString *)cancelLabel completionHandler:(passwordInputCompletionBlock)completionHandler;


@end
Loading

0 comments on commit 8ceb5b7

Please sign in to comment.