0

我正在使用 Trousers 与项目的 TPM 交互。我遇到了存储 SRK(存储根密钥)的问题。

我的理解是,SRK 密钥对是在获得 TPM 所有权时生成的,并且存储在 TPM 中。但看起来它的一部分存储在系统持久存储中(由 system_ps_file 配置定义)。如果系统持久存储被删除,则无法再加载 SRK。

创建 SRK 的代码

TSS_FLAG srk_flags =  TSS_KEY_TSP_SRK|TSS_KEY_AUTHORIZATION;
int result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY, srk_flags, srk_handle);

加载 SRK 的代码

TSS_UUID srk_uuid = TSS_UUID_SRK;
int result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, srk_uuid, srk_handle);

上面的代码正常工作,直到系统持久存储数据文件存在。但是一旦它被删除,我得到:

ERROR: Tspi Context LoadKeyByUUID (SRK ) failed rc =0 x2020

有没有办法恢复已删除的存储文件?还是避免将其用于 SRK ?

4

1 回答 1

1

您对正在发生的事情的评估非常正确。将密钥存储在持久存储中的要求直接来自 TSS 规范:

所有应由 TSS 的 Key Management Services 内部管理的密钥必须在 TCS(系统持久存储)或 TSP(用户持久存储)的持久存储数据库中注册。在这些数据库之一中注册的每个密钥都将由其 UUID 引用,并从本规范的角度称为持久密钥。

话虽如此,代替 SRK 存储的是一个归零的“假 SRK”,所以理论上你可以运行相同的代码来替换它:

BYTE *save;
/* Once the key file is created, it stays forever. There could be
 * migratable keys in the hierarchy that are still useful to someone.
 */
result = ps_remove_key(&SRK_UUID);
if (result != TSS_SUCCESS && result != TCSERR(TSS_E_PS_KEY_NOTFOUND)) {
    destroy_key_refs(&srkKeyContainer);
    LogError("Error removing SRK from key file.");
    *srkKeySize = 0;
    free(*srkKey);
    goto done;
}
/* Set the SRK pubkey to all 0's before writing the SRK to disk, this is for
 * privacy reasons as outlined in the TSS spec */
save = srkKeyContainer.pubKey.key;
srkKeyContainer.pubKey.key = fake_pubkey;
offset = 0;
LoadBlob_TSS_KEY(&offset, fake_srk, &srkKeyContainer);
if ((result = ps_write_key(&SRK_UUID, &NULL_UUID, NULL, 0, fake_srk,
               offset))) {
    destroy_key_refs(&srkKeyContainer);
    LogError("Error writing SRK to disk");
    *srkKeySize = 0;
    free(*srkKey);
    goto done;
}
srkKeyContainer.pubKey.key = save;

但是你应该做的是备份你的持久存储。如果您丢失它,您将丢失您创建的所有其他密钥(不是 SRK)。

于 2018-07-20T20:34:27.443 回答