SE050Sim: enforce applet 7.2 read policy on symmetric key objects - #10
Merged
LinuxJedi merged 2 commits intoJul 30, 2026
Merged
Conversation
On SE05x applet >= 7.2 hardware, ReadObject on a symmetric key object is refused with SW 0x6986 (command not allowed) unless the policy attached at object creation grants POLICY_OBJ_ALLOW_READ; an object created with no policy attached is not readable. wolfSSL's ECDH offload pre-creates the derive target HMACKey object and reads the shared secret back out of it, so a port that attaches no read policy fails only on hardware (ZD 22212) - the simulator accepted the read regardless of policy and strict-mode CI could not catch it. Record the union of the TAG_POLICY AR headers on HMACKey objects at WriteSymmKey and, in SE050_SIM_STRICT_ECDH=1 mode, refuse ReadObject with SW_COMMAND_NOT_ALLOWED unless POLICY_OBJ_ALLOW_READ is granted. The ECDH derive preserves the target's policy when overwriting its value. ReadSize stays unguarded since sss_key_store_get_key sizes its buffer with it, and lenient mode keeps the old always-readable behavior so hosts that predate the contract keep working.
There was a problem hiding this comment.
Pull request overview
This PR updates the SE050Sim “strict ECDH” behavior to better match SE05x applet >= 7.2 hardware by tracking object creation policies for HMACKey objects and enforcing the “read allowed” bit on ReadObject in strict mode. This closes a simulator/hardware behavioral gap that prevented CI from catching missing read-policy attachment on ECDH derive targets.
Changes:
- Add a minimal policy TLV parser (
policymodule) that extracts the union of AR headers from TAG_POLICY entries. - Record TAG_POLICY-derived AR header union on stored
HMACKeyobjects duringWriteSymmKey(P1=HMAC). - In strict mode, refuse
ReadObjectforHMACKeyunlessPOLICY_OBJ_ALLOW_READis granted; preserve the target policy across ECDH derive overwrites.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| SE050Sim/se050-sim/src/policy.rs | New minimal policy-entry parser for extracting AR header union. |
| SE050Sim/se050-sim/src/object_store/types.rs | Extend SecureObject::HMACKey to persist an optional policy header union. |
| SE050Sim/se050-sim/src/lib.rs | Export the new policy module. |
| SE050Sim/se050-sim/src/handlers/object_mgmt.rs | Add strict-mode gating for ReadObject exports of HMACKey based on recorded policy. |
| SE050Sim/se050-sim/src/handlers/ec.rs | Preserve HMACKey policy when ECDH overwrites the derive target. |
| SE050Sim/se050-sim/src/handlers/aes.rs | Parse and store TAG_POLICY-derived AR header union on HMACKey writes. |
| SE050Sim/se050-sim/src/dispatch.rs | Thread strict-mode flag into object reads via strict_ecdh_from_env(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
A TAG_POLICY value that does not parse as a policy entry sequence was silently recorded as no-policy-attached, deferring the failure to a confusing strict-mode read denial. Fail the write with SW_WRONG_DATA instead, as the applet would.
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.
Motivation
On SE05x applet >= 7.2 hardware,
ReadObjecton a symmetric key object is refused with SW 0x6986 (command not allowed) unless the policy attached at object creation grantsPOLICY_OBJ_ALLOW_READ; an object created with no policy attached is not readable. wolfSSL's ECDH offload pre-creates the derive target HMACKey object and reads the shared secret back out of it after the derive, so a port that attaches no read policy fails only on real hardware (ZD 22212) - the simulator accepted the read regardless of policy, and the strict-mode CI could not catch it.Changes
policymodule: minimal model of the object policy TLV (sequence oflength | authObjectId | AR headerentries perse05x_const.h), extracting the union of the AR headers.WriteSymmKeywith P1=HMAC records the attached TAG_POLICY AR header union on the storedHMACKeyobject (Nonewhen no policy is attached).SE050_SIM_STRICT_ECDH=1),ReadObjecton anHMACKeyobject is refused withSW_COMMAND_NOT_ALLOWED(0x6986) unless the recorded policy grantsPOLICY_OBJ_ALLOW_READ.ReadSizestays unguarded sincesss_key_store_get_keysizes its buffer with it.Validation
cargo test: 35 lib tests (5 new policy-parser tests, 5 new read-policy tests, 1 new derive-preserves-policy test, existing tests updated) + 14 integration tests pass.Dockerfile.wolfcrypt,SE050_SIM_STRICT_ECDH=1):se050_applet72_ecdhbranch without the read-policy fix: ECC test fails exactly like the customer's hardware log -APDU Transaction Error: Command not allowed - access denied based on object policy (0x6986)insss_se05x_key_store_get_key,ecc_test_curve_size 28 failedwith -248 (WC_HW_E).Pairs with the wolfSSL-side fix on the
se050_applet72_ecdhbranch; its CISIMULATORS_REFpin should be bumped to this PR's head once merged.