【问题标题】:Using TPM how do I use the SRK key to seal使用 TPM 如何使用 SRK 密钥进行密封
【发布时间】:2019-08-29 15:11:56
【问题描述】:

构建一个类来封装 TPM 功能。此类的目的是使用 SRK 密钥来密封和解封数组。我到了要密封的代码部分,我需要给它一个密钥,但我不知道如何告诉它使用 SRK 密钥: 那么我使用什么作为这个调用的第二个参数(hSRKey): 结果=Tspi_Data_Seal(hEncData,hSRKey,inv.size(),inv.data(),hPcrs);

std::vector<u8> CTpm::sealVector(std::vector<u8> inv)
{
    std::vector<u8> retVec;
    TSS_HOBJECT hPcrs;
    TSS_HOBJECT hEncData;
    TSS_HKEY hSRKey;
    //TSS_HOBJECT hPcrs;
    //memset(hPcrs,0,sizeof(TSS_HOBJECT));
    UINT32 ulPcrLen;
    BYTE rbgPcrValueX;
    BYTE* rbgPcrValue = &rbgPcrValueX;

    // create context
    result=Tspi_Context_CreateObject(hContext,TSS_OBJECT_TYPE_PCRS,0,&hPcrs);
    if (result)
        myLog->error("Unable to create context while getting FileKey. %s", Trspi_Error_String(result));

    // get current value for PCR 8
    result=Tspi_TPM_PcrRead(hTPM,8,&ulPcrLen,&rbgPcrValue);
    if (result)
        myLog->error("Unable to get Current value for PCR 8. %s", Trspi_Error_String(result));

    // set value of sealed PCR 8 to current value
    result=Tspi_PcrComposite_SetPcrValue(hPcrs,8,20,rbgPcrValue);
    if (result)
        myLog->error("Unable to set value for PCR 8. %s", Trspi_Error_String(result));

    // get current value for PCR 9
    result=Tspi_TPM_PcrRead(hTPM,9,&ulPcrLen,&rbgPcrValue);
    if (result)
        myLog->error("Unable to get Current value for PCR 9. %s", Trspi_Error_String(result));

    // set value of sealed PCR 9 to current value
    result=Tspi_PcrComposite_SetPcrValue(hPcrs,9,20,rbgPcrValue);
    if (result)
        myLog->error("Unable to set value for PCR 9. %s", Trspi_Error_String(result));

    // Create an data object for sealing
    result=Tspi_Context_CreateObject(hContext,TSS_OBJECT_TYPE_ENCDATA,TSS_ENCDATA_SEAL,&hEncData);
    if (result)
        myLog->error("Unable to create object for sealing. %s", Trspi_Error_String(result));

    // sealing the key
    result=Tspi_Data_Seal(hEncData,hSRKey,inv.size(),inv.data(),hPcrs);
    if (result)
        myLog->error("Unable to seal. %s", Trspi_Error_String(result));


    return retVec;
}

我得到“无效句柄”的结果错误代码

【问题讨论】:

  • SRK 具有持久句柄 0x40000000

标签: c++ tpm


【解决方案1】:

首先,您需要加载 srk 密钥,最简单的方法是使用

TSS_UUID SRK_UUID = TSS_UUID_SRK;
Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRKey);

进行此调用会将密钥加载到 tpm 并为您提供一个句柄,使用 TSS_UUID_SRK 作为用户 ID,而不是让 SRK 准备好使用,并为您提供它的句柄。完成此操作后,如果您打算将其用于数据密封,则需要对其设置授权,如果您使用众所周知的秘密,那么您将想做这样的事情

TSS_HPOLICY hOwnerPolicy;
BYTE wks[20] = TSS_WELL_KNOWN_SECRET;

Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hOwnerPolicy);
Tspi_Policy_SetSecret(hOwnerPolicy, TSS_SECRET_MODE_SHA1, 20, wks);

恐怕我对 TSPI 的了解真的只有这么多,但你可能还需要设置所有者策略,使用它来获取它。

Tspi_Context_GetTpmObject(hContext, &hTPM);
Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hOwnerPolicy);

然后对其调用 Tspi_Policy_SetSecret,并将密钥设置为 TPM 的所有者密码。 (我不确定这最后一步是否必要,我已经包含它,因为没有它我会遇到授权错误。)

我通过阅读可信计算实用指南中关于 TCG 的部分和对称密钥部分发现了大部分内容。这是迄今为止我在 Tspi 上找到的最有用的资源,即使它并不完美。

【讨论】:

    猜你喜欢
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 2019-02-12
    • 2010-10-10
    • 2020-04-16
    • 1970-01-01
    相关资源
    最近更新 更多