Repository navigation
Fix parameter encryption, argument checks and cleanup in the wolfTPM examples - #679
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Platform NV indexes can use the wrong authorization hierarchy, negative GPIO pins can trigger writes to the default pin, and ECDH secret erasure can be optimized away.
3 open issues
What changed in this PR
This PR hardens wolfTPM’s examples around parameter encryption, argument validation, error reporting, and cleanup. It also corrects HMAC authorization in the wrapper library and adds a regression test.
Changes:
- Keeps parameter-encryption sessions separate from handle authorization and policy sessions.
- Improves input checks, failure exit statuses, NV handling, and firmware-policy rollback.
- Adds resource cleanup and secret-buffer wiping, and clarifies demonstration limits.
| File | Description |
|---|---|
tests/unit_tests.c |
Adds HMAC parameter-encryption regression coverage. |
src/tpm2_wrap.c |
Supplies the key Name for HMAC_Start authorization. |
examples/wrap/wrap_test.c |
Adjusts encryption sessions, cleanup, and failure reporting. |
examples/wrap/hmac.c |
Moves parameter encryption to slot 1. |
examples/tls/tls_server.c |
Adjusts sessions, separates I/O errors, and closes accepted sockets. |
examples/tls/tls_client.c |
Adjusts sessions and separates I/O errors from byte counts. |
examples/tls/tls_client_notpm.c |
Improves cipher-selection failure and I/O error handling. |
examples/timestamp/signed_timestamp.c |
Corrects the session description in a comment. |
examples/spdm/spdm_ctrl.c |
Distinguishes unparsed capability responses from unsupported capabilities. |
examples/spdm/nv_bind.c |
Refuses to replace an existing NV index. |
examples/seal/seal_policy_auth.c |
Documents demonstration limits and validates PCR indexes before narrowing. |
examples/seal/seal_pcr.c |
Validates PCR indexes before narrowing. |
examples/run_examples.sh |
Copies CRLs under PEM-compatible filenames. |
examples/pqc/mldsa_verify_neg.c |
Flushes verification sequences after failures. |
examples/pqc/mldsa_sign.c |
Tracks and releases unfinished sequences. |
examples/pcr/read_pcr.c |
Returns an error for out-of-range PCR indexes. |
examples/pcr/quote.c |
Propagates argument, hashing, and verification failures. |
examples/pcr/policy.c |
Corrects the session description in a comment. |
examples/pcr/policy_sign.c |
Checks signature capacity, preserves errors, and wipes key buffers. |
examples/pcr/extend.c |
Returns an error for out-of-range PCR indexes. |
examples/nvram/store.c |
Selects authorization by NV range and accepts range boundaries. |
examples/nvram/seal_nv.c |
Validates PCR indexes and moves encryption to slot 1. |
examples/nvram/policy_nv.c |
Separates policy and encryption sessions and refreshes the NV Name. |
examples/nvram/extend.c |
Adjusts sessions, platform attributes, and endorsement-key cleanup. |
examples/nvram/counter.c |
Selects authorization by NV range and accepts range boundaries. |
examples/management/da_check.c |
Saves and restores dictionary-attack parameters. |
examples/keygen/keyload.c |
Separates sessions and cleans up keys after persistence failures. |
examples/keygen/keyimport.c |
Wipes the imported key buffer before release. |
examples/keygen/keygen.c |
Separates sessions and propagates artifact-writing failures. |
examples/keygen/ecdh.c |
Adds shared-secret wiping at cleanup. |
examples/keygen/create_primary.c |
Corrects the session description in a comment. |
examples/gpio/gpio_set.c |
Separates optional pin parsing from state options. |
examples/firmware/st33_fw_update.c |
Preserves start-command state for policy rollback. |
examples/firmware/ifx_fw_update.c |
Preserves start-command state for policy rollback. |
examples/firmware/ifx_fw_extract.c |
Uses the supplied buffer in extraction macros. |
examples/endorsement/verify_ek_cert.c |
Documents the limits of TPM-side certificate verification. |
examples/csr/csr.c |
Normalizes success and reports output-file opening failures. |
examples/boot/secret_unseal.c |
Tightens PCR validation and corrects the example description. |
examples/bench/bench.c |
Flushes ML-DSA verification sequences after completion failures. |
examples/attestation/activate_credential.c |
Accepts an input filename alongside the endorsement-key option. |
Review effort: Balanced
aidangarske
requested changes
Nov 23, 2026
aidangarske
left a comment
Member
There was a problem hiding this comment.
Skoll Code Review
Scan type: review
Overall recommendation: REQUEST_CHANGES
Findings: 2 total — 2 posted, 0 skipped
2 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] Platform-range indices retain owner authorization —
examples/nvram/policy_nv.c:95-107 - [Medium] NV hierarchy selection lacks boundary coverage —
examples/nvram/policy_nv.c:95-107
Review generated by Skoll
dgarske
force-pushed
the
fenrir_examples
branch
from
November 23, 2026 20:55
d000d12 to
57b9a58
Compare
dgarske
requested review from
aidangarske
and
a balanced review from Copilot
November 23, 2026 20:56
dgarske
force-pushed
the
fenrir_examples
branch
from
November 24, 2026 01:43
57b9a58 to
b91438e
Compare
aidangarske
reviewed
Nov 24, 2026
dgarske
force-pushed
the
fenrir_examples
branch
from
November 24, 2026 20:15
b91438e to
ba50dec
Compare
aidangarske
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This PR fixes defects in the examples found by review. One commit per finding. Key changes:
-aesand-xorsession was installed in an authorization slot that the next wrapper call overwrote or that was never sent, so nothing was encrypted. wrap_test, hmac, tls_client, tls_server, seal_nv, policy_nv, nvram/extend, keygen and keyload now keep the session in slot 1 and release it at exit. seal_nv and policy_nv salt that session with the storage key, since a session that authorizes nothing would otherwise have a key derived from public nonces.wolfTPM2_HmacStartsets the key Name for its authorization, so an HMAC session on HMAC_Start no longer fails with TPM_RC_BAD_AUTH. This is the one library change, with a unit test.Testing: the examples were run against the fwTPM and the reference simulator with and without parameter encryption, and the session was confirmed on the wire for each fixed example. No hardware TPM was used.
Scope: seal_policy_auth and verify_ek_cert are documented, not redesigned.
Resolves F-16127, F-16792, F-16793, F-16794, F-16795, F-16796, F-16797, F-16799, F-16801, F-16802, F-16804, F-16805, F-16806, F-16807, F-16813, F-16814, F-16829, F-16830, F-17114, F-17115, F-17116, F-17117, F-17118, F-17119, F-17120, F-17121, F-17122, F-17123, F-17124, F-17125, F-17127, F-17128, F-17129, F-17135, F-17136, F-17139, F-17975, F-17976, F-17977, F-17978, F-17979, F-17980, F-17981, F-17982, F-17983, F-17985, F-18061