-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PCR policy authmodel #833
base: master
Are you sure you want to change the base?
PCR policy authmodel #833
Changes from all commits
56d1d5c
81bb0f0
edaa1d9
d98b691
fc5a411
21a21e7
6483606
0e22870
03e9dd3
bccb707
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ | |
#include <tss2/tss2_mu.h> | ||
#include <tss2/tss2_rc.h> | ||
#include <tss2/tss2_tctildr.h> | ||
#ifdef HAVE_POLICY | ||
#include <tss2/tss2_policy.h> | ||
#endif | ||
|
||
#include "attrs.h" | ||
#include "checks.h" | ||
|
@@ -4008,6 +4011,111 @@ CK_RV tpm2_getmechanisms(tpm_ctx *ctx, CK_MECHANISM_TYPE *mechanism_list, CK_ULO | |
return rv; | ||
} | ||
|
||
#ifdef HAVE_POLICY | ||
static TSS2_RC tpm2_policy_get_pcr(TSS2_POLICY_PCR_SELECTION *selection, | ||
TPML_PCR_SELECTION *out_selection, | ||
TPML_DIGEST *out_digest, | ||
void *userdata) | ||
{ | ||
|
||
TPML_PCR_SELECTION in_pcr_selection = {0}; | ||
if (selection->type == TSS2_POLICY_PCR_SELECTOR_PCR_SELECTION) { | ||
in_pcr_selection = selection->selections.pcr_selection; | ||
} else { | ||
in_pcr_selection.count = 1; | ||
|
||
TPMS_PCR_SELECTION *pcr_bank = &in_pcr_selection.pcrSelections[0]; | ||
TPMS_PCR_SELECT *pcr_select = &selection->selections.pcr_select; | ||
|
||
pcr_bank->hash = TPM2_ALG_SHA256; | ||
pcr_bank->sizeofSelect = pcr_select->sizeofSelect; | ||
memcpy(pcr_bank->pcrSelect, pcr_select->pcrSelect, pcr_bank->sizeofSelect); | ||
} | ||
|
||
ESYS_CONTEXT *esys_ctx = userdata; | ||
|
||
UINT32 pcr_update_counter; | ||
TPML_PCR_SELECTION *pcr_selection = NULL; | ||
TPML_DIGEST *pcr_values = NULL; | ||
|
||
TSS2_RC rc = Esys_PCR_Read(esys_ctx, | ||
ESYS_TR_NONE, | ||
ESYS_TR_NONE, | ||
ESYS_TR_NONE, | ||
&in_pcr_selection, | ||
&pcr_update_counter, | ||
&pcr_selection, | ||
&pcr_values); | ||
if (rc != TSS2_RC_SUCCESS) { | ||
LOGE("Esys_PCR_Read: %s:", Tss2_RC_Decode(rc)); | ||
free(pcr_selection); | ||
free(pcr_values); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be ESYS_Free calls. |
||
return rc; | ||
} | ||
|
||
*out_selection = *pcr_selection; | ||
*out_digest = *pcr_values; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I would have the failure Esys_PCR_Read goto an out label that Esys_Free's all the allocated pointers and here where you transfer ownership to |
||
|
||
free(pcr_selection); | ||
free(pcr_values); | ||
return TSS2_RC_SUCCESS; | ||
} | ||
|
||
CK_RV tpm2_execute_policy(tpm_ctx *ctx, TSS2_POLICY_CTX *policy_ctx, uint32_t handle) | ||
{ | ||
|
||
check_pointer(ctx); | ||
check_pointer(policy_ctx); | ||
check_num(handle); | ||
|
||
TPMT_SYM_DEF symmetric = { | ||
.algorithm = TPM2_ALG_AES, | ||
.keyBits = { .aes = 128 }, | ||
.mode = { .aes = TPM2_ALG_CFB } | ||
}; | ||
|
||
TSS2_POLICY_CALC_CALLBACKS calc_callbacks = {0}; | ||
calc_callbacks.cbpcr = &tpm2_policy_get_pcr; | ||
calc_callbacks.cbpcr_userdata = ctx->esys_ctx; | ||
|
||
TSS2_RC rc; | ||
|
||
rc = Tss2_PolicySetCalcCallbacks(policy_ctx, &calc_callbacks); | ||
if (rc != TSS2_RC_SUCCESS) { | ||
LOGE("Tss2_PolicySetCalcCallbacks: %s:", Tss2_RC_Decode(rc)); | ||
return CKR_GENERAL_ERROR; | ||
} | ||
|
||
/* XXX should we cache the session or running multiple policies is unlikely? */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This session handle needs to be used to authorize the object for
|
||
ESYS_TR policy_session = ESYS_TR_NONE; | ||
rc = Esys_StartAuthSession(ctx->esys_ctx, | ||
handle, | ||
handle, | ||
ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE, | ||
NULL, | ||
TPM2_SE_POLICY, &symmetric, TPM2_ALG_SHA256, | ||
&policy_session); | ||
if (rc != TSS2_RC_SUCCESS) { | ||
LOGE("Esys_StartAuthSession: %s", Tss2_RC_Decode(rc)); | ||
return CKR_GENERAL_ERROR; | ||
} | ||
|
||
TSS2_RC result = Tss2_PolicyExecute(policy_ctx, ctx->esys_ctx, policy_session); | ||
if (result != TSS2_RC_SUCCESS) { | ||
LOGE("Tss2_PolicyExecute: %s:", Tss2_RC_Decode(result)); | ||
/* continue and stop the session */ | ||
} | ||
|
||
rc = Esys_FlushContext(ctx->esys_ctx, policy_session); | ||
if (rc != TSS2_RC_SUCCESS) { | ||
LOGE("Esys_FlushContext: %s", Tss2_RC_Decode(rc)); | ||
return CKR_GENERAL_ERROR; | ||
} | ||
|
||
return result; | ||
} | ||
#endif | ||
|
||
void tpm_init(void) { | ||
/* pass nothing to do */ | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create 2 versions of this function and ifdef between the two and avoid even looking for the policy on non-policy enabled builds.