This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] PROCESSOR-SDK-AM62A:读取 U-boot 和/或 Linux 中的 HS-SE 加密密钥

Guru**** 2330830 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1515182/processor-sdk-am62a-reading-hs-se-encryption-keys-in-u-boot-and-or-linux

器件型号:PROCESSOR-SDK-AM62A

工具/软件:

您好、

我正在 U-Boot 中对 Linux 映像进行加密和解密。 我已经使用 OTP Keywriter 工具成功将 SoC 状态转换为 HS-SE。 现在我想使用编程到 HSM 中的密钥在启动过程中解密一些加密的 Linux 映像。  

是否有方法可以在 U-boot 中安全地从 HSM 中提取密钥?  

我引用了/board-support/u-boot-2021.01 +gitAUTOINC+2ee8efd654-g2ee8efd654/drivers/firmware/ti_sci.c、但我看不到方法这么做。

SDK 版本:TI-PROCESSOR-SDK-LINUX-am62axx-EVM-08.06.00.45

谢谢您、

Joseph

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好:

    Unknown 说:
    是否有办法在 U-boot 中从 HSM 中安全地提取密钥?  [/报价]

    这是不可能的。

    用户最好使用以下 TISCI 消息来对签名和加密的 blob 进行身份验证和解密。

    https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/security/PROC_BOOT.html#proc-boot-authenticate-image-and-configure-processor

    此致、

    Prashant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Prashant、

    感谢您的回复和分享此 TISCI 消息。 我在 TISCI_MSG_PROC_SET_CONFIG 上读取信息、但不了解它与解密的关系。 我在 ti_sci.h 中看到 A53配置标志、但同样这些并未提及解密。

    目前、我正在使用 MCU SDK 中的 appimage_x509_cert_gen.py 脚本为映像签名和加密。 在 U-Boot 中、我可以对映像进行身份验证甚至解密、但我会在 U-boot 中对 AES 密钥进行硬编码以进行测试。 由于我已确认身份验证和解密正常工作、因此我不想这样做。  

    我知道您说、无法提取密钥。 相反、是否有另一种方法可以解密以某种方式使用 HSM 中存储的密钥的映像?

    是否有任何示例说明了如何实现这一目标?

    此致、

    Joseph

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好:

    我提到的消息是 TISCI_MSG_PROC_AUTH_BOOT

    给定一个签名且加密的 blob 后、如果使用正确的密钥对 blob 进行签名和加密、则该消息将返回原始解密的 blob。 这些密钥将是电子保险丝中活动的编程密钥(SMPK/SMEK 或 BMPK/BMEK)。

    此致、

    Prashant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢您的澄清。 我略微熟悉这条消息、因为我必须在下面的函数中添加 debug。

    void ti_secure_image_post_process(void **p_image, size_t *p_size)
    {
    	struct ti_sci_handle *ti_sci = get_ti_sci_handle();
    	struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
    	size_t cert_length;
    	u64 image_addr;
    	u32 image_size;
    	int ret;
    
    	image_size = *p_size;
    
    	if (!image_size)
    		return;
    
    	if (get_device_type() == K3_DEVICE_TYPE_GP) {
    		if (ti_secure_cert_detected(*p_image)) {
    			printf("Warning: Detected image signing certificate on GP device. "
    			       "Skipping certificate to prevent boot failure. "
    			       "This will fail if the image was also encrypted\n");
    
    			cert_length = ti_secure_cert_length(*p_image);
    			if (cert_length > *p_size) {
    				printf("Invalid signing certificate size\n");
    				return;
    			}
    
    			*p_image += cert_length;
    			*p_size -= cert_length;
    		}
    
    		return;
    	}
    
    	if (get_device_type() != K3_DEVICE_TYPE_HS_SE &&
    	    !ti_secure_cert_detected(*p_image)) {
    		printf("Warning: Did not detect image signing certificate. "
    		       "Skipping authentication to prevent boot failure. "
    		       "This will fail on Security Enforcing(HS-SE) devices\n");
    		return;
    	}
    
    	/* Clean out image so it can be seen by system firmware */
    	image_addr = dma_map_single(*p_image, *p_size, DMA_BIDIRECTIONAL);
    
    	debug("Authenticating image at address 0x%016llx\n", image_addr);
    	debug("Authenticating image of size %d bytes\n", image_size);
    
    	/* Authenticate image */
    	ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
    	if (ret) {
    		printf("Authentication failed!\n");
    		hang();
    	}
    
    	/* Invalidate any stale lines over data written by system firmware */
    	if (image_size)
    		dma_unmap_single(image_addr, image_size, DMA_BIDIRECTIONAL);
    
    	/*
    	 * The image_size returned may be 0 when the authentication process has
    	 * moved the image. When this happens no further processing on the
    	 * image is needed or often even possible as it may have also been
    	 * placed behind a firewall when moved.
    	 */
    	*p_size = image_size;
    
    	/*
    	 * Output notification of successful authentication to re-assure the
    	 * user that the secure code is being processed as expected. However
    	 * suppress any such log output in case of building for SPL and booting
    	 * via YMODEM. This is done to avoid disturbing the YMODEM serial
    	 * protocol transactions.
    	 */
    	if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
    	      IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
    	      spl_boot_device() == BOOT_DEVICE_UART))
    		printf("Authentication passed\n");
    }

    我发现只有当我传入的 p_image 在顶部具有签名、然后是解密的数据时、我才能通过身份验证。 我传入的 p_size 是带有证书的解密映像的大小。  

    1.此外、出于某种原因、从 proc_auth_boot_image 返回的 image_size 始终为0。 有一条评论解释了为什么我们应该如何处理这个问题? 我们是否应该添加自己的代码来保存预期的图像尺寸?

    2.在 U-boot 之外,签名和加密映像的正确顺序是什么? 我们应该先签署映像、然后再加密、还是反之?

    我注意到在 U-boot 中,它首先尝试解密 blob ,然后使用 ti_secure_image_post_process ()进行身份验证。

    谢谢、

    Joseph

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好:

    1. 此外、出于某种原因、从 proc_auth_boot_image 返回的 image_size 始终为0。 有一条评论解释了为什么我们应该如何处理这个问题? 我们是否应该添加自己的代码来保存预期的图像大小?

    它不应该为0。 如果身份验证成功、image_size 字段将等于解密的 blob 大小。

    2. 在 U-Boot 之外、对映像签名和加密的正确顺序是什么? 我们应该先签署映像、然后再加密、还是反之?

    请参阅以下指南:

    https://software-dl.ti.com/tisci/esd/latest/6_topic_user_guides/secure_boot_signing.html#signing-an-encrypted-binary-for-secure-boot

    MCU+ SDK 中的以下脚本实现了这些步骤:

    https://github.com/TexasInstruments/mcupsdk-core-k3/blob/k3_next/tools/boot/signing/appimage_x509_cert_gen.py

    此致、

    Prashant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Prashant、

    再次感谢您的详细答复。 根据您的回复、 只要 Blob 以正确的顺序加密和签名、TISCI_MSG_PROC_AUTH_BOOT 会同时处理身份验证和解密。

    我想我可能知道我的问题在哪里。 我将尝试在 U-boot 中关闭 CONFIG_FIT_cipher、这样它就不会首先尝试手动解密我的映像。 如果不是为了安全启动、CONFIG_FIT_cipher 的用途是什么?

    此致、

    Joseph

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Prashant、

    我能够使用  TISCI_MSG_PROC_AUTH_BOOT 引导加密的 Linux 映像。 不确定此问题是否已在最新版本中修复、但 appimage_x509_cert_gen.py 脚本中存在一个错误、其中"initalVector"的拼写不正确、导致默认情况下调用脚本时出现问题。

    我还在脚本中使用了 authtype 2来使所有内容都正常工作。 这是预期的输入参数吗? 从下面来看、"身份验证后移至证书开始"意味着什么?

    help='Authentication type. [0/1/2]. 0 - Move to destination address specified after authentication, 1 - In place authentication, 2 - Move to the certificate start after authentication. Default is 1')

    谢谢、

    Joseph

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好:

    不确定此  问题是否已在最新版本中得到修复、但 appimage_x509_cert_gen.py 脚本中存在一个错误、其中"initalVector"的拼写不正确、导致在默认情况下调用脚本时出现问题。

    不确定您遇到了什么问题。 它只是一个标识符、因此不应导致任何问题。

    从下面开始、"在身份验证后移至证书开始"意味着什么?

    给定地址 X 处的已签名映像(X.509证书+ blob)、TIFS 会将 blob 移动到身份验证后证书开始的地址。 这意味着、成功身份验证后地址 X 将包含原始 blob。

    此致、

    Prashant