Commit Graph

713 Commits (master)

Author SHA1 Message Date
Aidan Garske 64f2db9fcb Add SPDM-bound NV policy examples
Add an NV binding example and extend the SPDM control flow to exercise PSK- and certificate-authenticated policy sessions. Document and automate the end-to-end policy checks.
2026-09-15 12:24:05 -07:00
Aidan Garske a89169ef05 Include SPDM, PQC, test and CMake files in the source distribution 2026-09-14 13:28:18 -07:00
David Garske a2c3103e6e
Merge pull request #604 from aidangarske/fenrir-fixes-9172-13499
Harden wolfTPM examples fwTPM and SPDM error handling and secret zeroization
2026-09-11 09:31:34 -07:00
Aidan Garske 0d3f2f756a F-13463 - Clear ECC r and s on all policy signing paths 2026-09-10 13:09:23 -07:00
Aidan Garske 3adb0f5e4a F-13457 - Return an error for incomplete firmware update arguments 2026-09-10 13:09:23 -07:00
Aidan Garske 27d1bf5f9f F-10763 - Return an error on a GPIO config vendor mismatch 2026-09-10 13:09:23 -07:00
Aidan Garske 7d4d39780d F-13461 - Return success from the capabilities example handle listing 2026-09-10 13:09:23 -07:00
Aidan Garske 94963636ac F-11901 - Fail make credential when the AK name cannot be read 2026-09-10 13:09:23 -07:00
Aidan Garske e3cbe8ee1d F-11903 - Reject a negative get random length argument 2026-09-10 13:09:23 -07:00
Aidan Garske b58bee5952 F-9182 - Free PKCS7 state on error paths in the sign verify examples 2026-09-10 13:09:23 -07:00
Aidan Garske c425242730 F-9180 - Mask to the format-one field when checking hash bench errors 2026-09-10 13:09:23 -07:00
Aidan Garske 995b0879bc F-9175 - Return the flush result for an explicit handle 2026-09-10 13:09:23 -07:00
Aidan Garske 7792efb8ec F-9174 - Unload the TPM hash sequence object on failure paths 2026-09-10 13:09:23 -07:00
Aidan Garske 91326022d0 F-9173 - Return an error status from pcr policy argument validation 2026-09-10 13:09:23 -07:00
Aidan Garske 319d689108 F-9172 - Use XSTRNCMP to parse the -digest option in pcr policy 2026-09-10 13:09:23 -07:00
Aidan Garske 863f0f900b Restrict unsealed output file permissions 2026-09-10 12:54:14 -07:00
Aidan Garske 0df6f5253a Fix TLS and no-wolfCrypt CI failures 2026-09-10 09:22:04 -07:00
Aidan Garske 2f4b959ebb F-13528 - Honor peer certificate verification result in TLS examples 2026-09-09 15:31:02 -07:00
Aidan Garske e7a00928bd F-13458 - Stop the extend hashing loop on a short or failed read 2026-09-09 09:24:04 -07:00
Aidan Garske 18691a8b20 F-13455 - Read a precomputed digest file when crypto is disabled 2026-09-09 09:24:04 -07:00
Aidan Garske 4e073434bd F-11907 - Fail PKCS7 examples when the output file cannot be opened 2026-09-09 09:24:04 -07:00
Aidan Garske 90baab8d4b F-11906 - Report quote output file open and write failures 2026-09-09 09:24:04 -07:00
Aidan Garske 4f89183d18 F-11905 - Report make credential blob write failures 2026-09-09 09:24:04 -07:00
Aidan Garske b1be65ab14 F-11904 - Fail make credential when the RNG call fails 2026-09-09 09:24:04 -07:00
Aidan Garske bbd5036821 F-11902 - Treat clock_set argument as a forward increment 2026-09-09 09:24:04 -07:00
Aidan Garske 1413d16274 Refresh expired wolfSSL example CA certs and add a refresh script 2026-09-09 08:39:01 -07:00
Aidan Garske e9716101b2 Support ML-KEM credential activation and ML-DSA quotes in fwTPM 2026-09-07 18:44:02 -07:00
Aidan Garske 5e3cbd2241 F-12735 - Pin the SPDM responder identity 2026-09-02 14:14:58 -07:00
David Garske fe7167a6a9 Peer review feedback (thanks Aidan) 2026-09-02 11:54:59 -07:00
David Garske 50dfdcec95 Cover the ST33 command set probe in unit tests 2026-08-31 10:26:12 -07:00
David Garske 4ae80c56dd Fix vendor string capability accumulation 2026-08-31 10:26:12 -07:00
David Garske ca34684225 Select ST33 field upgrade commands from the TPM command set (ZD 22193) 2026-08-27 13:29:29 -07:00
David Garske 23a328ff87 Fix ST33 generation 1 manifest size and refuse oversized commands (ZD 22193) 2026-08-25 16:02:53 -07:00
Aidan Garske eda30bd209 Skip unsupported key loads without filesystem 2026-08-24 14:54:11 -07:00
Aidan Garske 2c67d40561 F-10759 - Report unsupported key loading 2026-08-22 09:50:46 -07:00
Aidan Garske 175b0bb428 F-9171 - Write exact quote attestation length 2026-08-21 14:23:41 -07:00
Aidan Garske 617b815a94 F-9170 - Fail unseal on file output errors 2026-08-21 14:21:47 -07:00
Aidan Garske 2051630166 F-9169 - Return failure from TLS setup errors 2026-08-21 14:19:39 -07:00
Aidan Garske 8134e7035a F-9167 - Stop GPIO setup after capability failure 2026-08-21 14:01:00 -07:00
Aidan Garske 25bb1672b2 F-9164 - Reject NULL file buffers in no-heap builds 2026-08-21 13:40:29 -07:00
Aidan Garske 32008fce9f F-9163 - Reject truncated public key blobs 2026-08-21 13:38:23 -07:00
David Garske 67027916e8
Merge pull request #570 from aidangarske/sealsq-pqc-tpm
Add SealSQ QVault post-quantum TPM Support
2026-08-14 13:38:37 -07:00
Aidan Garske b57d851156 Add SealSQ QVault TPM post-quantum support and pqc_ctrl example 2026-08-14 19:44:00 +01:00
David Garske 2b8e41caf1 Add caller-supplied policy authorization for TPM firmware upgrade
Lets a deployment gate the TPM firmware-update start command behind its own
platform hierarchy policy instead of the vendor default. Previously wolfTPM
always managed that authorization internally: on Infineon it installed and
satisfied a PolicyCommandCode(TPM_CC_FieldUpgradeStartVendor) policy on the
platform primary policy, and on ST33 it used password authorization with an
empty platform password. Both assume default platform auth, which a hardened
deployment will not have.

