Skip to content

Commit c12aa6b

Browse files
committed
1. .github/workflows/seal-test.yml — Pin actions/checkout@master → @v4 for supply-chain safety. Add explicit ref: master for wolfSSL, no ref for ibmswtpm2 (matches other workflows).
2. examples/seal/seal_policy_auth.c — Clarify header comment: no pre-existing key needed, but authkey.bin must be retained for unseal. 3. examples/seal/seal_test.sh - Add || return 1 to setup_pcr/change_pcr extend calls - Use grep -F -q -- for fixed-string secret matching - Add 6 new param enc tests (3.4a-c XOR, 3.5a-c AES) for seal_nv 4. examples/nvram/seal_nv.c — Implement real parameter encryption: - Add paramEncSession (separate from tpmSession to avoid conflict) - Start unsalted HMAC session with XOR/AES-CFB - Place on session slot 2 (slot 1 is used internally by NVWriteData for NV handle auth) - Clean up session in exit path 5. examples/run_examples.sh — Add seal_nv XOR param encryption integration test
1 parent bb6a71c commit c12aa6b

5 files changed

Lines changed: 81 additions & 8 deletions

File tree

.github/workflows/seal-test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ jobs:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- name: Checkout wolfTPM
26-
uses: actions/checkout@master
26+
uses: actions/checkout@v4
2727

2828
- name: Checkout wolfSSL
29-
uses: actions/checkout@master
29+
uses: actions/checkout@v4
3030
with:
3131
repository: wolfssl/wolfssl
32+
ref: master
3233
path: wolfssl
3334

3435
- name: Build and install wolfSSL
@@ -41,7 +42,7 @@ jobs:
4142
sudo ldconfig
4243
4344
- name: Checkout ibmswtpm2
44-
uses: actions/checkout@master
45+
uses: actions/checkout@v4
4546
with:
4647
repository: kgoldman/ibmswtpm2
4748
path: ibmswtpm2

examples/nvram/seal_nv.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ int TPM2_NVRAM_SealNV_Example(void* userCtx, int argc, char *argv[])
7474
int rc;
7575
WOLFTPM2_DEV dev;
7676
WOLFTPM2_SESSION tpmSession;
77+
WOLFTPM2_SESSION paramEncSession;
7778
WOLFTPM2_HANDLE parent;
7879
WOLFTPM2_NV nv;
7980
TPM_ALG_ID paramEncAlg = TPM_ALG_NULL;
@@ -94,6 +95,7 @@ int TPM2_NVRAM_SealNV_Example(void* userCtx, int argc, char *argv[])
9495

9596
XMEMSET(&dev, 0, sizeof(dev));
9697
XMEMSET(&tpmSession, 0, sizeof(tpmSession));
98+
XMEMSET(&paramEncSession, 0, sizeof(paramEncSession));
9799
XMEMSET(&parent, 0, sizeof(parent));
98100
XMEMSET(&nv, 0, sizeof(nv));
99101

@@ -167,6 +169,21 @@ int TPM2_NVRAM_SealNV_Example(void* userCtx, int argc, char *argv[])
167169
goto exit;
168170
}
169171

172+
if (paramEncAlg != TPM_ALG_NULL) {
173+
/* Start TPM session for parameter encryption */
174+
rc = wolfTPM2_StartSession(&dev, &paramEncSession, NULL, NULL,
175+
TPM_SE_HMAC, paramEncAlg);
176+
if (rc != 0) goto exit;
177+
printf("TPM2_StartAuthSession: sessionHandle 0x%x\n",
178+
(word32)paramEncSession.handle.hndl);
179+
/* Set TPM session attributes for parameter encryption.
180+
* Use index 2 to avoid conflict with NV handle auth on index 1 */
181+
rc = wolfTPM2_SetAuthSession(&dev, 2, &paramEncSession,
182+
(TPMA_SESSION_decrypt | TPMA_SESSION_encrypt |
183+
TPMA_SESSION_continueSession));
184+
if (rc != 0) goto exit;
185+
}
186+
170187
/* Validate that the PCR bank is available */
171188
pcrDigestSz = (int)sizeof(pcrDigest);
172189
rc = wolfTPM2_ReadPCR(&dev, pcrIndex, pcrAlg, pcrDigest, &pcrDigestSz);
@@ -335,6 +352,7 @@ int TPM2_NVRAM_SealNV_Example(void* userCtx, int argc, char *argv[])
335352
}
336353

337354
wolfTPM2_UnloadHandle(&dev, &tpmSession.handle);
355+
wolfTPM2_UnloadHandle(&dev, &paramEncSession.handle);
338356

339357
wolfTPM2_Cleanup(&dev);
340358

examples/run_examples.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,33 @@ if [ $NO_FILESYSTEM -eq 0 ]; then
793793
[ $RESULT -ne 0 ] && echo -e "seal_nv delete failed! $RESULT" && exit 1
794794

