Skip to content

Commit

Permalink
FAPI: Clean command context before execution.
Browse files Browse the repository at this point in the history
The FAPI command context now is cleared in the async function of
every command.

Signed-off-by: Juergen Repp <[email protected]>
  • Loading branch information
JuergenReppSIT authored and AndreasFuchsTPM committed Jan 24, 2024
1 parent 764d111 commit 84ead1b
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_CreateKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ Fapi_CreateKey_Async(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

attributes = &context->cmd.Key_Create.public_templ.public.publicArea.objectAttributes;

/* Reset all context-internal session state information. */
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_Decrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ Fapi_Decrypt_Async(
check_not_null(keyPath);
check_not_null(cipherText);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_Data_EncryptDecrypt * command = &(context->cmd.Data_EncryptDecrypt);

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_Delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ Fapi_Delete_Async(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_Entity_Delete * command = &(context->cmd.Entity_Delete);
IFAPI_OBJECT *object = &command->object;
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_Encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ Fapi_Encrypt_Async(
check_not_null(keyPath);
check_not_null(plainText);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_Data_EncryptDecrypt * command = &(context->cmd.Data_EncryptDecrypt);

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_ExportKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ Fapi_ExportKey_Async(
check_not_null(context);
check_not_null(pathOfKeyToDuplicate);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_ExportKey * command = &context->cmd.ExportKey;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_ExportPolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ Fapi_ExportPolicy_Async(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_ExportPolicy * command = &context->cmd.ExportPolicy;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_GetCertificate.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ Fapi_GetCertificate_Finish(
check_not_null(context);
check_not_null(x509certData);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_Key_SetCertificate *command = &context->cmd.Key_SetCertificate;
IFAPI_OBJECT *keyObject = &command->key_object;
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_GetEsysBlob.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ Fapi_GetEsysBlob_Async(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_GetEsysBlob * command = &(context->cmd.GetEsysBlob);
IFAPI_OBJECT *object = &command->object;
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_GetInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ Fapi_GetInfo_Async(
/* Check for NULL parameters */
check_not_null(context);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_GetInfo * command = &context->cmd.GetInfo;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_GetRandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ Fapi_GetRandom_Async(
/* Check for NULL parameters */
check_not_null(context);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_GetRandom * command = &context->get_random;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_Import.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ Fapi_Import_Async(
check_not_null(path);
check_not_null(importData);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_ImportKey * command = &context->cmd.ImportKey;
IFAPI_OBJECT *object = &command->object;
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_NvExtend.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ Fapi_NvExtend_Async(
check_not_null(nvPath);
check_not_null(data);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Check for maximum allowed dataSize. */
if (dataSize > 1024) {
LOG_ERROR("dataSize exceeds allowed maximum of 1024. dataSize = %zi", dataSize);
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_NvRead.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ Fapi_NvRead_Async(
check_not_null(context);
check_not_null(nvPath);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_NV_Cmds * command = &context->nv_cmd;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_PcrExtend.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ Fapi_PcrExtend_Async(
check_not_null(context);
check_not_null(data);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_PCR * command = &context->cmd.pcr;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_PcrRead.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ Fapi_PcrRead_Async(
/* Check for NULL parameters */
check_not_null(context);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_PCR * command = &context->cmd.pcr;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_SetAppData.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ Fapi_SetAppData_Async(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

if (context->state != _FAPI_STATE_INIT) {
return_error(TSS2_FAPI_RC_BAD_SEQUENCE, "Invalid State");
}
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_SetCertificate.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ Fapi_SetCertificate_Async(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

if (context->state != _FAPI_STATE_INIT) {
return_error(TSS2_FAPI_RC_BAD_SEQUENCE, "Invalid State");
}
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_SetDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ Fapi_SetDescription_Async(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

if (context->state != _FAPI_STATE_INIT) {
return_error(TSS2_FAPI_RC_BAD_SEQUENCE, "Invalid State");
}
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_Sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ Fapi_Sign_Async(
check_not_null(keyPath);
check_not_null(digest);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Check for invalid parameters */
if (padding) {
if (strcasecmp("RSA_SSA", padding) != 0 &&
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_Unseal.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Fapi_Unseal(
check_not_null(context);
check_not_null(path);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Check whether TCTI and ESYS are initialized */
return_if_null(context->esys, "Command can't be executed in none TPM mode.",
TSS2_FAPI_RC_NO_TPM);
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_VerifyQuote.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ Fapi_VerifyQuote_Async(
check_not_null(quoteInfo);
check_not_null(signature);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

if (context->state != _FAPI_STATE_INIT) {
return_error(TSS2_FAPI_RC_BAD_SEQUENCE, "Invalid State");
}
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_VerifySignature.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ Fapi_VerifySignature_Async(
check_not_null(digest);
check_not_null(signature);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_Key_VerifySignature * command = &context->cmd.Key_VerifySignature;

Expand Down
3 changes: 3 additions & 0 deletions src/tss2-fapi/api/Fapi_WriteAuthorizeNV.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ Fapi_WriteAuthorizeNv_Async(
check_not_null(nvPath);
check_not_null(policyPath);

/* Cleanup command context. */
memset(&context->cmd, 0, sizeof(IFAPI_CMD_STATE));

/* Helpful alias pointers */
IFAPI_api_WriteAuthorizeNv * command = &context->cmd.WriteAuthorizeNV;
IFAPI_NV_Cmds * nvCmd = &context->nv_cmd;
Expand Down

0 comments on commit 84ead1b

Please sign in to comment.