-
Notifications
You must be signed in to change notification settings - Fork 55
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
Improvements in auth handling to support Policy Password and Policy Auth Value #350
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
81c8371
Refactor to eliminate confusing cast between TPMS_AUTH_COMMAND and TP…
dgarske fe05d93
Support for policy auth value and policy password.
dgarske f65bea0
Support for NV policy write/read.
dgarske ab45d27
Cleanup new API's. Add documentation.
dgarske 2f4fb5e
Fix warnings for set, but not used.
dgarske 9a9ac2a
Fix docs.
dgarske File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,36 +233,34 @@ void TPM2_Packet_MarkU32(TPM2_Packet* packet, int* markSz) | |
TPM2_Packet_AppendU32(packet, 0); | ||
} | ||
} | ||
void TPM2_Packet_PlaceU32(TPM2_Packet* packet, int markSz) | ||
int TPM2_Packet_PlaceU32(TPM2_Packet* packet, int markSz) | ||
{ | ||
int actSz = 0; | ||
/* update with actual size */ | ||
if (packet) { | ||
UINT32 data; | ||
byte* sizePtr = &packet->buf[markSz]; | ||
markSz += sizeof(UINT32); /* skip marker */ | ||
if (markSz <= packet->pos) { | ||
markSz = packet->pos - markSz; | ||
actSz = packet->pos - markSz; | ||
|
||
data = cpu_to_be32(markSz); | ||
data = cpu_to_be32(actSz); | ||
XMEMCPY(sizePtr, &data, sizeof(UINT32)); | ||
} | ||
} | ||
return actSz; | ||
} | ||
|
||
void TPM2_Packet_AppendAuthCmd(TPM2_Packet* packet, TPMS_AUTH_COMMAND* authCmd) | ||
{ | ||
if (packet == NULL || authCmd == NULL) | ||
if (packet == NULL || authCmd == NULL) { | ||
return; | ||
} | ||
|
||
#ifdef WOLFTPM_DEBUG_VERBOSE | ||
TPM2_PrintAuth(authCmd); | ||
#endif | ||
|
||
/* make sure continueSession is set for TPM_RS_PW */ | ||
if (authCmd->sessionHandle == TPM_RS_PW && | ||
(authCmd->sessionAttributes & TPMA_SESSION_continueSession) == 0) { | ||
authCmd->sessionAttributes |= TPMA_SESSION_continueSession; | ||
} | ||
TPM2_Packet_AppendU32(packet, authCmd->sessionHandle); | ||
TPM2_Packet_AppendU16(packet, authCmd->nonce.size); | ||
TPM2_Packet_AppendBytes(packet, authCmd->nonce.buffer, authCmd->nonce.size); | ||
|
@@ -347,15 +345,53 @@ TPM_ST TPM2_Packet_AppendAuth(TPM2_Packet* packet, TPM2_CTX* ctx, CmdInfo_t* inf | |
|
||
info->authCnt = TPM2_GetCmdAuthCount(ctx, info); | ||
if (info->authCnt > 0) { | ||
int i, tmpSz = 0; | ||
TPM2_Packet_MarkU32(packet, &tmpSz); | ||
int i, authTotalSzPos = 0; | ||
TPM2_Packet_MarkU32(packet, &authTotalSzPos); | ||
for (i=0; i<info->authCnt; i++) { | ||
/* Note: Casting a TPM2_AUTH_SESSION to TPMS_AUTH_COMMAND here, | ||
* this is allowed because top of structure matches */ | ||
TPM2_Packet_AppendAuthCmd(packet, (TPMS_AUTH_COMMAND*)&ctx->session[i]); | ||
TPM2_AUTH_SESSION* session = &ctx->session[i]; | ||
|
||
/* Determine auth size - appended later in TPM2_CommandProcess */ | ||
|
||
/* sessionHandle */ | ||
packet->pos += sizeof(UINT32); | ||
|
||
/* Nonce size: | ||
* Determined by us and TPM matches it on reply | ||
* Typically use SHA2-256 digest size (16 bytes). The random nonce | ||
* is populated in TPM2_CommandProcess */ | ||
packet->pos += sizeof(UINT16); /* nonceSz */ | ||
if (session->sessionHandle != TPM_RS_PW) { | ||
session->nonceCaller.size = | ||
TPM2_GetHashDigestSize(WOLFTPM2_WRAP_DIGEST); | ||
packet->pos += session->nonceCaller.size; | ||
} | ||
|
||
/* sessionAttributes */ | ||
packet->pos += sizeof(UINT8); | ||
if (session->sessionHandle == TPM_RS_PW) { | ||
/* make sure continueSession is set for TPM_RS_PW */ | ||
session->sessionAttributes |= TPMA_SESSION_continueSession; | ||
} | ||
|
||
/* Password Auth */ | ||
packet->pos += sizeof(UINT16); /* hmac.size */ | ||
if (session->sessionHandle == TPM_RS_PW) { | ||
packet->pos += session->auth.size; | ||
} | ||
/* HMAC or Policy Session */ | ||
else if (TPM2_IS_HMAC_SESSION(session->sessionHandle) || | ||
TPM2_IS_POLICY_SESSION(session->sessionHandle)) { | ||
if (!session->policyAuth && session->auth.size > 0) { | ||
packet->pos += session->auth.size; | ||
} | ||
else { | ||
/* auth is always HMAC result */ | ||
packet->pos += TPM2_GetHashDigestSize(session->authHash); | ||
} | ||
} | ||
} | ||
/* based on position difference places calculated size at marked U32 above */ | ||
TPM2_Packet_PlaceU32(packet, tmpSz); | ||
i = TPM2_Packet_PlaceU32(packet, authTotalSzPos); | ||
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. Assigning |
||
st = TPM_ST_SESSIONS; | ||
} | ||
return st; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(void) i;
here to prevent unused warnings whenDEBUG_WOLFTPM
is not definedThere 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.
Fixed: