We implemented new android.hardware.biometrics.BiometricPrompt replacing the existing android.hardware.fingerprint. The new Biometrics API works as expected until we have the 'Preferred Biometric' as 'Fingerprint'.
When we set the 'Preferred Biometric' as 'Face Recognition' & try to use the face recognition as the authentication mechanism for our application, we receive "java.security.SignatureException: android.security.KeyStoreException: Key user not authenticated" in onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result).
This issue seems to be reproducible in Samsung devices with Android P. It works fine in Pixel devices with Android P (I believe currently the Pixel device don't provide support for Face Recognition for third party application).
private BiometricPrompt.AuthenticationCallback getAuthenticationCallback() {
@Override
public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
Log.i(TAG, "onAuthenticationSucceeded");
super.onAuthenticationSucceeded(result);
Signature signature = result.getCryptoObject().getSignature();
try {
//Exception is thrown when we try to update the Signature with our message.
signature.update(mToBeSignedMessage.getBytes());
String signatureString = Base64.encodeToString(signature.sign(), Base64.URL_SAFE);
Log.i(TAG, "Message: " + mToBeSignedMessage);
Log.i(TAG, "Signature (Base64 EncodeD): " + signatureString);
Toast.makeText(getApplicationContext(), mToBeSignedMessage + ":" + signatureString, Toast.LENGTH_SHORT).show();
} catch (SignatureException e) {
Log.d(TAG, e.getLocalizedMessage());
//java.security.SignatureException: android.security.KeyStoreException: Key user not authenticated"
}
}
}
Why I am getting the "KeyStoreException: Key user not authenticated", while trying to update the signature value ONLY when the "Preferred Biometric" as 'Face Recognition'.