使用TPM / TrouSerS API创建密钥时,“身份验证失败”

时间:2018-11-28 22:01:20

标签: tpm

我正在尝试通过TrouSerS API使用TPM对某些数据进行签名。我已经在网上搜寻了代码示例,而我遇到的唯一示例是在this PDF的幻灯片#30中(我认为TPM和Trousers的文档很神秘)。

当我调用以下函数来创建签名密钥时,代码将失败:

  

Tspi_Key_CreateKey()

我获得的错误代码为“ 1”,当通过Trspi_Error_String()函数运行时,该错误代码将转换为字符串“认证失败”。显然,创建签名密钥的调用失败,因为它没有正确的授权策略。

在下面的代码示例中,您可以看到我将默认策略机密设置为TSS_WELL_KNOWN_SECRET,如果我没记错的话,它是二十个0。我找不到有关策略如何运行以及如何确保我对TPM的呼叫已获得授权的良好文档。我需要帮助来了解两件事:

  • 策略在TrouSerS和TPM中如何工作?
  • 如何确定我对Tspi_Key_CreateKey()的呼叫已获得授权?
TSS_HCONTEXT hContext;
TSS_HKEY hSigningKey, hSRK;
TSS_HPOLICY hPolicy;
BYTE secret[] = TSS_WELL_KNOWN_SECRET;

// Init context and connect to tcsd daemon
Tspi_Context_Create(&hContext);
Tspi_Context_Connect(hContext, NULL);

// Create object for Software Root Key
Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_TSP_SRK, &hSRK);

// Create object for signing key
Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
                    TSS_KEY_TYPE_SIGNING |
                    TSS_KEY_SIZE_2048 |
                    TSS_KEY_AUTHORIZATION |
                    TSS_KEY_NOT_MIGRATABLE,
                    &hSigningKey);

// Set up the default policy, which applies to all objects
Tspi_Context_GetDefaultPolicy(hContext, &hPolicy);
Tspi_Policy_SetSecret(hPolicy, TSS_SECRET_MODE_SHA1, 20, secret);

// Load the SRK key
TSS_UUID SRK_UUID = TSS_UUID_SRK;
Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK);

// Create the signing key
Tspi_Key_CreateKey(hSigningKey, hSRK, 0);
if (result != TSS_SUCCESS) {
    LOG(ERROR) << "Failed to create signing key " << result;
    LOG(ERROR) << Trspi_Error_String(result);
    return;
}

1 个答案:

答案 0 :(得分:1)

我犯了一个错误,就是不阅读有关特定系统(Google Chromebook)的TPM文档。作为documentation says,Chromebook将SRK密码设置为NULL。调整我的代码以使用此机密使对Tspi_Key_CreateKey()的调用成功返回。从那里,我可以对一些数据进行签名并验证签名。您可以在下面找到调整后的代码:

TSS_HCONTEXT hContext;
TSS_HKEY hSigningKey, hSRK;
TSS_HPOLICY hPolicy;
BYTE secret[] = {}; // NOTE: Secret is now empty

// Init context and connect to tcsd daemon
Tspi_Context_Create(&hContext);
Tspi_Context_Connect(hContext, NULL);

// Create object for Software Root Key
Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY, TSS_KEY_TSP_SRK, &hSRK);

// Create object for signing key
Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
                    TSS_KEY_TYPE_SIGNING |
                    TSS_KEY_SIZE_2048 |
                    TSS_KEY_AUTHORIZATION |
                    TSS_KEY_NOT_MIGRATABLE,
                    &hSigningKey);

Tspi_Context_GetDefaultPolicy(hContext, &hPolicy);
Tspi_Policy_SetSecret(hPolicy, TSS_SECRET_MODE_PLAIN, 0, secret); // NOTE: Using TSS_SECRET_MODE_PLAIN now

// Load the SRK key
TSS_UUID SRK_UUID = TSS_UUID_SRK;
Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK);

// Create the signing key
Tspi_Key_CreateKey(hSigningKey, hSRK, 0);
相关问题