blob: 3f5952beb4985507aa7929a36d29b2a23447c984 [file] [log] [blame]
<html devsite><head>
<title>生物识别</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.yaml"/>
</head>
<body>
<!--
Copyright 2018 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
//www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>
Android 9 及更高版本包含一个 <a href="https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt" class="external">BiometricPrompt API</a>,应用开发者可以使用该 API 采用与设备和模态无关的方式将生物识别身份验证集成到其应用中。只有极为安全的生物识别技术才能与 <code>BiometricPrompt</code> 集成。如需了解详情,请参阅<a href="/security/biometric/measure#strong-weak-unlocks">衡量生物识别解锁模式的安全性</a>
</p>
<h2 id="source">源代码</h2>
<p>
Android 9 仅包含适用于 <a href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/biometrics" class="external">BiometricPrompt</a> 的指纹集成。但是,我们即将提供对其他生物识别模态的集成支持。
</p>
<p>
在 Android 9 及更高版本中,<a href="https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager" class="external">FingerprintManager</a> API 已被弃用。如果您的捆绑式应用和系统应用使用此 API,请更新这些应用以改用 <code>BiometricPrompt</code>
</p>
<h2 id="implementation">实现</h2>
<p>
为确保用户和开发者获享无缝的生物识别体验,请将生物识别堆栈与 <code>BiometricPrompt</code> 集成。为任何模态(包括面部、指纹和虹膜)启用 <code>BiometricPrompt</code> API 的设备必须符合这些<a href="/security/biometric/measure#strong-weak-unlocks">安全程度要求</a>。如果它们不符合这些安全程度要求,就无法实现此 API。
</p>
<p>
要将生物识别堆栈与 <code>BiometricPrompt</code> 集成,请执行以下操作:
</p>
<ol>
<li><code><a href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/biometrics/BiometricPrompt.java" class="external">/frameworks/base/core/java/android/hardware/biometrics/BiometricPrompt.java</a></code> 中添加一个 <code><var>Biometric</var>Manager</code> 类的实例</li>
<li>确保您的实例与 <code>BiometricPrompt</code> 提供的 <code><a href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/biometrics/BiometricPrompt.java#467" class="external">authenticate()</a></code> 方法挂钩。</li>
<li>更新框架以为添加的生物识别技术采用 <a href="https://developer.android.com/reference/android/app/admin/DevicePolicyManager#KEYGUARD_DISABLE_FACE" class="external"><code>KEYGUARD_DISABLE_*</code></a> 标记。</li>
</ol>
<figure>
<img src="/security/images/biometricprompt-architecture.png" alt="BiometricPrompt 架构"/>
<figcaption>
<strong>图 1</strong>. <code>BiometricPrompt</code> 架构。</figcaption>
</figure>
<h2 id="hal-implementation">HAL 实现指南</h2>
<p>
遵循以下生物识别 HAL 准则,以确保生物识别数据<strong>不会泄露</strong>,并会随用户从设备中移除时一并<strong>移除</strong>
</p>
<ol>
<li>确保在任何情况下都无法从传感器驱动程序或安全隔离环境(例如 TEE 或安全元件)以外访问原始生物识别数据或衍生内容(例如模板)。</li>
<li>如果硬件支持,则限制硬件对安全隔离环境的访问权限,并使用 SELinux 政策对其进行保护。使用针对所有设备文件的明确 SELinux 政策,确保信道(例如 SPI、I2C 等)只能供安全隔离环境访问。</li>
<li>为防止意外数据泄露,攻击免疫、指纹采集、注册和识别必须在安全隔离环境内部进行。</li>
<li>仅在文件系统上存储加密形式的生物识别数据或衍生内容(即使文件系统本身已加密)。</li>
<li>要防范重播攻击,请使用设备专用私钥对生物识别模板进行签名。对于高级加密标准 (AES),模板必须至少通过绝对文件系统路径、群组和生物识别 ID 进行签名,这样一来,相应模板文件便无法在其他设备上使用,并且无法用于在同一设备上注册的任何其他用户。例如,您将无法复制同一设备上其他用户的生物识别数据,也无法从其他设备复制生物识别数据。</li>
<li>使用 <code>set_active_group()</code> 函数提供的文件系统路径,或提供另一种能够在移除用户时一并清空所有用户模板数据的方法。强烈建议将生物识别模板文件以加密形式存储在提供的路径中。如果因安全隔离环境的存储要求导致这种做法不可行,请添加一些钩子,以确保在移除用户或清空设备数据时一并移除相关数据。</li>
</ol>
<h2 id="customization">自定义</h2>
<p>
如果您的设备支持多种生物识别技术,您可以指定默认值。但是,您必须允许用户在“设置”中更改其首选生物识别技术。
</p>
<h2 id="validation">验证</h2>
<p>
Android 9 更新了 <code>FingerprintManager</code> CTS 验证程序测试,以通过 <code><a href="https://android.googlesource.com/platform/cts/+/master/apps/CtsVerifier/src/com/android/cts/verifier/security/BiometricPromptBoundKeysTest.java">BiometricPromptBoundKeysTest</a></code> 测试 <code>BiometricPrompt</code>。对于其他生物识别技术,还没有正式的 CTS 或 CTS 验证程序测试。</p>
</body></html>