mirror of https://github.com/wolfSSL/wolfTPM.git
winapi: cleanup debug and signed_timestamp example
parent
3f79e7adfb
commit
efa2464496
|
@ -44,6 +44,13 @@ int TPM2_Timestamp_Test(void* userCtx)
|
||||||
WOLFTPM2_DEV dev;
|
WOLFTPM2_DEV dev;
|
||||||
TPMS_ATTEST attestedData;
|
TPMS_ATTEST attestedData;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFTPM_WINAPI
|
||||||
|
int tryNVkey = 0;
|
||||||
|
#else
|
||||||
|
int tryNVkey = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
union {
|
union {
|
||||||
/* For managing TPM session */
|
/* For managing TPM session */
|
||||||
StartAuthSession_In authSes;
|
StartAuthSession_In authSes;
|
||||||
|
@ -113,31 +120,36 @@ int TPM2_Timestamp_Test(void* userCtx)
|
||||||
|
|
||||||
/* Create RSA Storage Key, also called SRK */
|
/* Create RSA Storage Key, also called SRK */
|
||||||
/* See if SRK already exists */
|
/* 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
|
#ifdef TEST_WRAP_DELETE_KEY
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
storage.handle.hndl = TPM2_DEMO_STORAGE_KEY_HANDLE;
|
storage.handle.hndl = TPM2_DEMO_STORAGE_KEY_HANDLE;
|
||||||
rc = wolfTPM2_NVDeleteKey(&dev, TPM_RH_OWNER, &storage);
|
rc = wolfTPM2_NVDeleteKey(&dev, TPM_RH_OWNER, &storage);
|
||||||
if (rc != 0) goto exit;
|
if (rc != 0) goto exit;
|
||||||
rc = TPM_RC_HANDLE; /* mark handle as missing */
|
rc = TPM_RC_HANDLE; /* mark handle as missing */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (rc != 0) {
|
}
|
||||||
|
|
||||||
|
if (!tryNVkey || (tryNVkey && rc != 0)) {
|
||||||
/* Create primary storage key (RSA) */
|
/* 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);
|
(byte*)gStorageKeyAuth, sizeof(gStorageKeyAuth)-1);
|
||||||
if (rc != 0) goto exit;
|
if (rc != 0) goto exit;
|
||||||
|
|
||||||
/* Move storage key into persistent NV */
|
if (tryNVkey) {
|
||||||
rc = wolfTPM2_NVStoreKey(&dev, TPM_RH_OWNER, &storage,
|
/* Move storage key into persistent NV */
|
||||||
TPM2_DEMO_STORAGE_KEY_HANDLE);
|
rc = wolfTPM2_NVStoreKey(&dev, TPM_RH_OWNER, &storage,
|
||||||
if (rc != 0) {
|
TPM2_DEMO_STORAGE_KEY_HANDLE);
|
||||||
wolfTPM2_UnloadHandle(&dev, &storage.handle);
|
if (rc != 0) {
|
||||||
goto exit;
|
wolfTPM2_UnloadHandle(&dev, &storage.handle);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Created new RSA Primary Storage Key at 0x%x\n",
|
printf("Created new RSA Primary Storage Key at 0x%x\n",
|
||||||
TPM2_DEMO_STORAGE_KEY_HANDLE);
|
storage.handle.hndl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* specify auth password for storage key */
|
/* specify auth password for storage key */
|
||||||
|
@ -282,6 +294,10 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close key handles */
|
/* Close key handles */
|
||||||
|
if (!tryNVkey) {
|
||||||
|
wolfTPM2_UnloadHandle(&dev, &storage.handle);
|
||||||
|
}
|
||||||
|
|
||||||
wolfTPM2_UnloadHandle(&dev, &rsaKey.handle);
|
wolfTPM2_UnloadHandle(&dev, &rsaKey.handle);
|
||||||
wolfTPM2_UnloadHandle(&dev, &endorse.handle);
|
wolfTPM2_UnloadHandle(&dev, &endorse.handle);
|
||||||
|
|
||||||
|
|
|
@ -72,14 +72,11 @@ int TPM2_WinApi_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet)
|
||||||
if (ctx->winCtx.tbs_context == NULL) {
|
if (ctx->winCtx.tbs_context == NULL) {
|
||||||
rc = Tbsi_Context_Create((TBS_CONTEXT_PARAMS*)&tbs_params,
|
rc = Tbsi_Context_Create((TBS_CONTEXT_PARAMS*)&tbs_params,
|
||||||
&ctx->winCtx.tbs_context);
|
&ctx->winCtx.tbs_context);
|
||||||
printf("create rc: %d\n", rc);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* send the command to the device. Error if the device send fails. */
|
/* send the command to the device. Error if the device send fails. */
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
uint32_t tmp = packet->size;
|
uint32_t tmp = packet->size;
|
||||||
printf("tx:\n");
|
|
||||||
TPM2_PrintBin(packet->buf, packet->pos);
|
|
||||||
rc = Tbsip_Submit_Command(ctx->winCtx.tbs_context,
|
rc = Tbsip_Submit_Command(ctx->winCtx.tbs_context,
|
||||||
TBS_COMMAND_LOCALITY_ZERO,
|
TBS_COMMAND_LOCALITY_ZERO,
|
||||||
TBS_COMMAND_PRIORITY_NORMAL,
|
TBS_COMMAND_PRIORITY_NORMAL,
|
||||||
|
@ -88,12 +85,6 @@ int TPM2_WinApi_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet)
|
||||||
packet->buf,
|
packet->buf,
|
||||||
(UINT32*)&tmp);
|
(UINT32*)&tmp);
|
||||||
packet->pos = tmp;
|
packet->pos = tmp;
|
||||||
printf("submit rc: %d\n", rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc == 0) {
|
|
||||||
printf("rx:\n");
|
|
||||||
TPM2_PrintBin(packet->buf, packet->pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -105,7 +96,6 @@ int TPM2_WinApi_Cleanup(TPM2_CTX* ctx)
|
||||||
if (ctx->winCtx.tbs_context != NULL) {
|
if (ctx->winCtx.tbs_context != NULL) {
|
||||||
rc = Tbsip_Context_Close(ctx->winCtx.tbs_context);
|
rc = Tbsip_Context_Close(ctx->winCtx.tbs_context);
|
||||||
ctx->winCtx.tbs_context = NULL;
|
ctx->winCtx.tbs_context = NULL;
|
||||||
printf("close rc: %d\n", rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue