Skip to content

Commit 33a532f

Browse files
authored
Merge pull request #419 from dgarske/parsepubsz
Fix `TPM2_ParsePublic` size argument
2 parents bd68255 + 4719389 commit 33a532f

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

examples/attestation/make_credential.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ static void usage(void)
4949
printf("Notes:\n");
5050
printf("\tName digest is loaded from \"ak.name\" file\n");
5151
printf("\tPublic key is loaded from a file containing TPM2B_PUBLIC\n");
52-
printf("\t\"tek.pub\" for EK pub");
53-
printf("\t\"tsrk.pub\" for SRK pub");
52+
printf("\t\"ek.pub\" for EK pub\n");
53+
printf("\t\"srk.pub\" for SRK pub\n");
5454
printf("\tOutput is stored in \"cred.blob\"\n");
5555
printf("Demo usage without parameters, uses SRK pub\n");
5656
}

examples/nvram/read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int TPM2_NVRAM_Read_Example(void* userCtx, int argc, char *argv[])
221221

222222
/* Necessary for storing the publicArea with the correct encoding */
223223
rc = TPM2_ParsePublic(&keyBlob.pub, pubAreaBuffer,
224-
(word32)sizeof(pubAreaBuffer), &pubAreaSize);
224+
readSize, &pubAreaSize);
225225
if (rc != TPM_RC_SUCCESS) {
226226
printf("Decoding of PublicArea failed. Unable to extract correctly.\n");
227227
goto exit;

examples/run_examples.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,9 @@ if [ $WOLFCRYPT_ENABLE -eq 1 ]; then
493493
fi
494494

495495
if [ $WOLFCRYPT_ENABLE -eq 1 ] && [ $NO_FILESYSTEM -eq 0 ]; then
496-
./examples/keygen/keygen keyblob.bin -rsa >> $TPMPWD/run.out 2>&1
497-
RESULT=$?
498-
[ $RESULT -ne 0 ] && echo -e "keygen rsa failed! $RESULT" && exit 1
499-
./examples/attestation/make_credential >> $TPMPWD/run.out 2>&1
500-
RESULT=$?
501-
[ $RESULT -ne 0 ] && echo -e "make_credential failed! $RESULT" && exit 1
502-
./examples/attestation/activate_credential >> $TPMPWD/run.out 2>&1
503-
RESULT=$?
504-
[ $RESULT -ne 0 ] && echo -e "activate_credential failed! $RESULT" && exit 1
496+
rm -f keyblob.bin
505497

506-
# Endorsement hierarchy
498+
# Endorsement hierarchy (assumes keyblob.bin for key)
507499
./examples/keygen/keygen keyblob.bin -rsa -eh >> $TPMPWD/run.out 2>&1
508500
RESULT=$?
509501
[ $RESULT -ne 0 ] && echo -e "keygen rsa endorsement failed! $RESULT" && exit 1
@@ -514,10 +506,21 @@ if [ $WOLFCRYPT_ENABLE -eq 1 ] && [ $NO_FILESYSTEM -eq 0 ]; then
514506
RESULT=$?
515507
[ $RESULT -ne 0 ] && echo -e "activate_credential endorsement failed! $RESULT" && exit 1
516508

509+
./examples/keygen/keygen keyblob.bin -rsa >> $TPMPWD/run.out 2>&1
510+
RESULT=$?
511+
[ $RESULT -ne 0 ] && echo -e "keygen rsa failed! $RESULT" && exit 1
512+
./examples/attestation/make_credential >> $TPMPWD/run.out 2>&1
513+
RESULT=$?
514+
[ $RESULT -ne 0 ] && echo -e "make_credential failed! $RESULT" && exit 1
515+
./examples/attestation/activate_credential >> $TPMPWD/run.out 2>&1
516+
RESULT=$?
517+
[ $RESULT -ne 0 ] && echo -e "activate_credential failed! $RESULT" && exit 1
518+
517519
rm -f cred.blob
518520
rm -f ek.pub
519521
rm -f srk.pub
520522
rm -f ak.name
523+
# Keeping keyblob.bin for tests later
521524
fi
522525

523526
# PCR Quote Tests

examples/tpm_test_keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ int readKeyBlob(const char* filename, WOLFTPM2_KEYBLOB* key)
216216

217217
/* Decode the byte stream into a publicArea structure ready for use */
218218
rc = TPM2_ParsePublic(&key->pub, pubAreaBuffer,
219-
(word32)sizeof(pubAreaBuffer), &pubAreaSize);
219+
sizeof(UINT16) + key->pub.size, &pubAreaSize);
220220
if (rc != TPM_RC_SUCCESS) {
221221
goto exit;
222222
}

src/tpm2.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6465,13 +6465,6 @@ int TPM2_ParsePublic(TPM2B_PUBLIC* pub, byte* buf, word32 size, int* sizeUsed)
64656465
if (buf == NULL || pub == NULL || sizeUsed == NULL)
64666466
return BAD_FUNC_ARG;
64676467

6468-
if (size < sizeof(TPM2B_PUBLIC)) {
6469-
#ifdef DEBUG_WOLFTPM
6470-
printf("Insufficient buffer size for TPM2B_PUBLIC operations\n");
6471-
#endif
6472-
return TPM_RC_FAILURE;
6473-
}
6474-
64756468
/* Prepare temporary buffer */
64766469
packet.buf = buf;
64776470
packet.pos = 0;

src/tpm2_wrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ int wolfTPM2_SetKeyBlobFromBuffer(WOLFTPM2_KEYBLOB* key, byte *buffer,
481481

482482
/* Decode the byte stream into a publicArea structure ready for use */
483483
rc = TPM2_ParsePublic(&key->pub, pubAreaBuffer,
484-
(word32)sizeof(pubAreaBuffer), &pubAreaSize);
484+
(word32)(sizeof(UINT16) + key->pub.size), &pubAreaSize);
485485
if (rc != TPM_RC_SUCCESS) {
486486
return rc;
487487
}

0 commit comments

Comments
 (0)