【问题标题】:Create endorsement key using TSS with TrouSerS in C在 C 中使用 TSS 和 TrouSerS 创建背书密钥
【发布时间】:2019-10-12 21:59:57
【问题描述】:

我正在用 C 语言编写一个程序,以生成一个背书密钥和存储根密钥。如何设置生成背书密钥所需的密钥信息以及需要使用哪些标志?

我正在 VirtualBox 中处理两个预配置的虚拟机映像。其中一个是模拟 TPM,另一个是容纳 C 程序。这两者通过内部网络相互连接。我可以连接到 TPM 机器并在终端上运行 TrouSerS tpm_tools。我可以通过运行“createek”和 SRK 创建一个背书密钥。但是,我无法运行 trousers/src/include/tss/tspi.h 中包含的 Tspi_TPM_CreateEndorsementKey。

TCG Software Stack (TSS) Specification Version 1.10 Golden 2003 年 8 月 20 日提到,“在调用此方法之前,必须通过 Tspi_SetAttribData( ) 在密钥对象中设置创建背书密钥所需的密钥信息。”使用 Tspi_TPM_CreateEndorsementKey 时。我不明白如何设置此信息或使用什么信息。

这是我的方法。 “hKey”是应该保存创建背书密钥所需信息的密钥。

#include<stdio.h> 
#include<string.h> 
#include<stdlib.h> 
#include<sys/stat.h> 
#include<sys/types.h> 
#include<tss/platform.h> 
#include<tss/tss_defines.h> 
#include<tss/tss_typedef.h> 
#include<tss/tss_structs.h> 
#include<tss/tspi.h> 
#include<trousers/trousers.h> 
#include<tss/tss_error.h> 
// Macro for debug messages 
#define DBG(message , tResult) printf("(Line%d, %s) %s returned 0x%08x. %s.\n", __LINE__, __func__, message, tResult, (char*)Trspi_Error_String(tResult))

// MAIN entry point
int main (int argc, char **argv) 
{
    TSS_HCONTEXT hContext = 0;
    TSS_HTPM hTPM = 0;
    TSS_RESULT result;
    // Other unrelated attributes
        // Create context and get tpm handle 
    result = Tspi_Context_Create(&hContext);
    DBG("Create a context: ", result);
    // NULL  represents  the  local  TPM)
    result = Tspi_Context_Connect(hContext, NULL);
    DBG("Connect to TPM: ", result);
    result = Tspi_Context_GetTpmObject(hContext, &hTPM);
    DBG("Get TPM handle: ", result);

    // Create the endorsement key
    TSS_VALIDATION pValidationData;
    TSS_HKEY hKey = 0;
    result = Tspi_TPM_CreateEndorsementKey(hTPM, hKey, &pValidationData);
    DBG("Create endorsement key: ", result);
    // Get EK public key
    TSS_HKEY hEndorsementPubKey;
    result = Tspi_TPM_GetPubEndorsementKey(hTPM, FALSE, NULL, &hEndorsementPubKey);
    DBG("Get EK public key: ", result);
    // START OF APP

// some code

    // END OF APP 
        // Free memory 
    result = Tspi_Context_FreeMemory(hContext, NULL);
    DBG("Tspi Context Free Memory: " , result);
    result = Tspi_Context_Close(hContext);
    DBG("Tspi Context Close: ", result);

    return 0;
}

这是运行程序时的打印输出。

(Line48, main) Create a context:  returned 0x00000000. Success.
(Line51, main) Connect to TPM:  returned 0x00000000. Success.
(Line53, main) Get TPM handle:  returned 0x00000000. Success.
(Line59, main) Create endorsement key:  returned 0x00003126. Invalid handle.

----Stuff to do afterwards-----

(Line109, main) Tspi Context Free Memory:  returned 0x00000000. Success.
(Line111, main) Tspi Context Close:  returned 0x00000000. Success.

如果这些句柄之一无效,则使用返回码“无效句柄”; hTPM,hKey。我很确定它是 hKey。当我在终端上使用 createek 生成背书密钥时,我可以将 hTPM 用于其他指令,例如 Tspi_TPM_OwnerGetSRKPubKey。

【问题讨论】:

    标签: c++ c security tpm


    【解决方案1】:

    看起来您可以创建一个带有“TSS_KEY_SIZE_2048”标志的“TSS_OBJECT_TYPE_RSAKEY”类型的对象来生成密钥。无需按照文档中的建议使用 setAttribData 设置任何属性。要考虑的另一件事是将 CreateEndorsementKey 中的“TSS_VALIDATION”参数设置为空指针。这告诉 TSS 服务处理密钥的验证,因此您不必自己处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-30
      • 2018-02-08
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多