feat(tbor): implement SdCreate/RestorePeerBackup (peer SD cloning) - #570
Merged
Conversation
vsonims
force-pushed
the
sd/restore-remote-backup
branch
from
July 17, 2026 12:00
b838686 to
aeb070b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements TBOR security-domain peer cloning by adding the SdCreatePeerBackup (0x0E) and SdRestorePeerBackup (0x0F) command pair, gated by the SD policy’s allow_peer_cloning flag, and aligns the wire schema/docs/tests accordingly.
Changes:
- Add firmware handlers for
SdCreatePeerBackup(stateless HPKE-Auth seal of recovered BKS3) andSdRestorePeerBackup(stateful HPKE-Auth open + reprovision flow). - Refactor shared SD-backup logic by extracting
recover_bks3_from_pok_localintosd_backup.rsand reusing it fromSdRestoreLocalBackupandSdCreatePeerBackup. - Extend error/status surface and wiring: new
SdPeerCloningNotAllowederror, opcode classification/dispatch, updated host wrappers, docs, and new emu integration tests.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| fw/pal/traits/src/error.rs | Adds HsmError::SdPeerCloningNotAllowed for policy-gated peer cloning. |
| fw/core/lib/src/op.rs | Marks 0x0E/0x0F as InSession via SessionCtrl::from_tbor_opcode. |
| fw/core/lib/src/ddi/tbor/sd_create_peer_backup.rs | New handler: recover BKS3 from local backup and HPKE-Auth-seal to a peer (policy-gated). |
| fw/core/lib/src/ddi/tbor/sd_restore_peer_backup.rs | New handler: HPKE-Auth-open peer backup and reprovision SD (policy-gated, one-shot). |
| fw/core/lib/src/ddi/tbor/sd_restore_local_backup.rs | Refactors to reuse shared BKS3 recovery helper. |
| fw/core/lib/src/ddi/tbor/sd_backup.rs | Extracts shared recover_bks3_from_pok_local helper used by restore/local + create/peer. |
| fw/core/lib/src/ddi/tbor/mod.rs | Wires opcodes 0x0E/0x0F through module exports, dispatch, and opcode classifiers. |
| fw/core/ddi/tbor/types/src/sd_create_peer_backup.rs | Updates firmware-side wire schema for masked sealing key + HPKE peer backup (161B). |
| fw/core/ddi/tbor/types/src/sd_restore_peer_backup.rs | Updates firmware-side wire schema for masked sealing key + HPKE peer backup + prev_sd_mk_backup. |
| ddi/tbor/types/src/status.rs | Adds TborStatus::SdPeerCloningNotAllowed mirror status code. |
| ddi/tbor/types/src/sd_create_peer_backup.rs | Updates host-side wrapper types to match new schema (masked key + fixed-size peer backup). |
| ddi/tbor/types/src/sd_restore_peer_backup.rs | Updates host-side wrapper types to match new schema (masked key + fixed-size peer backup + prev backup). |
| ddi/tbor/types/tests/commands/mod.rs | Registers new integration test modules. |
| ddi/tbor/types/tests/commands/sd_create_peer_backup.rs | New emu integration tests for create-peer (roundtrip + policy/lifecycle rejects). |
| ddi/tbor/types/tests/commands/sd_restore_peer_backup.rs | New emu integration tests for restore-peer (roundtrip + one-shot + policy/lifecycle rejects). |
| docs/tbor-ddi/README.md | Updates command table rows to remove “schema-only” for 0x0E/0x0F. |
| docs/tbor-ddi/commands/sd_create_peer_backup.md | Rewrites command documentation to reflect the implemented handler and updated schema/flow. |
| docs/tbor-ddi/commands/sd_restore_peer_backup.md | Rewrites command documentation to reflect the implemented handler and updated schema/flow. |
jaygmsft
previously approved these changes
Jul 17, 2026
vsonims
force-pushed
the
sd/restore-remote-backup
branch
from
July 18, 2026 11:56
aeb070b to
717daad
Compare
vsonims
force-pushed
the
sd/restore-remote-backup
branch
from
July 18, 2026 12:08
717daad to
401df3b
Compare
vsonims
force-pushed
the
sd/restore-remote-backup
branch
from
July 19, 2026 03:17
401df3b to
ce8c882
Compare
vsonims
force-pushed
the
sd/restore-remote-backup
branch
from
July 20, 2026 18:35
ce8c882 to
2b03645
Compare
vsonims
enabled auto-merge
July 20, 2026 19:44
radutta99
approved these changes
Jul 20, 2026
Implements the security-domain peer-cloning command pair gated by the SD policy's `allow_peer_cloning` flag. Both use masked SD-sealing keys (unmasked on-device), not vault handles, matching the rest of the SD backup family; the stale schema-only stubs (key_id + 180-byte pok_peer_backup) are reworked to masked_sealing_key and a 161-byte HPKE-Auth seal. SdCreatePeerBackup (0x0E, stateless): recover BKS3 from the caller's pok_local_backup (under PartLocalMK) and HPKE-Auth-seal it to a destination peer named by dst_evidence, authenticated by the sender's masked sealing key. It is CreateSD's seal front-end over a recovered (not minted) BKS3; not one-shot, so a rebooted partition can clone to a peer after PartFinal without first restoring the SD locally. SdRestorePeerBackup (0x0F, stateful/one-shot): = SdRestoreRemoteBackup + an allow_peer_cloning gate. HPKE-Auth-open pok_peer_backup with the masked receiver key (authenticated by the sender peer's attested key), then reprovision_sd_from_bks3(prev_sd_mk_backup). Shared refactor: extract recover_bks3_from_pok_local into sd_backup.rs (used by local-restore and create-peer). New error HsmError::SdPeerCloningNotAllowed (0x0870010A) + TborStatus mirror. Wires opcodes 0x0E/0x0F through dispatch, op.rs (from_tbor_opcode), and the mod.rs classifiers. Adds emu integration tests: create-peer self-seal round-trip + reject paths; restore-peer create-peer→reboot→PartFinal(restore PartLocalMK)→ restore HPKE round-trip, one-shot, no-peer-cloning, and reject-before- finalize. Full emu suite: 121/121. Rewrites both command docs and the README table rows.
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.
What
Implements the security-domain peer-cloning command pair —
SdCreatePeerBackup(opcode0x0E, §3.3.10) andSdRestorePeerBackup(0x0F, §3.3.11) — gated by the SD policy'sallow_peer_cloningflag.Both commands use masked SD-sealing keys (unmasked on-device via
SdSealingKeyGen), not vault handles — matching the rest of the SD backup family. The stale schema-only stubs (key_id+ a 180-bytepok_peer_backup) are reworked tomasked_sealing_keyand a 161-byte HPKE-Auth seal.SdCreatePeerBackup (0x0E) — stateless
Recover BKS3 from the caller's
pok_local_backup(unmask underPartLocalMK) and HPKE-Auth-seal it to a destination peer named bydst_evidence, authenticated by the sender's masked sealing key →pok_peer_backup(161 B). It isSdCreateRemoteBackup's seal front-end over a recovered (not minted) BKS3. Not one-shot and does not touchSDMK, so a rebooted partition can clone to a peer afterPartFinalwithout first restoring the SD locally.SdRestorePeerBackup (0x0F) — stateful, one-shot
=
SdRestoreRemoteBackup+ anallow_peer_cloninggate. HPKE-Auth-openpok_peer_backupwith the masked receiver key (authenticated by the sender peer's attested key), thenreprovision_sd_from_bks3(prev_sd_mk_backup)→ device-local backups + vaultSDMK+ mark SD-initialized (undo-guarded).Shared refactor
recover_bks3_from_pok_localintosd_backup.rs(BKS3 unmask underPartLocalMK+SdPartitionOwnerSeedkind + anti-rollback);SdRestoreLocalBackuprefactored to reuse it, andSdCreatePeerBackupshares it.HsmError::SdPeerCloningNotAllowed = 0x0870010A+TborStatusmirror.0x0E/0x0Fwired throughdispatch,op.rsfrom_tbor_opcode, and themod.rsclassifiers.Tests
New emu integration tests (self-peer, sender == receiver):
pok_peer_backup), reject-no-peer-cloning, reject-before-finalize.PartFinal(prev_local_mk_backup)restoresPartLocalMK→ HPKE-open restore returns non-zero refreshed backups; one-shot (SdAlreadyInitialized); no-peer-cloning (SdPeerCloningNotAllowed); reject-before-finalize.Validation
cargo xtask nextest --features emu -p azihsm_ddi_tbor_types→ 121/121 (114 prior + 7 new, no regression).cargo xtask build -p azihsm_fw_hsm_std✓ · unocargo xtask clippy✓ · maincargo xtask clippy✓ · fw types unit tests 35/35 ✓.cargo +nightly fmt+cargo xtask copyrightclean.Docs
Rewrites both command docs and the README table rows (drops "schema-only").
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
Copilot-Session: 0b09e50a-a9be-4bae-b347-d42dc775a258