【问题标题】:Android fingerprint detect new finger addedAndroid指纹检测新增手指
【发布时间】:2017-06-13 08:05:18
【问题描述】:

如何检测用户在我的应用程序中验证手指后是否将新指纹添加到 Android 设置?

即iOS 有一个叫做 (evaluatePolicyDomainState) 的东西来检测指纹目录的变化 Android 中的替代方案是什么?

出于安全原因,在这种情况下需要提示密码

【问题讨论】:

  • 这在 Android 中是不可能的。
  • 谢谢希望他们尽快支持这样的事情

标签: android detect fingerprint biometrics


【解决方案1】:

来自setUserAuthenticationRequired 的文档:

一旦安全锁定屏幕被禁用(重新配置为无、滑动或其他不验证用户身份的模式)或安全锁定屏幕被强制重置(例如,由设备管理员),密钥将不可逆转地失效。此外,如果密钥要求在每次使用密钥时都进行用户身份验证,则一旦注册了新指纹或不再注册指纹,它也将不可逆转地失效,除非使用setInvalidatedByBiometricEnrollment(boolean)允许注册后的有效性。尝试使用此类密钥初始化加密操作将引发 KeyPermanentlyInvalidatedException。

因此,要检查自您创建指纹关联密钥后是否注册了任何新指纹,只需使用该密钥创建一个密码并尝试init 该密码。如果注册了任何新指纹,init 调用应触发KeyPermanentlyInvalidatedException

【讨论】:

  • 您是否有描述该步骤详细信息的文章链接
  • 我不知道有这样的文章。只需按照您通常的方式实施指纹身份验证(我相信您可以通过 google 找到相关教程),并确保处理文档中提到的所有可能引发的异常。您有兴趣检测是否已注册其他指纹的地址是KeyPermanentlyInvalidatedException
【解决方案2】:

我可以得到所有整数的手指id。

private void getFingerprintInfo(Context context) 
{
    try {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        Method method = FingerprintManager.class.getDeclaredMethod("getEnrolledFingerprints");
        Object obj = method.invoke(fingerprintManager);

        if (obj != null) {
            Class<?> clazz = Class.forName("android.hardware.fingerprint.Fingerprint");
            Method getFingerId = clazz.getDeclaredMethod("getFingerId");

            for (int i = 0; i < ((List) obj).size(); i++)
            {
                Object item = ((List) obj).get(i);
                if(item != null)
                {
                    System.out.println("fkie4. fingerId: " + getFingerId.invoke(item));
                }
            }
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
        e.printStackTrace();
    }
}

请参考:https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/fingerprint/Fingerprint.java

有一个公共方法getFingerId(),但我们无法调用它,因为它有“@UnsupportedAppUsage”。

所以你需要使用反射来调用方法。获取指纹ID列表后,您可以对其进行加密并存储在sharedPreference中。

Finger id是设置中存储的指纹的id

获取所有指纹后,可以判断用户是否添加/删除了指纹。

无需依赖 KeyPermanentlyInvalidatedException。它不会在 Android 8.0 中抛出

祝你好运!!!...

不要相信谷歌做得这么差

【讨论】:

  • 我已经对其进行了测试,到目前为止它似乎是一个不错的方法,但是使用它的人应该注意两件事:(1) 一些供应商生成的顺序 ID(查看here 了解更多信息),除此之外,(2) getEnrolledFingerprints 不幸被列入灰名单(请查看 here 了解信息),这意味着如果您的应用针对 API 29+,这将不起作用。
  • 我想补充一下 gbazilio 所说的 getFingerId() 在三星设备上没有返回有效的 fingerId,它返回的索引 (1, 2, 3, ...) 对检查是否添加了新指纹。
    我还测试了其他 4 个功能,但不是很有用,例如:getName()getGroupId()getDeviceId()describeContents()
    getName() 可能有用与索引连接,但这里的问题是当您删除保存的最后一个指纹并创建其他具有相同名称的指纹时
  • 似乎在提供的类中修改了变量。并且不能再使用了。 :(
【解决方案3】:
/**
 * Generate NIST P-256 EC Key pair for signing and verification
 *
 * @param keyName
 * @param invalidatedByBiometricEnrollment
 * @return
 * @throws Exception
 */
@TargetApi(Build.VERSION_CODES.P)
private KeyPair generateKeyPair(String keyName, boolean invalidatedByBiometricEnrollment) throws Exception {
  KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
  KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(keyName,
      KeyProperties.PURPOSE_SIGN)
      .setAlgorithmParameterSpec(new ECGenParameterSpec("secp256r1"))
      .setDigests(KeyProperties.DIGEST_SHA256,
          KeyProperties.DIGEST_SHA384,
          KeyProperties.DIGEST_SHA512)
      // Require the user to authenticate with a biometric to authorize every use of the key
      .setUserAuthenticationRequired(true)
      .setInvalidatedByBiometricEnrollment(invalidatedByBiometricEnrollment);
  keyPairGenerator.initialize(builder.build());
  return keyPairGenerator.generateKeyPair();
}

【讨论】:

    【解决方案4】:

    您无法从应用中添加新指纹。

    在您的应用程序中,您只能访问 Auth Fingerprint Method,该方法通过 keyStore 检查注册的指纹。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 2013-11-22
      • 1970-01-01
      相关资源
      最近更新 更多