Skip to content

Commit

Permalink
Cleanups from testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Aug 30, 2023
1 parent a152603 commit 78cd719
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion examples/boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Example for creating a sealed secret using that signed policy based on public ke

```sh
# Create a keyed hash sealed object using the policy authorization for the public key
./examples/boot/secret_seal -policy=policyauth.bin -out=sealblob.bin
./examples/boot/secret_seal -rsa -policy=policyauth.bin -out=sealblob.bin
./examples/boot/secret_seal -ecc -policy=policyauth.bin -out=sealblob.bin
# OR
# Provide the public key for policy authorization (instead of -policy=)
./examples/boot/secret_seal -rsa -publickey=./certs/example-rsa2048-key-pub.der -out=sealblob.bin
Expand Down
4 changes: 3 additions & 1 deletion examples/boot/secret_seal.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void usage(void)
printf("Expected usage:\n");
printf("./examples/boot/secret_seal [-secretstr=/-secrethex] [-policy=] [-out=]\n");
printf("./examples/boot/secret_seal [-secretstr=/-secrethex] [-ecc/-rsa] [-publickey=] [-out=]\n");
printf("* -secret=value: Secret to seal (default=random)\n");
printf("* -secretstr=string/-secrethex=hex: Secret to seal (default=random)\n");
printf("* -policy=file: Policy authorization digest for the public key used to sign the policy (default policyauth.bin)\n");
printf("* -ecc/-rsa: Public key is RSA or ECC (default is RSA)\n");
printf("* -publickey=file: Public key file (PEM or DER) for the policy signing key used\n");
Expand Down Expand Up @@ -138,6 +138,8 @@ int TPM2_Boot_SecretSeal_Example(void* userCtx, int argc, char *argv[])
else if (XSTRNCMP(argv[argc-1], "-secretstr=", XSTRLEN("-secretstr=")) == 0) {
const char* secretStr = argv[argc-1] + XSTRLEN("-secretstr=");
secretSz = (int)XSTRLEN(secretStr);
if (secretSz > (word32)sizeof(secret))
secretSz = (word32)sizeof(secret);
XMEMCPY(secret, secretStr, secretSz);
}
else if (XSTRNCMP(argv[argc-1], "-secrethex=", XSTRLEN("-secrethex=")) == 0) {
Expand Down
9 changes: 7 additions & 2 deletions examples/boot/secret_unseal.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ int TPM2_Boot_SecretUnseal_Example(void* userCtx, int argc, char *argv[])
Unseal_Out unsealOut;
byte* policyRef = NULL; /* optional nonce */
word32 policyRefSz = 0;
byte secret[MAX_SYM_DATA+1]; /* room for NULL term */
word32 secretSz = 0;

XMEMSET(&dev, 0, sizeof(WOLFTPM2_DEV));
XMEMSET(&storage, 0, sizeof(WOLFTPM2_KEY));
Expand Down Expand Up @@ -331,8 +333,11 @@ int TPM2_Boot_SecretUnseal_Example(void* userCtx, int argc, char *argv[])
goto exit;
}

printf("Secret (%d bytes):\n", unsealOut.outData.size);
printHexString(unsealOut.outData.buffer, unsealOut.outData.size, 32);
secretSz = unsealOut.outData.size;
XMEMSET(secret, 0, sizeof(secret));
XMEMCPY(secret, unsealOut.outData.buffer, secretSz);
printf("Secret (%d bytes): %s\n", secretSz, secret);
printHexString(secret, secretSz, 32);

exit:
if (rc != 0) {
Expand Down
15 changes: 11 additions & 4 deletions examples/boot/secure_rot.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
static void usage(void)
{
printf("Expected usage:\n");
printf("./examples/boot/secure_rot [-nvindex] [-write=/-hash=] [-auth] [-sha384] [-lock]\n");
printf("./examples/boot/secure_rot [-nvindex] [-write=/-hash=] [-authhex=/-authstr=] [-sha384] [-lock]\n");
printf("* -nvindex=[handle] (default 0x%x)\n",
TPM2_DEMO_NV_SECURE_ROT_INDEX);
printf("* -hash=hash: Hex string digest to write\n");
printf("* -write=filename: DER formatted public key to write\n");
printf("* -auth=password: Optional password for NV\n");
printf("* -authstr=password/-authhex=hexstring: Optional password for NV\n");
printf("* -sha384: Use SHA2-384 (default is SHA2-256)\n");
printf("* -lock: Lock the write\n");
printf("\nExamples:\n");
Expand Down Expand Up @@ -135,8 +135,15 @@ int TPM2_Boot_SecureROT_Example(void* userCtx, int argc, char *argv[])
}
doWrite = 1;
}
else if (XSTRNCMP(argv[argc-1], "-auth=", XSTRLEN("-auth=")) == 0) {
const char* authHexStr = argv[argc-1] + XSTRLEN("-auth=");
else if (XSTRNCMP(argv[argc-1], "-authstr=", XSTRLEN("-authstr=")) == 0) {
const char* authHexStr = argv[argc-1] + XSTRLEN("-authstr=");
authBufSz = (int)XSTRLEN(authHexStr);
if (authBufSz > (int)sizeof(authBuf))
authBufSz = (word32)sizeof(authBuf);
XMEMCPY(authBuf, authHexStr, authBufSz);
}
else if (XSTRNCMP(argv[argc-1], "-authhex=", XSTRLEN("-authhex=")) == 0) {
const char* authHexStr = argv[argc-1] + XSTRLEN("-authhex=");
int authHexStrLen = (int)XSTRLEN(authHexStr);
if (authHexStrLen > (int)sizeof(authBuf)*2+1)
authBufSz = -1;
Expand Down

0 comments on commit 78cd719

Please sign in to comment.