@@ -14,13 +14,54 @@ var available = function () {
14
14
} ) ;
15
15
} ;
16
16
17
+ /**
18
+ * this 'default' method uses keychain instead of localauth so the passcode fallback can be used
19
+ */
17
20
var verifyFingerprint = function ( arg ) {
21
+ return new Promise ( function ( resolve , reject ) {
22
+ try {
23
+
24
+ if ( keychainItemServiceName === null ) {
25
+ var bundleID = NSBundle . mainBundle ( ) . infoDictionary . objectForKey ( "CFBundleIdentifier" ) ;
26
+ keychainItemServiceName = bundleID + ".TouchID" ;
27
+ }
28
+
29
+ if ( ! createKeyChainEntry ( ) ) {
30
+ verifyFingerprint ( arg ) ;
31
+ } else {
32
+ var message = arg !== null && arg . message || "Scan your finger" ;
33
+ var query = NSMutableDictionary . alloc ( ) . init ( ) ;
34
+ query . setObjectForKey ( kSecClassGenericPassword , kSecClass ) ;
35
+ query . setObjectForKey ( keychainItemIdentifier , kSecAttrAccount ) ;
36
+ query . setObjectForKey ( keychainItemServiceName , kSecAttrService ) ;
37
+ query . setObjectForKey ( message , kSecUseOperationPrompt ) ;
38
+
39
+ // Start the query and the fingerprint scan and/or device passcode validation
40
+ var res = SecItemCopyMatching ( query , null ) ;
41
+ if ( res === 0 ) { // 0 = ok (match, not canceled)
42
+ resolve ( ) ;
43
+ } else {
44
+ reject ( res ) ;
45
+ }
46
+ }
47
+
48
+ } catch ( ex ) {
49
+ console . log ( "Error in touchid.verifyFingerprint: " + ex ) ;
50
+ reject ( ex ) ;
51
+ }
52
+ } ) ;
53
+ } ;
54
+
55
+ /**
56
+ * This implementation uses LocalAuthentication and has no built-in passcode fallback
57
+ */
58
+ var verifyFingerprintWithCustomFallback = function ( arg ) {
18
59
return new Promise ( function ( resolve , reject ) {
19
60
try {
20
61
var laContext = LAContext . alloc ( ) . init ( ) ;
21
62
if ( laContext . canEvaluatePolicyError ( LAPolicyDeviceOwnerAuthenticationWithBiometrics , null ) ) {
22
- var message = arg != null && arg . message || "Scan your finger" ;
23
- if ( arg != null && arg . fallbackMessage ) {
63
+ var message = arg !== null && arg . message || "Scan your finger" ;
64
+ if ( arg !== null && arg . fallbackMessage ) {
24
65
laContext . localizedFallbackTitle = arg . fallbackMessage ;
25
66
}
26
67
laContext . evaluatePolicyLocalizedReasonReply (
@@ -44,46 +85,6 @@ var verifyFingerprint = function (arg) {
44
85
} ) ;
45
86
} ;
46
87
47
- var verifyFingerprintWithPasscodeFallback = function ( arg ) {
48
- return new Promise ( function ( resolve , reject ) {
49
- try {
50
-
51
- if ( keychainItemServiceName == null ) {
52
- var bundleID = NSBundle . mainBundle ( ) . infoDictionary . objectForKey ( "CFBundleIdentifier" ) ;
53
- keychainItemServiceName = bundleID + ".TouchID" ;
54
- console . log ( "---- keychainItemServiceName " + keychainItemServiceName ) ;
55
- }
56
-
57
- if ( ! createKeyChainEntry ( ) ) {
58
- console . log ( "Keychain trouble. Falling back to verifyFingerprintWithCustomPasswordFallback." ) ;
59
- verifyFingerprintWithCustomPasswordFallback ( arg ) ;
60
- } else {
61
-
62
- var message = arg != null && arg . message || "Scan your finger" ;
63
- console . log ( "message: " + message ) ;
64
-
65
- var query = NSMutableDictionary . alloc ( ) . init ( ) ;
66
- query . setObjectForKey ( kSecClassGenericPassword , kSecClass ) ;
67
- query . setObjectForKey ( keychainItemIdentifier , kSecAttrAccount ) ;
68
- query . setObjectForKey ( keychainItemServiceName , kSecAttrService ) ;
69
- query . setObjectForKey ( message , kSecUseOperationPrompt ) ;
70
-
71
- console . log ( "query: " + query ) ;
72
-
73
- // Start the query and the fingerprint scan and/or device passcode validation
74
- var res = SecItemCopyMatching ( query , null ) ;
75
- console . log ( "res: " + res ) ; // 0 = noErr
76
- resolve ( res == noErr ) ;
77
- }
78
- //}
79
-
80
- } catch ( ex ) {
81
- console . log ( "Error in touchid.verifyFingerprint: " + ex ) ;
82
- reject ( ex ) ;
83
- }
84
- } ) ;
85
- } ;
86
-
87
88
var createKeyChainEntry = function ( ) {
88
89
var attributes = NSMutableDictionary . alloc ( ) . init ( ) ;
89
90
attributes . setObjectForKey ( kSecClassGenericPassword , kSecClass ) ;
@@ -97,7 +98,7 @@ var createKeyChainEntry = function () {
97
98
kSecAccessControlUserPresence ,
98
99
null
99
100
) ;
100
- if ( accessControlRef == null ) {
101
+ if ( accessControlRef === null ) {
101
102
console . log ( "Can't store identifier '" + keychainItemIdentifier + "' in the KeyChain: " + accessControlError + "." ) ;
102
103
return false ;
103
104
} else {
@@ -117,4 +118,4 @@ var createKeyChainEntry = function () {
117
118
118
119
exports . available = available ;
119
120
exports . verifyFingerprint = verifyFingerprint ;
120
- exports . verifyFingerprintWithPasscodeFallback = verifyFingerprintWithPasscodeFallback ;
121
+ exports . verifyFingerprintWithCustomFallback = verifyFingerprintWithCustomFallback ;
0 commit comments