mirror of https://github.com/wolfSSL/wolfBoot.git
Fix simulator to not just while(1) on panic, which causes CI to spin/timeout (instead exit with error). Fix ROT logic and make sure read error code gets passed up stack.
parent
2349a68e76
commit
c04960c097
|
@ -53,14 +53,9 @@ jobs:
|
|||
run: |
|
||||
make -C tools/keytools && make -C tools/bin-assemble
|
||||
|
||||
# needed for tpm tools
|
||||
- name: Build keystore.c
|
||||
run: |
|
||||
make keys ${{inputs.make-args}}
|
||||
|
||||
- name: Build TPM tools
|
||||
run: |
|
||||
make tpmtools
|
||||
make tpmtools ${{inputs.make-args}}
|
||||
|
||||
- name: Write TPM ROT to TPM
|
||||
run: |
|
||||
|
|
|
@ -107,5 +107,6 @@ jobs:
|
|||
with:
|
||||
arch: host
|
||||
config-file: ./config/examples/sim-tpm-seal.config
|
||||
make-args: SIGN=RSA2048ENC HASH=SHA256 POLICY_FILE=policy.bin
|
||||
# use larger image header size for two 2048-bit signatures
|
||||
make-args: SIGN=RSA2048ENC HASH=SHA256 POLICY_FILE=policy.bin IMAGE_HEADER_SIZE=1024
|
||||
authstr: TestAuth
|
||||
|
|
2
Makefile
2
Makefile
|
@ -167,7 +167,7 @@ keytools:
|
|||
@$(MAKE) -C tools/keytools -s clean
|
||||
@$(MAKE) -C tools/keytools -j
|
||||
|
||||
tpmtools:
|
||||
tpmtools: keys
|
||||
@echo "Building TPM tools"
|
||||
@$(MAKE) -C tools/tpm -s clean
|
||||
@$(MAKE) -C tools/tpm -j
|
||||
|
|
|
@ -83,6 +83,12 @@ void wolfBoot_start(void);
|
|||
asm volatile("b .-6"); \
|
||||
asm volatile("b .-8");
|
||||
|
||||
#elif defined(ARCH_SIM)
|
||||
#include <stdlib.h>
|
||||
static inline void wolfBoot_panic(void)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
static inline void wolfBoot_panic(void)
|
||||
{
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 50bfac48a970a61afa1463ec6514bf9b404830cb
|
||||
Subproject commit acdbc446d27272735177f768c3b06f4ae776570d
|
17
src/tpm.c
17
src/tpm.c
|
@ -824,7 +824,6 @@ int wolfBoot_unseal_blob(struct wolfBoot_image* img, WOLFTPM2_KEYBLOB* seal_blob
|
|||
int rc, i;
|
||||
WOLFTPM2_SESSION policy_session;
|
||||
uint32_t key_type;
|
||||
int key_slot = -1;
|
||||
TPM_ALG_ID pcrAlg = WOLFBOOT_TPM_PCR_ALG;
|
||||
TPM_ALG_ID alg = TPM_ALG_NULL, sigAlg;
|
||||
TPMT_PUBLIC template;
|
||||
|
@ -868,6 +867,7 @@ int wolfBoot_unseal_blob(struct wolfBoot_image* img, WOLFTPM2_KEYBLOB* seal_blob
|
|||
memset(&authKey, 0, sizeof(authKey));
|
||||
memset(&template, 0, sizeof(template));
|
||||
memset(&policy_session, 0, sizeof(policy_session));
|
||||
memset(&checkTicket, 0, sizeof(checkTicket));
|
||||
|
||||
/* Setup a TPM session that can be used for parameter encryption */
|
||||
rc = wolfTPM2_StartSession(&wolftpm_dev, &policy_session, &wolftpm_srk,
|
||||
|
@ -1152,6 +1152,7 @@ int wolfBoot_check_rot(int key_slot, uint8_t* pubkey_hint)
|
|||
#ifdef WOLFBOOT_TPM_KEYSTORE_AUTH
|
||||
nv.handle.auth.size = (UINT16)strlen(WOLFBOOT_TPM_KEYSTORE_AUTH);
|
||||
memcpy(nv.handle.auth.buffer, WOLFBOOT_TPM_KEYSTORE_AUTH, nv.handle.auth.size);
|
||||
wolfTPM2_SetAuthHandle(&wolftpm_dev, 0, &nv.handle);
|
||||
#endif
|
||||
|
||||
/* Enable parameter encryption for session - to protect auth */
|
||||
|
@ -1163,12 +1164,16 @@ int wolfBoot_check_rot(int key_slot, uint8_t* pubkey_hint)
|
|||
nv.handle.hndl = WOLFBOOT_TPM_KEYSTORE_NV_BASE + key_slot;
|
||||
rc = wolfTPM2_NVReadAuth(&wolftpm_dev, &nv, nv.handle.hndl,
|
||||
digest, &digestSz, 0);
|
||||
if (rc == 0 && digestSz == WOLFBOOT_SHA_DIGEST_SIZE &&
|
||||
memcmp(digest, pubkey_hint, WOLFBOOT_SHA_DIGEST_SIZE) == 0) {
|
||||
wolfBoot_printf("TPM Root of Trust valid (id %d)\n", key_slot);
|
||||
if (rc == 0) {
|
||||
if (digestSz == WOLFBOOT_SHA_DIGEST_SIZE &&
|
||||
memcmp(digest, pubkey_hint, WOLFBOOT_SHA_DIGEST_SIZE) == 0) {
|
||||
wolfBoot_printf("TPM Root of Trust valid (id %d)\n", key_slot);
|
||||
}
|
||||
else {
|
||||
rc = -1; /* digest match failure */
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (rc >= 0) rc = -1; /* failure */
|
||||
if (rc != 0) {
|
||||
wolfBoot_printf("TPM Root of Trust failed! %d (%s)\n",
|
||||
rc, wolfTPM2_GetRCString(rc));
|
||||
wolfBoot_printf("Expected Hash %d\n", digestSz);
|
||||
|
|
|
@ -614,19 +614,22 @@ static uint8_t *load_key(uint8_t **key_buffer, uint32_t *key_buffer_sz,
|
|||
|
||||
if (*pubkey_sz <= KEYSTORE_PUBKEY_SIZE_RSA2048) {
|
||||
CMD.sign = SIGN_RSA2048;
|
||||
CMD.header_sz = 512;
|
||||
CMD.signature_sz = 256;
|
||||
}
|
||||
else if (*pubkey_sz <= KEYSTORE_PUBKEY_SIZE_RSA3072) {
|
||||
CMD.sign = SIGN_RSA3072;
|
||||
|
||||
if(CMD.hash_algo != HASH_SHA256) {
|
||||
if (CMD.policy_sign) {
|
||||
CMD.header_sz = 1024;
|
||||
}
|
||||
else {
|
||||
CMD.header_sz = 512;
|
||||
}
|
||||
CMD.signature_sz = 256;
|
||||
}
|
||||
else if (*pubkey_sz <= KEYSTORE_PUBKEY_SIZE_RSA3072) {
|
||||
CMD.sign = SIGN_RSA3072;
|
||||
if (CMD.hash_algo != HASH_SHA256 || CMD.policy_sign) {
|
||||
CMD.header_sz = 1024;
|
||||
}
|
||||
else {
|
||||
CMD.header_sz = 512;
|
||||
}
|
||||
|
||||
CMD.signature_sz = 384;
|
||||
}
|
||||
else if (*pubkey_sz <= KEYSTORE_PUBKEY_SIZE_RSA4096) {
|
||||
|
@ -673,22 +676,24 @@ static uint8_t *load_key(uint8_t **key_buffer, uint32_t *key_buffer_sz,
|
|||
}
|
||||
else if (keySzOut == 384) {
|
||||
CMD.sign = SIGN_RSA3072;
|
||||
|
||||
if(CMD.hash_algo != HASH_SHA256) {
|
||||
if (CMD.hash_algo != HASH_SHA256 || CMD.policy_sign) {
|
||||
CMD.header_sz = 1024;
|
||||
}
|
||||
else {
|
||||
CMD.header_sz = 512;
|
||||
}
|
||||
|
||||
CMD.signature_sz = 384;
|
||||
}
|
||||
else {
|
||||
CMD.sign = SIGN_RSA2048;
|
||||
CMD.header_sz = 512;
|
||||
if (CMD.policy_sign) {
|
||||
CMD.header_sz = 1024;
|
||||
}
|
||||
else {
|
||||
CMD.header_sz = 512;
|
||||
}
|
||||
CMD.signature_sz = 256;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -743,7 +748,7 @@ static uint8_t *load_key(uint8_t **key_buffer, uint32_t *key_buffer_sz,
|
|||
printf("image header size overridden by config value (%u bytes)\n", IMAGE_HEADER_SIZE);
|
||||
CMD.header_sz = IMAGE_HEADER_SIZE;
|
||||
} else {
|
||||
printf("image header size calculated at runtime (%u bytes)\n", IMAGE_HEADER_SIZE);
|
||||
printf("image header size calculated at runtime (%u bytes)\n", CMD.header_sz);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_SIGNTOOL
|
||||
|
|
|
@ -104,6 +104,9 @@ static int TPM2_Boot_SecureROT_Example(TPMI_RH_NV_AUTH authHandle, word32 nvBase
|
|||
|
||||
printf("Computing keystore hash for index %d\n", id);
|
||||
|
||||
printf("Public Key (%d)\n", bufSz);
|
||||
TPM2_PrintBin(buf, bufSz);
|
||||
|
||||
/* hash public key */
|
||||
digestSz = wc_HashGetDigestSize(hashType);
|
||||
rc = wc_Hash(hashType, buf, (word32)bufSz, digest, digestSz);
|
||||
|
|
Loading…
Reference in New Issue