react-native-keychain icon indicating copy to clipboard operation
react-native-keychain copied to clipboard

[question] Device fingerprint change

Open krutkowski86 opened this issue 5 years ago • 20 comments

How do I determine that user has changed (add/remove) fingerprint/touch id/face id?

krutkowski86 avatar Apr 24 '20 10:04 krutkowski86

why do you need this? Users cannot change biometric without passing the existing biometric verification first... so from security point of view, it does not matter, a user is still verified and valid.

P.S. depends on implementation on the device. Samsung just returns unique IDs for each fingerprint, but Huawei for example just returns the order number instead of unique IDs. (or vise versa, did not remember who is doing what correctly). But it's possible to detect.

OleksandrKucherenko avatar Apr 24 '20 11:04 OleksandrKucherenko

@OleksandrKucherenko What I meant was that someone could somehow add new fingerprint to our device which means that he can now authenticate in the app. Most of bank applications inform us about such change and requires standard (non biometric) authentication.

krutkowski86 avatar Apr 24 '20 12:04 krutkowski86

I’m not sure if it works but we have “Biometry current set” option. Try to find it in the docs.

koyta avatar Apr 25 '20 01:04 koyta

I'm using Keychain.ACCESS_CONTROL.BIOMETRY_CURRENT_SET - but it doesn't stop me from getting credentials after changing biometry settings (new fingerprint).

krutkowski86 avatar Apr 27 '20 12:04 krutkowski86

@OleksandrKucherenko android docs says something about setInvalidatedByBiometricEnrollment

// Invalidate the keys if the user has registered a new biometric // credential, such as a new fingerprint. Can call this method only // on Android 7.0 (API level 24) or higher. The variable // "invalidatedByBiometricEnrollment" is true by default.

https://developer.android.com/training/sign-in/biometric-auth#biometric-only

Can we set it somehow?

krutkowski86 avatar May 04 '20 17:05 krutkowski86

looks like it is set to true by default? I too would like this feature.

@OleksandrKucherenko android docs says something about setInvalidatedByBiometricEnrollment

// Invalidate the keys if the user has registered a new biometric // credential, such as a new fingerprint. Can call this method only // on Android 7.0 (API level 24) or higher. The variable // "invalidatedByBiometricEnrollment" is true by default.

https://developer.android.com/training/sign-in/biometric-auth#biometric-only

Can we set it somehow?

looks like it is set to true by default. I too would like this feature.

joelnewton avatar May 29 '20 14:05 joelnewton

@krutkowski86 @joelnewton

I set the following in CipherStorageBase.java > In the tryGenerateRegularSecurityKey() and tryGenerateStrongBoxSecurityKey() methods,

.setUserAuthenticationRequired(true) .setInvalidatedByBiometricEnrollment(true) .build();

Can you please let me know if it works for you? (assuming you are willing to fork and make changes?)

jambanagar avatar Jun 16 '20 07:06 jambanagar

any update son this topic? I use setInvalidatedByBiometricEnrollment(true) and I can still log in after adding / deleting a fingerprint.

warrioru avatar Jan 05 '21 15:01 warrioru

any update please it's urgent!

amircoh avatar Mar 17 '21 15:03 amircoh

Bump. Having the same issue

tieorange avatar May 07 '21 10:05 tieorange

any updates ?

husainkantawalaFS avatar Nov 29 '21 22:11 husainkantawalaFS

Same issue here

imdaniele avatar Feb 11 '22 10:02 imdaniele

Any news? i've tried to add storage: Keychain.STORAGE_TYPE.RSA but I can still log in after adding / deleting a fingerprint.

armibit avatar Jul 13 '22 00:07 armibit

same here .setInvalidatedByBiometricEnrollment(true) doesn't seem to work

MosCD3 avatar Jul 18 '22 05:07 MosCD3

The current implementation doesn't support the usage of such feature just adding the flag. As of now the authentication is "time-bound" (setUserAuthenticationValidityDurationSeconds is set to 5 seconds), it means the Cipher can be used "asynchronously" between user authentication and encryption/decryption operations. If you want to setInvalidatedByBiometricEnrollment properly you have to, as per documentation:

  • setUserAuthenticationRequired as true AND setUserAuthenticationValidityDurationSeconds as no positive value

It basically will produce a key that requires user authentication every time you need to perform an encryption/decryption operation, it means that every time the user authenticates (trough biometry for instance) you have to perform cryptography tasks using the Cipher in a "synch" way.

Using the Cipher in a "synch" way forces you to pass it into a CryptoObject when you authenticate the user.

protected BiometricPrompt authenticateWithPrompt(@NonNull final FragmentActivity activity) {
    final BiometricPrompt prompt = new BiometricPrompt(activity, executor, this);
    try {
      this.storage.getCachedInstance().init(Cipher.DECRYPT_MODE, context.key);
      prompt.authenticate(this.promptInfo, new BiometricPrompt.CryptoObject(this.storage.getCachedInstance()));
    }
    catch (final Throwable fail) {
      // any other exception treated as a failure
      this.onDecrypt(null, fail);
    }
    return prompt;
  }

Then the same CryptoObject will be returned as result by onAuthenticationSucceeded callback.

 @Override
  public void onAuthenticationSucceeded(@NonNull final BiometricPrompt.AuthenticationResult result) {
    result.getCryptoObject().getCipher()
    .......
  }

Now the Cipher allows you to perform decryption of data.

Here comes the further limitation of the current implementation: currently both username and password are encrypted/decrypted, but using the above scheme the Cipher is unlocked only for a single operation per user authentication. Probably if we want to switch to this mode we should accept either to do not encrypt username or to merge both username and password in a single token-separated string.

mpatafio avatar Jul 22 '22 14:07 mpatafio

Hi everyone, Since our project requires that whenever the Biometric setting changes (like add/remove a new fingerprint) the biometric config in the app should be removed. I see that the lib react-native-biometrics can do that. But I think it would be nice if I could stick to this amazing lib. Any suggestions guys? Thanks

anhquan291 avatar Oct 19 '22 07:10 anhquan291

Are there any updates on this?

hraschan avatar Feb 13 '23 12:02 hraschan

Hi everyone, Since our project requires that whenever the Biometric setting changes (like add/remove a new fingerprint) the biometric config in the app should be removed. I see that the lib react-native-biometrics can do that. But I think it would be nice if I could stick to this amazing lib. Any suggestions guys? Thanks

i am using react-native-biometrics but also not detect add a new fingerprint

Daohai122 avatar Feb 14 '23 08:02 Daohai122

react-native-biometrics does not do it currently, how can that be fixed ?

gabk17 avatar May 09 '23 12:05 gabk17

I was trying to get this working on Android with this plugin but could not. react-native-sensitive-info does this out of the box.

It works on Android and throws a Key permanently invalidated error when biometrics are altered in the device settings.

It returns undefined when you retrieve data if you pass kSecAccessControl: 'kSecAccessControlBiometryCurrentSet', when you save data.

satheeshwaran avatar Jul 13 '23 04:07 satheeshwaran