我正在用C编写程序,以生成认可密钥和存储根密钥。如何设置生成认可密钥所需的密钥信息以及需要使用哪些标志?
我正在VirtualBox中处理两个预配置的虚拟机镜像。其中一个正在模拟TPM,另一个正在容纳C程序。这两个通过内部网络相互连接。我可以连接到TPM机器,并在终端上运行TrouSerS tpm_tools。我可以通过运行“createek”和SRK来创建背书密钥。但是,我在运行trousers / src / include / tss / tspi.h中包含的Tspi_TPM_CreateEndorsementKey时遇到麻烦。
TCG软件堆栈(TSS)规范版本1.10(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.
如果这些句柄之一无效,则使用返回代码“Invalid handle”。
hTPM,hKey。我很确定这是hKey。在终端上使用createek生成背书密钥时,我可以将hTPM用于其他指令,例如Tspi_TPM_OwnerGetSRKPubKey。
最佳答案
看起来您只需创建带有“TSS_KEY_SIZE_2048”标志的“TSS_OBJECT_TYPE_RSAKEY”类型的对象即可生成密钥。如文档中所建议的,无需使用setAttribData设置任何属性。要考虑的另一件事是将CreateEndorsementKey中的“TSS_VALIDATION”参数设置为空指针。这告诉TSS服务处理密钥验证,因此您不必自己处理密钥。
关于c++ - 使用TSS和C中的TrouSerS创建背书 key ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58358921/