New _ex entry points take an already-satisfied session:
  wolfTPM2_FirmwareUpgradeHash_ex()
  wolfTPM2_FirmwareUpgrade_ex()
  wolfTPM2_FirmwareUpgradeRecover_ex()
Passing NULL for startSession keeps the existing library-managed behavior, so
the original functions are unchanged wrappers and existing code is unaffected.
With a session supplied, Infineon no longer overwrites the platform primary
policy (the caller provisions it) and ST33 uses the session in place of
TPM_RS_PW.

Supporting wrappers:
  wolfTPM2_PolicyOR()               satisfy a session with a compound OR
  wolfTPM2_PolicyCommandCodeMake()  offline PolicyCommandCode digest
  wolfTPM2_IsAlgSupported()         report whether the TPM implements an alg
PolicyOR is hash-agnostic (each branch carries its own size), so SHA2-256
through SHA2-512 policy branches all work. It requires at least two branches
per TPM 2.0 Part 3 Sec.23.6 and validates each branch size against the digest
buffer. PolicyCommandCodeMake takes digestSz as in/out - input is the output
buffer capacity and BUFFER_E is returned when it is too small, checked before
the buffer is written. IsAlgSupported reports through an out-parameter and
returns TPM_RC, so a capability-query failure cannot be misread as
"supported"; it sets the out-parameter to 0 on every error path.

