Skip to content

Commit 4408eea

Browse files
committed
Fixes for sealing/unsealing:
* Fix for sealing policy, which was not being set on creation. * Fix to clear the userWithAuth bit requiring policy * Updated wolfTPM submodule with changes in wolfSSL/wolfTPM#327
1 parent c6ac284 commit 4408eea

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

docs/TPM.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In wolfBoot we support TPM based root of trust, sealing/unsealing, cryptographic
1515
| `MEASURED_PCR_A=16` | `WOLFBOOT_MEASURED_PCR_A=16` | The PCR index to use. See [docs/measured_boot.md](/docs/measured_boot.md). |
1616
| `WOLFBOOT_TPM_SEAL=1` | `WOLFBOOT_TPM_SEAL` | Enables support for sealing/unsealing based on PCR policy signed externally. |
1717
| `WOLFBOOT_TPM_SEAL_NV_BASE=0x01400300` | `WOLFBOOT_TPM_SEAL_NV_BASE` | To override the default sealed blob storage location in the platform hierarchy. |
18-
| `WOLFBOOT_TPM_SEAL_AUTH=secret` | `WOLFBOOT_TPM_SEAL_AUTH` | Password for sealing/unsealing secrets |
18+
| `WOLFBOOT_TPM_SEAL_AUTH=secret` | `WOLFBOOT_TPM_SEAL_AUTH` | Password for sealing/unsealing secrets, if omitted the PCR policy will be used |
1919

2020
## Root of Trust (ROT)
2121

src/tpm.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ int wolfBoot_seal_blob(const uint8_t* pubkey_hint,
788788
/* build authorization policy based on public key */
789789
/* digest here is input and output, must be zero'd */
790790
uint32_t digestSz = TPM2_GetHashDigestSize(pcrAlg);
791+
/* Create a new key for sealing using external signing auth */
792+
wolfTPM2_GetKeyTemplate_KeySeal(&template, pcrAlg);
791793
memset(template.authPolicy.buffer, 0, digestSz);
792794
rc = wolfTPM2_PolicyAuthorizeMake(pcrAlg, &authKey.pub,
793795
template.authPolicy.buffer, &digestSz, NULL, 0);
@@ -800,8 +802,15 @@ int wolfBoot_seal_blob(const uint8_t* pubkey_hint,
800802
wolfBoot_print_hexstr(template.authPolicy.buffer,
801803
template.authPolicy.size, 0);
802804
#endif
803-
/* Create a new key for sealing using external signing auth */
804-
wolfTPM2_GetKeyTemplate_KeySeal(&template, pcrAlg);
805+
806+
if (auth != NULL && authSz > 0) {
807+
/* allow password based sealing */
808+
template.objectAttributes |= TPMA_OBJECT_userWithAuth;
809+
}
810+
else {
811+
/* disable password based sealing, require policy */
812+
template.objectAttributes &= ~TPMA_OBJECT_userWithAuth;
813+
}
805814
rc = wolfTPM2_CreateKeySeal_ex(&wolftpm_dev, seal_blob,
806815
&wolftpm_srk.handle, &template, auth, authSz,
807816
pcrAlg, NULL, 0, secret, secret_sz);
@@ -1005,9 +1014,21 @@ int wolfBoot_unseal_blob(const uint8_t* pubkey_hint,
10051014
wolfBoot_printf("Loaded seal blob to 0x%x\n",
10061015
(uint32_t)seal_blob->handle.hndl);
10071016
#endif
1008-
seal_blob->handle.auth.size = authSz;
1009-
memcpy(seal_blob->handle.auth.buffer, auth, authSz);
1010-
wolfTPM2_SetAuthHandle(&wolftpm_dev, 0, &seal_blob->handle);
1017+
1018+
/* if using password auth, set it otherwise use policy auth */
1019+
if (auth != NULL && authSz > 0) {
1020+
seal_blob->handle.auth.size = authSz;
1021+
memcpy(seal_blob->handle.auth.buffer, auth, authSz);
1022+
wolfTPM2_SetAuthHandle(&wolftpm_dev, 0, &seal_blob->handle);
1023+
}
1024+
else {
1025+
/* use the policy session for unseal */
1026+
rc = wolfTPM2_SetAuthSession(&wolftpm_dev, 0, &policy_session,
1027+
(TPMA_SESSION_decrypt | TPMA_SESSION_encrypt |
1028+
TPMA_SESSION_continueSession));
1029+
/* set the sealed object name 0 (required) */
1030+
wolfTPM2_SetAuthHandleName(&wolftpm_dev, 0, &seal_blob->handle);
1031+
}
10111032

10121033
/* unseal */
10131034
unsealIn.itemHandle = seal_blob->handle.hndl;

0 commit comments

Comments
 (0)