@@ -186,7 +186,11 @@ class KeychainModule(reactContext: ReactApplicationContext) :
186
186
val level = getSecurityLevelOrDefault(options)
187
187
val storage = getSelectedStorage(options)
188
188
throwIfInsufficientLevel(storage, level)
189
- val promptInfo = getPromptInfo(options)
189
+ val accessControl = getAccessControlOrDefault(options)
190
+ val usePasscode = getUsePasscode(accessControl) && isPasscodeAvailable
191
+ val useBiometry =
192
+ getUseBiometry(accessControl) && (isFingerprintAuthAvailable || isFaceAuthAvailable || isIrisAuthAvailable)
193
+ val promptInfo = getPromptInfo(options, usePasscode, useBiometry)
190
194
val result =
191
195
encryptToResult(alias, storage, username, password, level, promptInfo)
192
196
prefsStorage.storeEncryptedEntry(alias, result)
@@ -249,7 +253,11 @@ class KeychainModule(reactContext: ReactApplicationContext) :
249
253
return @launch
250
254
}
251
255
val storageName = resultSet.cipherStorageName
252
- val promptInfo = getPromptInfo(options)
256
+ val accessControl = getAccessControlOrDefault(options)
257
+ val usePasscode = getUsePasscode(accessControl) && isPasscodeAvailable
258
+ val useBiometry =
259
+ getUseBiometry(accessControl) && (isFingerprintAuthAvailable || isFaceAuthAvailable || isIrisAuthAvailable)
260
+ val promptInfo = getPromptInfo(options, usePasscode, useBiometry)
253
261
val cipher = getCipherStorageByName(storageName)
254
262
val decryptionResult =
255
263
decryptCredentials(alias, cipher!! , resultSet, promptInfo)
@@ -295,9 +303,7 @@ class KeychainModule(reactContext: ReactApplicationContext) :
295
303
for (cipher in ciphers) {
296
304
val aliases = cipher!! .getAllKeys()
297
305
for (alias in aliases) {
298
- if (alias != WARMING_UP_ALIAS ) {
299
- result.add(alias)
300
- }
306
+ result.add(alias)
301
307
}
302
308
}
303
309
return result
@@ -384,6 +390,17 @@ class KeychainModule(reactContext: ReactApplicationContext) :
384
390
resetGenericPassword(alias, promise)
385
391
}
386
392
393
+ @ReactMethod
394
+ fun isPasscodeAuthAvailable (promise : Promise ) {
395
+ try {
396
+ val reply: Boolean = DeviceAvailability .isDevicePasscodeAvailable(reactApplicationContext)
397
+ promise.resolve(reply)
398
+ } catch (fail: Throwable ) {
399
+ Log .e(KEYCHAIN_MODULE , fail.message, fail)
400
+ promise.reject(Errors .E_UNKNOWN_ERROR , fail)
401
+ }
402
+ }
403
+
387
404
@ReactMethod
388
405
fun getSupportedBiometryType (promise : Promise ) {
389
406
try {
@@ -542,14 +559,6 @@ class KeychainModule(reactContext: ReactApplicationContext) :
542
559
oldCipherStorage.removeKey(service)
543
560
}
544
561
545
- @get:Throws(CryptoFailedException ::class )
546
- val cipherStorageForCurrentAPILevel: CipherStorage
547
- /* *
548
- * The "Current" CipherStorage is the cipherStorage with the highest API level that is lower
549
- * than or equal to the current API level
550
- */
551
- get() = getCipherStorageForCurrentAPILevel(true , true )
552
-
553
562
/* *
554
563
* The "Current" CipherStorage is the cipherStorage with the highest API level that is lower than
555
564
* or equal to the current API level. Parameter allow to reduce level.
@@ -620,7 +629,7 @@ class KeychainModule(reactContext: ReactApplicationContext) :
620
629
621
630
val isPasscodeAvailable: Boolean
622
631
/* * Is secured hardware a part of current storage or not. */
623
- get() = DeviceAvailability .isDeviceCredentialAuthAvailable (reactApplicationContext)
632
+ get() = DeviceAvailability .isDevicePasscodeAvailable (reactApplicationContext)
624
633
625
634
/* * Resolve storage to security level it provides. */
626
635
private fun getSecurityLevel (useBiometry : Boolean , usePasscode : Boolean ): SecurityLevel {
@@ -646,7 +655,6 @@ class KeychainModule(reactContext: ReactApplicationContext) :
646
655
const val FACE_SUPPORTED_NAME = " Face"
647
656
const val IRIS_SUPPORTED_NAME = " Iris"
648
657
const val EMPTY_STRING = " "
649
- const val WARMING_UP_ALIAS = " warmingUp"
650
658
private val LOG_TAG = KeychainModule ::class .java.simpleName
651
659
652
660
@@ -731,10 +739,11 @@ class KeychainModule(reactContext: ReactApplicationContext) :
731
739
}
732
740
733
741
/* * Extract user specified prompt info from options. */
734
- private fun getPromptInfo (options : ReadableMap ? ): PromptInfo {
735
- val accessControl = getAccessControlOrDefault(options)
736
- val usePasscode = getUsePasscode(accessControl)
737
- val useBiometry = getUseBiometry(accessControl)
742
+ private fun getPromptInfo (
743
+ options : ReadableMap ? ,
744
+ usePasscode : Boolean ,
745
+ useBiometry : Boolean
746
+ ): PromptInfo {
738
747
val promptInfoOptionsMap =
739
748
if (options != null && options.hasKey(Maps .AUTH_PROMPT )) options.getMap(Maps .AUTH_PROMPT )
740
749
else null
@@ -750,22 +759,20 @@ class KeychainModule(reactContext: ReactApplicationContext) :
750
759
promptInfoBuilder.setDescription(it)
751
760
}
752
761
753
- val allowedAuthenticators = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
754
- when {
755
- usePasscode && useBiometry ->
756
- BiometricManager .Authenticators .BIOMETRIC_STRONG or BiometricManager .Authenticators .DEVICE_CREDENTIAL
762
+ val allowedAuthenticators = when {
763
+ usePasscode && useBiometry ->
764
+ BiometricManager .Authenticators .BIOMETRIC_STRONG or BiometricManager .Authenticators .DEVICE_CREDENTIAL
757
765
758
- usePasscode ->
759
- BiometricManager .Authenticators .DEVICE_CREDENTIAL
766
+ usePasscode ->
767
+ BiometricManager .Authenticators .DEVICE_CREDENTIAL
760
768
761
- else ->
762
- BiometricManager .Authenticators .BIOMETRIC_STRONG
763
- }
764
- } else {
765
- BiometricManager .Authenticators .BIOMETRIC_STRONG
769
+ else ->
770
+ null
766
771
}
767
772
768
- promptInfoBuilder.setAllowedAuthenticators(allowedAuthenticators)
773
+ if (allowedAuthenticators != null ) {
774
+ promptInfoBuilder.setAllowedAuthenticators(allowedAuthenticators)
775
+ }
769
776
770
777
if (! usePasscode) {
771
778
promptInfoOptionsMap?.getString(AuthPromptOptions .CANCEL )?.let {
0 commit comments