Session contract: the vendor FieldUpgradeStart commands are hand-marshalled
with an authorization area carrying only the session handle - empty
nonceCaller, zero attributes, empty HMAC. That is correct only for an
unsalted, unbound policy session with no auth value, so the _ex path validates
the caller session up front and rejects anything needing a computed session
HMAC or parameter encryption (PolicyAuthValue/PolicyPassword, attached auth
value, bind, salt, encrypt/decrypt/audit attributes, or a non-policy handle).
Validation runs before any TPM traffic. On a successful start the TPM consumes
the session and the library sets handle.hndl to TPM_RH_NULL; this is now
documented, including that it is not zero and that wolfTPM2_UnloadHandle
no-ops on it.

Examples: ifx_fw_update and st33_fw_update gain --policy, --policyor and
--policytest, backed by a shared examples/firmware/firmware_policy.c. The
--policytest mode is a non-destructive self-test that checks the TPM's running
policy digest against an offline computation at SHA2-256/384/512, skipping any
hash the TPM does not implement or the local wolfCrypt build was not compiled
with (a build mismatch is a skip, not a failure). The provisioned PolicyOR
carries a PolicyCommandCode(TPM_CC_SetPrimaryPolicy) branch so the policy can
authorize its own removal, and cleanup is gated on a FirmwarePolicyCtx that
records what was actually provisioned, so an early failure cannot clear a
policy the deployment installed itself. A failed rollback is reported but
never overwrites the upgrade error that explains the run, and is skipped once
the start has succeeded (the TPM has reset into upgrade mode and will not
service SetPrimaryPolicy).

Because TPM 2.0 offers no way to read a hierarchy authPolicy back, the example
cannot detect or restore one it replaces, so provisioning prints an explicit
warning naming that. The policy modes are also refused where the session could
never be used: any Infineon operational mode other than normal (recovery and
finalize skip the start entirely), and on ST33 when the TPM is already in
firmware-upgrade mode - previously the flags were silently ignored there,
which is the authorization downgrade they exist to prevent. Rollback normally uses platform password
authorization, which an installed authPolicy does not disable (TPM 2.0 Part 1
Sec.19.7); this was confirmed on ST33KTPM2X, SLB9670 and SLB9673 parts.

The firmware examples now require wolfCrypt in their feature guards. They
drive wolfTPM2_FirmwareUpgrade_ex, which hashes the manifest with SHA-384 and
only exists with wolfCrypt, so --enable-firmware with --disable-wolfcrypt
previously failed to compile.

Also converts examples/nvram/extend.c to the new PolicyCommandCodeMake
capacity contract.

Tests: argument validation and known-answer vectors for the new wrappers,
short-buffer and canary coverage for PolicyCommandCodeMake, caller-session
rejection for every unsupported session shape plus an accepted session,
simulator-backed success paths for PolicyOR and IsAlgSupported, and a
regression test that a platform authPolicy remains clearable with password
authorization while a non-matching policy session is refused.
2026-08-13 11:18:25 -07:00
David Garske 46d2d337a4
Merge pull request #563 from aidangarske/fenrir-fixes-7606-7610
Reuse transport connections and reduce NV write and hash cache overhead
2026-08-11 15:30:00 -07:00
Aidan Garske 099de0e64c F-7593 - Check GetNvAttributesTemplate status before modifying attributes 2026-08-06 12:59:10 -07:00
Aidan Garske 62427d8060 F-7592 - Check BuildPolicyCommandCode status for each policy digest 2026-08-06 12:59:09 -07:00
Aidan Garske cc7cb89c11 F-7590 - Reserve the NUL terminator when clamping -secrethex= input 2026-08-06 12:59:09 -07:00
Aidan Garske 394dce3545 F-7586 - Keep EK cert verify result out of the example return code 2026-08-06 12:59:08 -07:00
Aidan Garske dc655b6b6f F-7585 - Parse policy_sign -pcrdigest= hex result in a signed temporary 2026-08-06 12:59:08 -07:00