我正在用C语言写一个程序,生成一个背书密钥和存储根密钥。如何设置生成背书密钥所需的密钥信息,需要使用哪些标志?
我正在VirtualBox中处理两个预配置的虚拟机映像。其中一个是模拟TPM,另一个是存放C程序。这两者通过内部网络相互连接。我可以连接到TPM机器并在终端上运行TrouSerS tpm_tools。我可以通过运行"createek“和SRK来创建背书密钥。然而,我在运行Tspi_TPM_CreateEndorsementKey时遇到了问题,该文件包含在tss/src/include/tss/tspi.h中。
TCG Software Stack (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。
发布于 2019-10-15 02:57:18
看起来你可以创建一个带有"TSS_KEY_SIZE_2048“标志的"TSS_OBJECT_TYPE_RSAKEY”类型的对象来生成密钥。不需要按照文档中的建议使用setAttribData设置任何属性。另一件需要考虑的事情是将CreateEndorsementKey中的"TSS_VALIDATION“参数设置为空指针。这将告诉TSS服务处理密钥的验证,这样您就不必自己处理它了。
https://stackoverflow.com/questions/58358921
复制相似问题