【问题标题】:Removal of Fingerprint not triggering InvalidKeyException for Fingerprnt Authentication移除指纹不会触发 InvalidKeyException 进行 Fingerprnt 身份验证
【发布时间】:2018-10-02 04:01:25
【问题描述】:

我正面临指纹认证的问题,实际上,我已经在我的应用程序中集成了指纹认证,并且除了一种情况外工作正常。

我在我的设备中设置了两个指纹,在使用指纹密钥初始化KeyGenerator 后,我从设备中删除了一个指纹并返回到我的应用程序并执行指纹验证,它工作正常。我不知道为什么它没有像添加指纹一样触发InvalidKeyException这是预期的行为还是操作系统的任何错误?

设备详情如下,

Device : Pixel

OS: Android 8.0

我的实现代码如下,

protected void generateKey() {
       try {
           keyStore = KeyStore.getInstance("AndroidKeyStore");
       } catch (Exception e) {
           e.printStackTrace();
       }


       KeyGenerator keyGenerator;
       try {
           keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
       } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
           throw new RuntimeException("Failed to get KeyGenerator instance", e);
       }


       try {
           keyStore.load(null);
           keyGenerator.init(new
                   KeyGenParameterSpec.Builder(KEY_NAME,
                   KeyProperties.PURPOSE_ENCRYPT |
                           KeyProperties.PURPOSE_DECRYPT)
                   .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                   .setUserAuthenticationRequired(true)
                   .setEncryptionPaddings(
                           KeyProperties.ENCRYPTION_PADDING_PKCS7)
                   .build());
           keyGenerator.generateKey();
       } catch (NoSuchAlgorithmException |
               InvalidAlgorithmParameterException
               | CertificateException | IOException e) {
           throw new RuntimeException(e);
       }
   }

 public boolean cipherInit() {
       try {
           cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
       } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
           throw new RuntimeException("Failed to get Cipher", e);
       }


       try {
           keyStore.load(null);
           SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME,
                   null);
           cipher.init(Cipher.ENCRYPT_MODE, key);
           return true;
       } catch (KeyPermanentlyInvalidatedException e) {
           return false;
       } catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
           throw new RuntimeException("Failed to init Cipher", e);
       }
   }
}

我已经尝试过一些帖子(How to detect the removal fingerprint in Android?Android Fingerprint API and Private/Public keysAndroid Key Invalidation when Fingerprints removed),但没有什么能帮助我摆脱它。

【问题讨论】:

    标签: android android-fingerprint-api


    【解决方案1】:

    您的代码并未严格与指纹绑定。与此有些相关的是:

    setUserAuthenticationRequired(true)
    

    这表示您在AndroidKeyStore 中创建的密钥需要用户身份验证。它没有提到指纹。

    如果用户注册了指纹,则用户可以使用指纹进行身份验证以使用此密钥。这将适用于用户注册的任何指纹,在您的情况下,您仍然有一个注册的指纹(即使在用户删除了第二个指纹之后)。此外,用户不必使用指纹进行身份验证——他们可以使用自己的密码、PIN 或图案,如果他们愿意的话。

    这是预期的行为还是操作系统的任何错误?

    这是预期的行为。

    【讨论】:

    • 非常感谢您提供的简短详细信息,有什么方法可以识别指纹删除吗?
    • @SathishKumar:我不这么认为。
    • 好的,谢谢。
    • “此外,用户不必使用指纹进行身份验证 - 他们可以使用他们的密码、PIN 或模式,如果他们愿意的话。” 除非@987654323 @ 用于允许在给定时间范围内每次身份验证多次使用密钥。否则文档说明“目前,这种授权的唯一方式是指纹认证”
    • 不正确,当 setUserAuthenticationRequired 设置为 true 时,Keystore 密钥失效,无法再使用密钥。请参阅文档。
    猜你喜欢
    • 1970-01-01
    • 2017-01-07
    • 2010-11-08
    • 2018-07-28
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多