AndroidX Biometric API IRIS scan issue

37 Views Asked by At

We have recently migrated from old Fingerprint manager to new Android X Biometric API and now all biometric authentication is handled by this API in our app. I have found an issue with Samsung S9+ which has multiple biometric options. When I select Fingerprint or Iris option in device settings for biometric and login to my app. It shows me Fingerprint and IRIS options to login to the app . Just to note, I have only registered Fingerprint as my biometric to login to the app. But still I can login from iris and get inside the app.

I am not sure why my biometric keys are not getting invalidated when I try to login with non registered biometric i.e. IRIS.

**Code to create biometric key **

private val keyGenParameterSpec: KeyGenParameterSpec
    get() = KeyGenParameterSpec.Builder(
        BIOMETRICS_INTEGRITY_KEY_ALIAS,
        KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
    )
        .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
        // setUserAuthenticationRequired(true) is necessary to link our key with
        // the device biometrics
        .setUserAuthenticationRequired(true)
        .setInvalidatedByBiometricEnrollment(true)
        .build()

Biometric Prompt class:

fun authenticate(
    fragment: Fragment,
    params: BiometricDialogParams,
    onResult: (BiometricPromptResult) -> Unit
) {
    val promptInfo = BiometricPrompt.PromptInfo.Builder()
        .setTitle(params.title)
        .setDescription(params.description)
        .setConfirmationRequired(true)
        .setAllowedAuthenticators(Authenticators.BIOMETRIC_STRONG)
        .setNegativeButtonText(params.actionName)
        .build()
    
    val executor = ContextCompat.getMainExecutor(fragment.requireContext())
    val biometricsPrompt =
        BiometricPrompt(fragment, executor, authenticationCallbackHandler(fragment, onResult))

    try {
        val cryptoObject = BiometricPrompt.CryptoObject(biometricsKeyStore.getCipher())
        biometricsPrompt.authenticate(promptInfo, cryptoObject)
    } catch (exception: KeyPermanentlyInvalidatedException) {
        logException(exception)
        onResult(BiometricPromptResult.Changed)
    } catch (exception: Exception) {
        logException(exception)
    }
}
0

There are 0 best solutions below