如何查看Androidphone是否支持TEE?

How to check whether Android phone supports TEE?

我已经阅读了这两个帖子:One and ,但我仍然有疑问。

我使用 KeyStore (Android 9) 生成 AES 密钥,并使用 isInsideSecureHardware() method to check whether the key isInsideSecureHardware. I got return False. Sample code can be found here, and here.

public boolean isInsideSecureHardware ()

Returns true if the key resides inside secure hardware (e.g., Trusted Execution Environment (TEE) or Secure Element (SE)). Key material of such keys is available in plaintext only inside the secure hardware and is not exposed outside of it.

因此,我想进一步确认我的phone设备(华为P20)是否支持TEE。

问题:

  1. 如果phone支持TEE,KeyStore生成的key会自动存入TEE?我需要在 Java 中进行任何手动配置吗?听说key会自动存入TEE,只要使用KeyStore.getInstance(),密钥生成器 .getInstance(算法,KeyStore 名称)。但我不确定这是真的还是假的?

  2. 如果Q1的答案是"Need manually configuration",则成为isInsideSecureHardware()的原因returns,对吧?如果Q1的答案是"automatically",忽略Q2.

  3. 有什么方法可以在Java中直接检查phone是否支持TEE?

来自 Android keystore system 文档:

Supported devices running Android 9 (API level 28) or higher installed can have a StrongBox Keymaster, an implementation of the Keymaster HAL that resides in a hardware security module. The module contains the following:
[...]
* Secure storage.
[...]
When checking keys stored in the StrongBox Keymaster, the system corroborates a key's integrity with the Trusted Execution Environment (TEE).
[...]
When generating or importing keys using the KeyStore class, you indicate a preference for storing the key in the StrongBox Keymaster by passing true to the setIsStrongBoxBacked() method.

根据我的理解,这意味着当您生成密钥并为密钥配置调用 keyGenParameterSpecBuilder.setIsStrongBoxBacked(true) 时,您可以确保它得到 TEE 的支持。如果没有 TEE 可用,它会抛出一个 StrongBoxUnavailableException.

因此,要检查是否有 TEE 可用,您可以尝试以这种方式生成密钥,看看它是否有效。

@JensV 是正确的:如果在 keyGenParameterSpecBuilder 上设置 setIsStrongBoxBacked,如果不支持 StrongBox,密钥生成将失败并显示 StrongBoxUnavailableException。然而,中间情况 - 有 TEE(即密钥在安全硬件中生成和使用),但不支持 StrongBox - 更难以辨别。

一般来说,要走的路是在设备上实际生成一个密钥,然后执行 HW key attestation on it at the server - 查阅已签名的密钥属性以检查硬件支持的确切程度:

  • 在服务器上生成一个随机数(随机字节串),传递给设备
  • 在设备上生成一个密钥,通过在 KeyGenParameterSpec 构建器上调用 setAttestationChallenge 并传入从服务器获得的随机数来请求硬件证明(不要使用在设备上生成的随机数)
  • 从 Android 密钥库
  • 请求密钥的证明链
  • 将证明数据(证书链)传递到您的服务器
  • 验证服务器上的证明(签名)链
  • 确认根证书匹配已发布的 Google 根证书
  • 确认链中没有任何证书被撤销(检查 CRL @ https://android.googleapis.com/attestation/status
  • 检查叶证书的 Google 密钥证明扩展 (OID 1.3.6.1.4.1.11129.2.1.17) 的属性
    • 确认随机数匹配(attestationChallenge
    • 参考KeyDescriptionattestationSecurityLevel
SecurityLevel ::= ENUMERATED {
    Software  (0),
    TrustedEnvironment  (1),
    StrongBox  (2),
}

TrustedEnvironmentStrongBox 都对应 hardware-backed 密钥和加密操作。