Repository navigation
Fix hmac_smoke sign-permission test to run on real HW (not just emu) - #741
Stuart R. Anderson (netsweng) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The documented emulator-only test scope is correctly enforced.
Review effort: Lite
Findings: None
What changed in this PR
Restricts the HMAC permission smoke test to emulator builds, preventing failures on real hardware.
Changes:
- Replaced the
not(mock)gate withfeature = "emu".
| File | Description |
|---|---|
ddi/mbor/types/tests/integration/hmac_smoke.rs |
Limits the sign-permission test to emulator builds. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
This needs to be rebased to pick up a fix form PR #742 once it merges. |
… only (#740) The test's module doc already documents this as an emu-only test (deriving a derive-only VarHmac256 key via HKDF then attempting to sign), but the #[cfg] gate used not(feature = "mock") which also included real hardware (nix backend). Real HSM firmware rejects the derive-only VarHmac256 HKDF-derive step with InvalidPermissions before the test reaches its intended sign-permission assertion, causing spurious failures on real hardware. Verified: all 616 tests pass with --features mock, and a locally built azihsm_ddi_tests binary (nix/real-hardware backend) run against real AZIHSM hardware now passes 599/599 (0 failed). Co-authored-by: Stuart R. Anderson <stuanderson@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
30767f2 to
2a01220
Compare
Follow-up: confirmed real-HW behavior is a deliberate firmware design divergence, not a stale buildRetested this PR's fix on mock, emu, and real hardware:
Root cause, traced to the real firmware sourceI dug further into why real HW rejects this (initially suspected a stale firmware build lagging the SDK's
This means the SDK's ConclusionThe |
test_hmac_requires_sign_permission_smoke was gated to emu only because real firmware rejects the derive-only VarHmac key at creation time (InvalidPermissions from HkdfDerive), rather than at the later MAC-sign attempt like the emu backend. Change the gate to not(feature = "mock") and accept InvalidPermissions at either the key-derivation step (real HW) or the MAC-sign step (emu), so the test exercises the same permission-enforcement guarantee uniformly across both non-mock backends. Verified: mock 2/2 (test still excluded), emu 4/4, real HW 4/4 (previously 3/4 with the unconditional emu-only gate removed).
| //! - **Sign permission** (emu only): a `derive`-only HMAC key cannot | ||
| //! generate a MAC — rejected with `InvalidPermissions` (MAC | ||
| //! generation is a PKCS#11 `C_Sign` operation requiring `CKA_SIGN`). | ||
| //! - **Sign permission** (emu + real HW, not mock): a `derive`-only |
There was a problem hiding this comment.
Good catch — the PR description's testing command was wrong. I re-ran it correctly as cargo xtask nextest --features emu --package azihsm_ddi_mbor_types (the test is gated #[cfg(not(feature = "mock"))], so --features mock skips it entirely; --features emu is the correct flag to exercise the emu rejection-of-MAC-attempt path). Confirmed it passes. Updated the PR description accordingly.

Summary
test_hmac_requires_sign_permission_smokeis supposed to prove aderive-only HMAC key can't produce a MAC, but it hung off a cfg gate (#[cfg(not(feature = "mock"))]) that also included real hardware (nix backend), and its body assumed the emu-only rejection point. Real HSM firmware rejects the derive-onlyVarHmac256HKDF-derive key's creation outright (every HMAC-class key requiresSignVerify, with noderive-only carve-out) before the test ever reaches its intended sign-permission-on-MAC assertion, causing spurious failures on real hardware.The intent of this PR is to make the test actually pass on real HW, not merely to cherry-pick #740's original (incorrect) fix as-is — that fix narrowed the gate to
#[cfg(feature = "emu")], which hides the real-HW path instead of fixing it to work there too.Fix
Instead of gating the test to emu-only, relaxed the assertion to accept either backend's valid rejection point:
InvalidPermissions(the original scenario this test was written for).InvalidPermissionsbefore a MAC is ever attempted.Both are valid proof that a key lacking sign permission can't produce a MAC, so the test now runs on both backends instead of being emu-only.
Testing
cargo xtask nextest --features emu --package azihsm_ddi_mbor_types(emu path): passedAZIHSM_USE_TPM=1: passed, exercising the real-HWInvalidPermissions-on-creation rejection path