Skip to content

Commit 1672637

Browse files
committed
Cleanups for quote/signed timestamp in H5 sample app.
1 parent 7411e24 commit 1672637

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

test-app/app_stm32h5.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ void extra_led_off(void)
151151
}
152152

153153
extern int ecdsa_sign_verify(int devId);
154+
static void print_signature(const TPMT_SIGNATURE* sig);
154155

155156
/* Command line commands */
156157
static int cmd_help(const char *args);
@@ -194,7 +195,7 @@ struct console_command COMMANDS[] =
194195
{cmd_success, "success", "confirm a successful update"},
195196
{cmd_login_pkcs11, "pkcs11", "enable and test crypto calls with PKCS11 in secure mode" },
196197
{cmd_random, "random", "generate a random number"},
197-
{cmd_timestamp, "timestamp", "print the current timestamp"},
198+
{cmd_timestamp, "timestamp", "print the current systick/timestamp"},
198199
{cmd_benchmark, "benchmark", "run the wolfCrypt benchmark"},
199200
{cmd_test, "test", "run the wolfCrypt test"},
200201
{cmd_update_xmodem, "update", "update the firmware via XMODEM"},
@@ -204,7 +205,7 @@ struct console_command COMMANDS[] =
204205
#ifdef WOLFTPM_MFG_IDENTITY
205206
{cmd_tpm_idevid, "idevid", "show Initial Device Identification (IDevID) certificate"},
206207
{cmd_tpm_iak, "iak", "show Initial Attestation Identification (IAK) certificate"},
207-
{cmd_tpm_signed_timestamp, "signed_timestamp", "TPM IAK signed timestamp attestation report"},
208+
{cmd_tpm_signed_timestamp, "signed_time", "TPM IAK signed timestamp attestation report"},
208209
{cmd_tpm_quote, "quote", "TPM IAK signed PCR(s) attestation report"},
209210
#endif
210211
#endif
@@ -894,6 +895,8 @@ static int cmd_tpm_signed_timestamp(const char *args)
894895
/* a TPM vendor-specific value indicating the version number of the firmware */
895896
printf("\tFirmware Version (vendor specific): 0x%lX\n",
896897
(unsigned long)timeAttest.attested.time.firmwareVersion);
898+
899+
print_signature(&getTime.signature);
897900
}
898901

899902
if (rc != 0) {
@@ -905,6 +908,29 @@ static int cmd_tpm_signed_timestamp(const char *args)
905908
return rc;
906909
}
907910

911+
static void print_signature(const TPMT_SIGNATURE* sig)
912+
{
913+
char algName[24];
914+
printf("\tTPM generated %s signature:\n",
915+
wolfBoot_tpm2_get_alg_name(sig->sigAlg, algName, sizeof(algName)));
916+
printf("\tHash algorithm: %s\n",
917+
wolfBoot_tpm2_get_alg_name(sig->signature.any.hashAlg, algName, sizeof(algName)));
918+
switch (sig->sigAlg) {
919+
case TPM_ALG_ECDSA:
920+
case TPM_ALG_ECDAA:
921+
printf("\tR size: %d\n", sig->signature.ecdsa.signatureR.size);
922+
print_hex(sig->signature.ecdsa.signatureR.buffer, sig->signature.ecdsa.signatureR.size, 0);
923+
printf("\tS size: %d\n", sig->signature.ecdsa.signatureS.size);
924+
print_hex(sig->signature.ecdsa.signatureS.buffer, sig->signature.ecdsa.signatureS.size, 0);
925+
break;
926+
case TPM_ALG_RSASSA:
927+
case TPM_ALG_RSAPSS:
928+
printf("\tSignature size: %d\n", sig->signature.rsassa.sig.size);
929+
print_hex(sig->signature.rsassa.sig.buffer, sig->signature.rsassa.sig.size, 0);
930+
break;
931+
};
932+
}
933+
908934
static int cmd_tpm_quote(const char *args)
909935
{
910936
int rc;
@@ -913,7 +939,6 @@ static int cmd_tpm_quote(const char *args)
913939
TPMS_ATTEST quoteAttest;
914940
uint8_t pcrArray[1];
915941
uint32_t pcrArraySz = 0;
916-
char algName[24];
917942

918943
#ifdef WOLFBOOT_MEASURED_PCR_A
919944
pcrArray[0] = WOLFBOOT_MEASURED_PCR_A;
@@ -931,33 +956,15 @@ static int cmd_tpm_quote(const char *args)
931956
rc = wolfBoot_tpm2_parse_attest(&quoteResult.quoted, &quoteAttest);
932957
}
933958
if (rc == 0) {
934-
TPMT_SIGNATURE* sig = &quoteResult.signature;
935959
printf("TPM with signature attests (type 0x%x):\n", quoteAttest.type);
936-
printf("\tTPM signed %lu count of PCRs\n",
960+
printf("\tTPM signed %lu PCRs\n",
937961
(unsigned long)quoteAttest.attested.quote.pcrSelect.count);
938962

939963
printf("\tPCR digest:\n");
940964
print_hex(quoteAttest.attested.quote.pcrDigest.buffer,
941965
quoteAttest.attested.quote.pcrDigest.size, 0);
942966

943-
printf("\tTPM generated %s signature:\n",
944-
wolfBoot_tpm2_get_alg_name(sig->sigAlg, algName, sizeof(algName)));
945-
printf("\tHash algorithm: %s\n",
946-
wolfBoot_tpm2_get_alg_name(sig->signature.any.hashAlg, algName, sizeof(algName)));
947-
switch (sig->sigAlg) {
948-
case TPM_ALG_ECDSA:
949-
case TPM_ALG_ECDAA:
950-
printf("\tR size: %d\n", sig->signature.ecdsa.signatureR.size);
951-
print_hex(sig->signature.ecdsa.signatureR.buffer, sig->signature.ecdsa.signatureR.size, 0);
952-
printf("\tS size: %d\n", sig->signature.ecdsa.signatureS.size);
953-
print_hex(sig->signature.ecdsa.signatureS.buffer, sig->signature.ecdsa.signatureS.size, 0);
954-
break;
955-
case TPM_ALG_RSASSA:
956-
case TPM_ALG_RSAPSS:
957-
printf("\tSignature size: %d\n", sig->signature.rsassa.sig.size);
958-
print_hex(sig->signature.rsassa.sig.buffer, sig->signature.rsassa.sig.size, 0);
959-
break;
960-
};
967+
print_signature(&quoteResult.signature);
961968
}
962969
else {
963970
char error[100];

0 commit comments

Comments
 (0)