@@ -186,7 +186,11 @@ class KeychainModule(reactContext: ReactApplicationContext) :
186186 val level = getSecurityLevelOrDefault(options)
187187 val storage = getSelectedStorage(options)
188188 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)
190194 val result =
191195 encryptToResult(alias, storage, username, password, level, promptInfo)
192196 prefsStorage.storeEncryptedEntry(alias, result)
@@ -249,7 +253,11 @@ class KeychainModule(reactContext: ReactApplicationContext) :
249253 return @launch
250254 }
251255 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)
253261 val cipher = getCipherStorageByName(storageName)
254262 val decryptionResult =
255263 decryptCredentials(alias, cipher!! , resultSet, promptInfo)
@@ -295,9 +303,7 @@ class KeychainModule(reactContext: ReactApplicationContext) :
295303 for (cipher in ciphers) {
296304 val aliases = cipher!! .getAllKeys()
297305 for (alias in aliases) {
298- if (alias != WARMING_UP_ALIAS ) {
299- result.add(alias)
300- }
306+ result.add(alias)
301307 }
302308 }
303309 return result
@@ -384,6 +390,17 @@ class KeychainModule(reactContext: ReactApplicationContext) :
384390 resetGenericPassword(alias, promise)
385391 }
386392
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+
387404 @ReactMethod
388405 fun getSupportedBiometryType (promise : Promise ) {
389406 try {
@@ -542,14 +559,6 @@ class KeychainModule(reactContext: ReactApplicationContext) :
542559 oldCipherStorage.removeKey(service)
543560 }
544561
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-
553562 /* *
554563 * The "Current" CipherStorage is the cipherStorage with the highest API level that is lower than
555564 * or equal to the current API level. Parameter allow to reduce level.
@@ -620,7 +629,7 @@ class KeychainModule(reactContext: ReactApplicationContext) :
620629
621630 val isPasscodeAvailable: Boolean
622631 /* * Is secured hardware a part of current storage or not. */
623- get() = DeviceAvailability .isDeviceCredentialAuthAvailable (reactApplicationContext)
632+ get() = DeviceAvailability .isDevicePasscodeAvailable (reactApplicationContext)
624633
625634 /* * Resolve storage to security level it provides. */
626635 private fun getSecurityLevel (useBiometry : Boolean , usePasscode : Boolean ): SecurityLevel {
@@ -646,7 +655,6 @@ class KeychainModule(reactContext: ReactApplicationContext) :
646655 const val FACE_SUPPORTED_NAME = " Face"
647656 const val IRIS_SUPPORTED_NAME = " Iris"
648657 const val EMPTY_STRING = " "
649- const val WARMING_UP_ALIAS = " warmingUp"
650658 private val LOG_TAG = KeychainModule ::class .java.simpleName
651659
652660
@@ -731,10 +739,11 @@ class KeychainModule(reactContext: ReactApplicationContext) :
731739 }
732740
733741 /* * 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 {
738747 val promptInfoOptionsMap =
739748 if (options != null && options.hasKey(Maps .AUTH_PROMPT )) options.getMap(Maps .AUTH_PROMPT )
740749 else null
@@ -750,22 +759,20 @@ class KeychainModule(reactContext: ReactApplicationContext) :
750759 promptInfoBuilder.setDescription(it)
751760 }
752761
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
757765
758- usePasscode ->
759- BiometricManager .Authenticators .DEVICE_CREDENTIAL
766+ usePasscode ->
767+ BiometricManager .Authenticators .DEVICE_CREDENTIAL
760768
761- else ->
762- BiometricManager .Authenticators .BIOMETRIC_STRONG
763- }
764- } else {
765- BiometricManager .Authenticators .BIOMETRIC_STRONG
769+ else ->
770+ null
766771 }
767772
768- promptInfoBuilder.setAllowedAuthenticators(allowedAuthenticators)
773+ if (allowedAuthenticators != null ) {
774+ promptInfoBuilder.setAllowedAuthenticators(allowedAuthenticators)
775+ }
769776
770777 if (! usePasscode) {
771778 promptInfoOptionsMap?.getString(AuthPromptOptions .CANCEL )?.let {
0 commit comments