795795
rm -f $TMPFILE aaa_nv.bin
796+
797+
# seal_nv with XOR parameter encryption
798+
if [ $WOLFCRYPT_ENABLE -eq 1 ]; then
799+
echo aaa > aaa_nv.bin
800+
./examples/pcr/reset 16 >> $TPMPWD/run.out 2>&1
801+
./examples/pcr/extend 16 aaa_nv.bin >> $TPMPWD/run.out 2>&1
802+
803+
SECRET_STRING="NVSealXorTest"
804+
./examples/nvram/seal_nv -store -pcr=16 -xor -secretstr=$SECRET_STRING >> $TPMPWD/run.out 2>&1
805+
RESULT=$?
806+
[ $RESULT -ne 0 ] && echo -e "seal_nv store -xor failed! $RESULT" && exit 1
807+
808+
TMPFILE=$(mktemp)
809+
./examples/nvram/seal_nv -read -pcr=16 -xor &> $TMPFILE
810+
RESULT=$?
811+
cat $TMPFILE >> $TPMPWD/run.out
812+
[ $RESULT -ne 0 ] && echo -e "seal_nv read -xor failed! $RESULT" && exit 1
813+
grep "$SECRET_STRING" $TMPFILE >> $TPMPWD/run.out 2>&1
814+
RESULT=$?
815+
[ $RESULT -ne 0 ] && echo -e "seal_nv read -xor match failed! $RESULT" && exit 1
816+
817+
./examples/nvram/seal_nv -delete >> $TPMPWD/run.out 2>&1
818+
RESULT=$?
819+
[ $RESULT -ne 0 ] && echo -e "seal_nv delete (xor) failed! $RESULT" && exit 1
820+
821+
rm -f $TMPFILE aaa_nv.bin
822+
fi
796823
fi
797824

798825
run_tpm_policy() { # Usage: run_tpm_policy [ecc/rsa] [key] [pcrs]

examples/seal/seal_policy_auth.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
/* Self-contained PolicyAuthorize seal/unseal example.
2323
*
2424
* Creates a TPM-internal signing key, seals a secret with PolicyAuthorize
25-
* + PCR policy, then unseals using the same key. Single program, no
26-
* external key files needed.
25+
* + PCR policy, then unseals using the same key. No pre-existing signing
26+
* key is required — the TPM generates one internally. However, the key
27+
* blob file (authkey.bin) must be retained for subsequent unseal operations.
2728
*
2829
* Sealing method: PolicyAuthorize (with PCR policy)
2930
* Complexity: High

examples/seal/seal_test.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ run_test() {
5353
if [ $rc -ne 0 ]; then
5454
fail "$desc (exit code: $rc)"; rm -f "$tmpout"; return 1
5555
fi
56-
if [ -n "$secret" ] && ! grep -q "$secret" "$tmpout"; then
56+
if [ -n "$secret" ] && ! grep -F -q -- "$secret" "$tmpout"; then
5757
fail "$desc (secret not found in output)"; rm -f "$tmpout"; return 1
5858
fi
5959
pass "$desc"; rm -f "$tmpout"; return 0
@@ -66,12 +66,12 @@ run_test() {
6666
setup_pcr() {
6767
./examples/pcr/reset 16 >> "$LOGFILE" 2>&1 || return 1
6868
echo aaa > aaa_pcr16.bin
69-
./examples/pcr/extend 16 aaa_pcr16.bin >> "$LOGFILE" 2>&1
69+
./examples/pcr/extend 16 aaa_pcr16.bin >> "$LOGFILE" 2>&1 || return 1
7070
}
7171

7272
change_pcr() {
7373
echo bbb > bbb_pcr16.bin
74-
./examples/pcr/extend 16 bbb_pcr16.bin >> "$LOGFILE" 2>&1
74+
./examples/pcr/extend 16 bbb_pcr16.bin >> "$LOGFILE" 2>&1 || return 1
7575
}
7676

7777
# Pre-flight
@@ -248,6 +248,32 @@ else
248248
./examples/nvram/seal_nv -read -pcr=16 -nvindex=0x01800204
249249
run_test "3.3c seal_nv -delete nvindex=0x01800204" expect_pass -- \
250250
./examples/nvram/seal_nv -delete -nvindex=0x01800204
251+
252+
# 3.4: XOR param encryption
253+
if [ $WOLFCRYPT_ENABLE -eq 1 ]; then
254+
setup_pcr; S="NVSealXor004"
255+
run_test "3.4a seal_nv -store -xor" expect_pass -- \
256+
./examples/nvram/seal_nv -store -pcr=16 -xor -secretstr="$S"
257+
run_test "3.4b seal_nv -read -xor (verify)" expect_pass "$S" -- \
258+
./examples/nvram/seal_nv -read -pcr=16 -xor
259+
run_test "3.4c seal_nv -delete" expect_pass -- \
260+
./examples/nvram/seal_nv -delete
261+
else
262+
skip "3.4 seal_nv -xor (wolfCrypt disabled)"
263+
fi
264+
265+
# 3.5: AES param encryption
266+
if [ $WOLFCRYPT_ENABLE -eq 1 ] && [ $WOLFCRYPT_DEFAULT -eq 0 ]; then
267+
setup_pcr; S="NVSealAes005"
268+
run_test "3.5a seal_nv -store -aes" expect_pass -- \
269+
./examples/nvram/seal_nv -store -pcr=16 -aes -secretstr="$S"
270+
run_test "3.5b seal_nv -read -aes (verify)" expect_pass "$S" -- \
271+
./examples/nvram/seal_nv -read -pcr=16 -aes
272+
run_test "3.5c seal_nv -delete" expect_pass -- \
273+
./examples/nvram/seal_nv -delete
274+
else
275+
skip "3.5 seal_nv -aes (wolfCrypt default or disabled)"
276+
fi
251277
fi
252278
echo ""
253279

0 commit comments

Comments
 (0)