简体   繁体   English

如何查看Android手机是否支持TEE?

[英]How to check whether Android phone supports TEE?

I have read this two posts: One and Two , but I still have question.我已经阅读了这两个帖子: ,但我仍然有疑问。

I use KeyStore (Android 9) to generate an AES key, and use isInsideSecureHardware() method to check whether the key isInsideSecureHardware .我使用 KeyStore (Android 9) 生成 AES 密钥,并使用isInsideSecureHardware()方法检查密钥是否为isInsideSecureHardware I got return False .我得到了回报False Sample code can be found here , and here .可以在此处此处找到示例代码。

public boolean isInsideSecureHardware ()公共 boolean isInsideSecureHardware ()

Returns true if the key resides inside secure hardware (eg, Trusted Execution Environment (TEE) or Secure Element (SE)).如果密钥位于安全硬件(例如,可信执行环境 (TEE) 或安全元件 (SE))内,则返回 true。 Key material of such keys is available in plaintext only inside the secure hardware and is not exposed outside of it.此类密钥的密钥材料仅在安全硬件内部以明文形式提供,并且不会暴露在其外部。

Thus, I want to further confirm whether my phone device (Huawei P20) supports TEE.因此,我想进一步确认我的手机设备(华为 P20)是否支持 TEE。

Question:问题:

  1. If the phone supports TEE, the key generated by KeyStore will be store into TEE automatically?如果手机支持 TEE,KeyStore 生成的密钥会自动存入 TEE 吗? Do I Need any manually configuration in Java?我需要在 Java 中进行任何手动配置吗? I heard that keys will be automatically stored in TEE, as long as you use KeyStore.getInstance() , KeyGenerator.getInstance(algorithm, KeyStore Name) .听说只要你使用KeyStore.getInstance() , KeyGenerator.getInstance(algorithm, KeyStore Name) ,密钥会自动存储在 TEE 中。 But I am not sure this is True or Not?但我不确定这是真的还是假的?

  2. If the answer of Q1 is "Need manually configuration", it becomes the reason of isInsideSecureHardware () returns False , right?如果 Q1 的答案是“需要手动配置”,那就是isInsideSecureHardware () 返回False的原因吧? If the answer of Q1 is "automatically", ignore Q2.如果 Q1 的答案是“自动”,则忽略 Q2。

  3. Any method to directly check whether the phone supports TEE, in Java?在Java中有什么方法可以直接查看手机是否支持TEE?

From the Android keystore system docs:来自Android 密钥库系统文档:

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.运行 Android 9(API 级别 28)或更高版本的受支持设备可以安装 StrongBox Keymaster,这是一种位于硬件安全模块中的 Keymaster HAL 实现。 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).检查存储在 StrongBox Keymaster 中的密钥时,系统会通过可信执行环境 (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.使用 KeyStore class 生成或导入密钥时,您可以通过将 true 传递给 setIsStrongBoxBacked() 方法来指示将密钥存储在 StrongBox Keymaster 中的偏好。

In my understanding that means when you generate a Key and call keyGenParameterSpecBuilder.setIsStrongBoxBacked(true) for the key configuration you can ensure that it's backed by a TEE .据我了解,这意味着当您生成 Key 并为密钥配置调用keyGenParameterSpecBuilder.setIsStrongBoxBacked(true)时,您可以确保它由TEE支持。 If there is no TEE available, it'll throw a StrongBoxUnavailableException .如果没有可用的TEE ,它将抛出StrongBoxUnavailableException

So to check if there's a TEE available you could just attempt to generate a key this way and see if it works.因此,要检查是否有可用的TEE ,您可以尝试以这种方式生成密钥并查看它是否有效。

@JensV is correct: if you set setIsStrongBoxBacked on the keyGenParameterSpecBuilder , key generation will fail with a StrongBoxUnavailableException if StrongBox is not supported. @JensV 是正确的:如果您在setIsStrongBoxBacked上设置keyGenParameterSpecBuilder ,如果 StrongBox 不受支持,则密钥生成将失败并出现StrongBoxUnavailableException However, the intermediate case - where there is a TEE (ie keys are generated and used within secure HW), but no support for StrongBox - is more tricky to discern.然而,中间情况——存在 TEE(即在安全硬件中生成和使用密钥),但不支持 StrongBox——更难以辨别。

In general, the way to go is to actually generate a key on the device, and then perform HW key attestation on it at the server - consulting the signed key properties to examine the exact degree of HW backing:一般来说,go 的方法是在设备上实际生成一个密钥,然后在服务器上对其进行硬件密钥证明- 查阅签名的密钥属性以检查硬件支持的确切程度:

  • generate a nonce (random byte string) ON The SERVER, pass it to the device在服务器上生成一个随机数(随机字节字符串),将其传递给设备
  • generate a key on the device, requesting HW attestation by calling setAttestationChallenge on the KeyGenParameterSpec builder and passing in the nonce you get from the server (DO NOT USE A NONCE PRODUCED ON THE DEVICE)在设备上生成密钥,通过调用setAttestationChallenge构建器上的KeyGenParameterSpec并传入您从服务器获得的随机数来请求硬件证明(不要使用在设备上生成的随机数)
  • request the attestation chain for the key from the Android Key Store从 Android 密钥库请求密钥的证明链
  • pass the attestation data (cert chain) to your server将证明数据(证书链)传递到您的服务器
  • verify the attestation (signature) chain on your server验证服务器上的证明(签名)链
  • confirm that the root cert matches a published Google root cert确认根证书与已发布的 Google 根证书匹配
  • confirm that no cert in the chain hasn been revoked (check against CRL @ https://android.googleapis.com/attestation/status )确认链中没有证书被撤销(检查 CRL @ https://android.googleapis.com/attestation/status
  • examine the properties of the Google Key Attestation extension (OID 1.3.6.1.4.1.11129.2.1.17) of the leaf cert检查叶子证书的 Google Key Attestation 扩展 (OID 1.3.6.1.4.1.11129.2.1.17) 的属性
    • confirm the nonce matches ( attestationChallenge )确认随机数匹配( attestationChallenge
    • consult the attestationSecurityLevel of KeyDescription查阅KeyDescriptionattestationSecurityLevel
SecurityLevel ::= ENUMERATED {
    Software  (0),
    TrustedEnvironment  (1),
    StrongBox  (2),
}

TrustedEnvironment and StrongBox both correspond to hardware-backed keys and crypto operations. TrustedEnvironmentStrongBox都对应于硬件支持的密钥和加密操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM