winapi: cleanup debug and signed_timestamp example

pull/127/head
Elms 2020-10-12 15:42:56 -07:00
parent 3f79e7adfb
commit efa2464496
2 changed files with 33 additions and 27 deletions

View File

@ -44,6 +44,13 @@ int TPM2_Timestamp_Test(void* userCtx)
WOLFTPM2_DEV dev;
TPMS_ATTEST attestedData;
#ifdef WOLFTPM_WINAPI
int tryNVkey = 0;
#else
int tryNVkey = 1;
#endif
union {
/* For managing TPM session */
StartAuthSession_In authSes;
@ -113,31 +120,36 @@ int TPM2_Timestamp_Test(void* userCtx)
/* Create RSA Storage Key, also called SRK */
/* See if SRK already exists */
rc = wolfTPM2_ReadPublicKey(&dev, &storage, TPM2_DEMO_STORAGE_KEY_HANDLE);
if (tryNVkey) {
rc = wolfTPM2_ReadPublicKey(&dev, &storage, TPM2_DEMO_STORAGE_KEY_HANDLE);
#ifdef TEST_WRAP_DELETE_KEY
if (rc == 0) {
storage.handle.hndl = TPM2_DEMO_STORAGE_KEY_HANDLE;
rc = wolfTPM2_NVDeleteKey(&dev, TPM_RH_OWNER, &storage);
if (rc != 0) goto exit;
rc = TPM_RC_HANDLE; /* mark handle as missing */
}
if (rc == 0) {
storage.handle.hndl = TPM2_DEMO_STORAGE_KEY_HANDLE;
rc = wolfTPM2_NVDeleteKey(&dev, TPM_RH_OWNER, &storage);
if (rc != 0) goto exit;
rc = TPM_RC_HANDLE; /* mark handle as missing */
}
#endif
if (rc != 0) {
}
if (!tryNVkey || (tryNVkey && rc != 0)) {
/* Create primary storage key (RSA) */
rc = wolfTPM2_CreateSRK(&dev, &storage, TPM_ALG_RSA,
rc = wolfTPM2_CreateSRK(&dev, &storage, TPM_ALG_RSA,
(byte*)gStorageKeyAuth, sizeof(gStorageKeyAuth)-1);
if (rc != 0) goto exit;
/* Move storage key into persistent NV */
rc = wolfTPM2_NVStoreKey(&dev, TPM_RH_OWNER, &storage,
TPM2_DEMO_STORAGE_KEY_HANDLE);
if (rc != 0) {
wolfTPM2_UnloadHandle(&dev, &storage.handle);
goto exit;
if (tryNVkey) {
/* Move storage key into persistent NV */
rc = wolfTPM2_NVStoreKey(&dev, TPM_RH_OWNER, &storage,
TPM2_DEMO_STORAGE_KEY_HANDLE);
if (rc != 0) {
wolfTPM2_UnloadHandle(&dev, &storage.handle);
goto exit;
}
}
printf("Created new RSA Primary Storage Key at 0x%x\n",
TPM2_DEMO_STORAGE_KEY_HANDLE);
storage.handle.hndl);
}
else {
/* specify auth password for storage key */
@ -282,6 +294,10 @@ exit:
}
/* Close key handles */
if (!tryNVkey) {
wolfTPM2_UnloadHandle(&dev, &storage.handle);
}
wolfTPM2_UnloadHandle(&dev, &rsaKey.handle);
wolfTPM2_UnloadHandle(&dev, &endorse.handle);

View File

@ -72,14 +72,11 @@ int TPM2_WinApi_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet)
if (ctx->winCtx.tbs_context == NULL) {
rc = Tbsi_Context_Create((TBS_CONTEXT_PARAMS*)&tbs_params,
&ctx->winCtx.tbs_context);
printf("create rc: %d\n", rc);
}
}
/* send the command to the device. Error if the device send fails. */
if (rc == 0) {
uint32_t tmp = packet->size;
printf("tx:\n");
TPM2_PrintBin(packet->buf, packet->pos);
rc = Tbsip_Submit_Command(ctx->winCtx.tbs_context,
TBS_COMMAND_LOCALITY_ZERO,
TBS_COMMAND_PRIORITY_NORMAL,
@ -88,12 +85,6 @@ int TPM2_WinApi_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet)
packet->buf,
(UINT32*)&tmp);
packet->pos = tmp;
printf("submit rc: %d\n", rc);
}
if (rc == 0) {
printf("rx:\n");
TPM2_PrintBin(packet->buf, packet->pos);
}
return rc;
@ -105,7 +96,6 @@ int TPM2_WinApi_Cleanup(TPM2_CTX* ctx)
if (ctx->winCtx.tbs_context != NULL) {
rc = Tbsip_Context_Close(ctx->winCtx.tbs_context);
ctx->winCtx.tbs_context = NULL;
printf("close rc: %d\n", rc);
}
return rc;