自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
首次使用时信任 (TOFU)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
对于搭载 Android 13 或更高版本的设备,Android 支持首次使用时信任 (TOFU) 身份验证方法 (RFC7435),让用户能够信任企业 (EAP) 网络,方法是安装服务器使用的根 CA 并在已保存的网络中设置其域名。借助 TOFU,设备可以在用户首次连接到某个企业网络时获取未经身份验证的公钥,并保留该公钥以在后续连接时使用。
背景
与仅需要密码的个人网络相比,企业网络使用公钥基础架构 (PKI) 身份验证方法,该方法需要客户端预安装相关证书。在 Android 11 或更低版本中,用户可以在网络设置中为服务器 CA 证书选择“不验证”选项,以绕过服务器端证书验证。不过,为了增强安全性并遵守 WPA R2 规范,Android 12 针对企业网络引入了服务器证书验证要求。这项附加要求为用户设置了屏障,因为他们需要为此类网络安装 CA 证书。借助 TOFU,用户只需接受基于 PKI 的企业网络的根 CA,即可连接到相应网络。
功能行为
在用户连接到没有已安装且经过身份验证的公钥时,支持 TOFU 的设备会表现出以下行为。
通过 Wi-Fi 选择器连接到新网络
在 Wi-Fi 选择器中选择新的企业网络。
设备会显示一个对话框(图 1),用于确认网络是否可信。
点按是,连接即可接受网络连接,或点按否,不连接即可拒绝连接。
图 1. TOFU 功能的对话框
连接到已启用自动连接功能的现有网络
在连接到已启用自动连接功能但缺少有效 CA 证书的企业网络时,设备会自动连接,然后显示固定(不可关闭)通知。
点按通知。
设备会显示一个对话框(图 1),用于确认网络是否可信。
点按是,连接即可接受网络连接,或点按否,不连接即可拒绝连接。
实现
如需支持 TOFU 功能,请实现 Android 开源项目 (AOSP) 中提供的客户端 HAL,网址为 /hardware/interfaces/wifi/supplicant/aidl/android/hardware/wifi/supplicant
。
Android 13 中提供了可供应用使用的以下公共 API:
验证
如需验证 TOFU 在您的设备上的实现情况,请使用以下测试:
- CTS:
CtsWifiTestCases
- VTS:
VtsHalWifiSupplicantStaNetworkTargetTest
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-25。
[null,null,["最后更新时间 (UTC):2025-03-25。"],[],[],null,["# Trust on First Use (TOFU)\n\nFor devices running Android 13 or higher, Android\nsupports the Trust on First Use (TOFU) authentication approach\n([RFC7435](https://datatracker.ietf.org/doc/html/rfc7435.html)),\nwhich lets users trust an enterprise (EAP) network by installing the root CA\nused by the server and setting its domain name in a saved network. TOFU allows\nthe device to obtain an unauthenticated public key when a user first connects\nto an enterprise network and retain the key for subsequent connections.\n\nBackground\n----------\n\nCompared to personal networks that just require a password, enterprise networks\nuse public key infrastructure (PKI) authentication, which requires the client\nto preinstall certificates. In Android 11 or lower, users can select the\n*Do not validate* option for the server CA certificate in the network settings,\nbypassing the validation of the server side certificate. However, to strengthen\nsecurity and comply with the WPA R2 specification, Android 12 introduced a\nrequirement for enterprise networks to have server certificate validation. This\nadditional requirement created a barrier for users as they need to install a CA\ncertificate for such networks. TOFU provides a way for users to connect to a\nPKI-based enterprise network by simply accepting its root CA.\n\nFeature behavior\n----------------\n\nDevices that support TOFU display the following behavior when a user connects\nto an enterprise network that doesn't have an *already-installed*\nauthenticated public key.\n\n### Connect to new network through Wi-Fi picker\n\n1. Select a new enterprise network in Wi-Fi picker.\n\n The device displays a dialog (Figure 1) to confirm whether the\n network is trusted.\n2. Tap **Yes, connect** to accept the network connection, or tap **No, don't\n connect** to decline.\n\n - If you tap **Yes, connect**, the device automatically configures the\n security parameters, connects to the network, and enables autoconnect\n for the network.\n\n | **Note:** Misconfigured networks that use invalid or expired certificates might not allow any security validation by the device. In such cases, the device fails to connect to the network.\n - If you tap **No, don't connect**, the device disconnects from the\n network and disables autoconnect for the network.\n\n **Figure 1.** Dialog for the TOFU feature\n\n### Connect to existing network with autoconnect enabled\n\nWhen connecting to an enterprise network that has autoconnect enabled but\ndoesn't have a valid CA certificate, the device connects automatically, then\ndisplays a sticky (nondismissable) notification.\n\n1. Tap the notification.\n\n The device displays a dialog (Figure 1) to confirm whether the\n network is trusted.\n2. Tap **Yes, connect** to accept the network connection, or tap **No, don't\n connect** to decline.\n\n - If you tap **Yes, connect**, the device automatically configures the\n security parameters, connects to the network, and enables autoconnect\n for the network.\n\n | **Note:** Misconfigured networks that use invalid or expired certificates might not allow any security validation by the device. In such cases, the device fails to connect to the network.\n - If you tap **No, don't connect**, the device disconnects from the\n network and disables autoconnect for the network.\n\nImplementation\n--------------\n\nTo support the TOFU feature, implement the supplicant HALs provided in the\nAndroid Open Source Project (AOSP) at\n[`/hardware/interfaces/wifi/supplicant/aidl/android/hardware/wifi/supplicant`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/wifi/supplicant/aidl/android/hardware/wifi/supplicant).\n\nThe following public APIs are available in Android 13\nfor use by apps:\n\n- [`WifiManager#isTrustOnFirstUseSupported()`](https://developer.android.com/reference/android/net/wifi/WifiManager#isTrustOnFirstUseSupported()): Indicates whether the device supports TOFU.\n- [`WifiEnterpriseConfig#enableTrustOnFirstUse(boolean)`](https://developer.android.com/reference/android/net/wifi/WifiEnterpriseConfig#enableTrustOnFirstUse(boolean)): Enables TOFU.\n- [`WifiEnterpriseConfig#isTrustOnFirstUseEnabled()`](https://developer.android.com/reference/android/net/wifi/WifiEnterpriseConfig#isTrustOnFirstUseEnabled()): Indicates whether TOFU is enabled.\n\nValidation\n----------\n\nTo validate the implementation of TOFU on your device, use the following tests:\n\n- CTS: `CtsWifiTestCases`\n- VTS: `VtsHalWifiSupplicantStaNetworkTargetTest`"]]