Skip to content

SE050Sim: enforce applet 7.2 read policy on symmetric key objects - #10

Merged
LinuxJedi merged 2 commits into
wolfSSL:mainfrom
LinuxJedi:se050-strict-derive-read-policy
Jul 30, 2026
Merged

SE050Sim: enforce applet 7.2 read policy on symmetric key objects#10
LinuxJedi merged 2 commits into
wolfSSL:mainfrom
LinuxJedi:se050-strict-derive-read-policy

Conversation

@LinuxJedi

Copy link
Copy Markdown
Member

Motivation

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 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

  • New policy module: minimal model of the object policy TLV (sequence of length | authObjectId | AR header entries per se05x_const.h), extracting the union of the AR headers.
  • WriteSymmKey with P1=HMAC records the attached TAG_POLICY AR header union on the stored HMACKey object (None when no policy is attached).
  • In strict mode (SE050_SIM_STRICT_ECDH=1), ReadObject on an HMACKey object is refused with SW_COMMAND_NOT_ALLOWED (0x6986) unless the recorded policy grants POLICY_OBJ_ALLOW_READ. ReadSize stays unguarded since sss_key_store_get_key sizes its buffer with it.
  • The ECDH derive preserves the target object's policy when overwriting its value with the shared secret.
  • Lenient mode (default) keeps the old always-readable behavior so hosts that predate the contract keep working.

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.
  • wolfCrypt-vs-simulator Docker run (Dockerfile.wolfcrypt, SE050_SIM_STRICT_ECDH=1):
    • against the wolfSSL se050_applet72_ecdh branch 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) in sss_se05x_key_store_get_key, ecc_test_curve_size 28 failed with -248 (WC_HW_E).
    • against the branch with the read-policy fix (attaches a common policy granting read/write/delete to the derive target): full wolfCrypt suite passes.

Pairs with the wolfSSL-side fix on the se050_applet72_ecdh branch; its CI SIMULATORS_REF pin should be bumped to this PR's head once merged.

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.
Copilot AI review requested due to automatic review settings July 30, 2026 09:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (policy module) that extracts the union of AR headers from TAG_POLICY entries.
  • Record TAG_POLICY-derived AR header union on stored HMACKey objects during WriteSymmKey (P1=HMAC).
  • In strict mode, refuse ReadObject for HMACKey unless POLICY_OBJ_ALLOW_READ is 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.

Comment thread SE050Sim/se050-sim/src/handlers/aes.rs Outdated
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.
@LinuxJedi
LinuxJedi merged commit 3453013 into wolfSSL:main Jul 30, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants