【问题标题】:BiometricPrompt Android: UnrecoverableKeyException on Samsung after software or security updatesBiometricPrompt Android:软件或安全更新后三星出现 UnrecoverableKeyException
【发布时间】:2020-09-06 13:37:39
【问题描述】:

第一次在这里发帖,祝我好运:)

我们使用 BiometricPrompt API 在我们的移动应用中开发了对生物特征身份验证的支持。我们决定使用 CryptoObjects,因为它可以让我们遵守法规。

实施后,我们在三星设备和某些华为设备上面临一个问题,即在一些设备软件更新之后以及我们获得的几乎每个安全补丁之后:

Caused by java.security.UnrecoverableKeyException: Failed to obtain information about key
       at android.security.keystore.AndroidKeyStoreProvider.getKeyCharacteristics(AndroidKeyStoreProvider.java:238)
       at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreKeyFromKeystore(AndroidKeyStoreProvider.java:360)
       at android.security.keystore.AndroidKeyStoreSpi.engineGetKey(AndroidKeyStoreSpi.java:116)
       at java.security.KeyStore.getKey(KeyStore.java:1062)
       at com.*****.mobile.data.crypto.CryptoRepositoryImpl.getSignature(CryptoRepositoryImpl.java:527)
       at com.*****.mobile.business.biometric.authentication.BiometricAuthenticationPromptInteractorImpl$getSignatureForAuthentication$1.subscribe(BiometricAuthenticationPromptInteractorImpl.java:52)

Caused by android.security.KeyStoreException: User authentication required
       at android.security.KeyStore.getKeyStoreException(KeyStore.java:1151)
       at android.security.keystore.AndroidKeyStoreProvider.getKeyCharacteristics(AndroidKeyStoreProvider.java:240)
       at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreKeyFromKeystore(AndroidKeyStoreProvider.java:360)
       at android.security.keystore.AndroidKeyStoreSpi.engineGetKey(AndroidKeyStoreSpi.java:116)
       at java.security.KeyStore.getKey(KeyStore.java:1062)

这迫使我们生成一个新的密钥对,导致糟糕的用户体验。

有没有人遇到过类似的问题?并且可以建议需要更改/考虑哪些内容以防止我们的密钥在三星安全补丁后失效/损坏?

我们正在使用以下代码生成密钥对 (由于我们发现便宜的三星设备不支持 EC,因此使用了后备,因此我们在此类设备上使用 RSA)

@RequiresApi(Build.VERSION_CODES.M)
override fun createSigningKey(keyBaseName: KeyBaseName, useFallbackAlgorithm: Boolean): Either<Throwable, JavaPublicKey> = try {
  deleteKey(keyBaseName)
  when {
    useFallbackAlgorithm -> KeyPairGenerator
        .getInstance(KEY_ALGORITHM_RSA, ANDROID_KEY_STORE_PROVIDER)
        .apply {
          initialize(KeyGenParameterSpec.Builder(keyBaseName, PURPOSE_SIGN or PURPOSE_VERIFY)
              .setAlgorithmParameterSpec(RSAKeyGenParameterSpec(KEY_SIZE, RSAKeyGenParameterSpec.F4))
              .setDigests(DIGEST_SHA256, DIGEST_SHA512)
              .setSignaturePaddings(SIGNATURE_PADDING_RSA_PKCS1)
              .setUserAuthenticationRequired(true)
              .build())
        }
    else -> KeyPairGenerator
        .getInstance(KEY_ALGORITHM_EC, ANDROID_KEY_STORE_PROVIDER)
        .apply {
          initialize(KeyGenParameterSpec.Builder(keyBaseName, PURPOSE_SIGN or PURPOSE_VERIFY)
              .setDigests(DIGEST_SHA256, DIGEST_SHA512)
              .setUserAuthenticationRequired(true)
              .build())
        }
  }.generateKeyPair()
      .public
      .right()
} catch (e: Exception) {
  firebaseRepository.logException(RuntimeException("createSigningKey", e))
  e.left()
}

谢谢!

【问题讨论】:

  • 那么...您的问题到底是什么? “为什么三星手机会出现这样的问题?”也许?
  • 您好!问题是是否有可能避免我们的密钥在设备软件更新或安全补丁后被损坏/失效:(因为没有 Android 规范将其描述为正常行为。
  • 也许三星的安卓规范可以?这似乎是一个非常特定于供应商的问题。因为三星和华为都(非常)以使用普通的香草安卓根本没有的东西而闻名。

标签: android samsung-mobile biometrics android-biometric-prompt


【解决方案1】:

您可以尝试实施以下 2 个解决方案,看看它是否适合您。

  1. 将allowBackup false 添加到AndroidManifest.xml 文件中
<application
    android:allowBackup="false"
...
>
  1. Android 密钥库不是线程安全的,请使用 synchronized 关键字包装所有 Android 密钥库操作。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多