Skip to content

feat(tbor): implement SdRestoreRemoteBackup (remote SD recovery) - #567

Merged
vsonims merged 1 commit into
mainfrom
sd/restore-remote-backup
Jul 20, 2026
Merged

feat(tbor): implement SdRestoreRemoteBackup (remote SD recovery)#567
vsonims merged 1 commit into
mainfrom
sd/restore-remote-backup

Conversation

@vsonims

@vsonims vsonims commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

What

Implements SdRestoreRemoteBackup (opcode 0x0C, manticore §3.3.8) — the peer/migration recovery path for a security domain. It is SdResealRemoteBackup's HPKE-open front-end + SdRestoreLocalBackup's provisioning back-end.

Stacked on #566 (sd/restore-local-backup). Review/merge that first; this PR's diff is only the remote-restore delta.

Flow

  1. Gate to a Crypto-Officer Active session on an Initialized partition; fail-fast one-shot (SdAlreadyInitialized).
  2. Bind the caller policy to the partition policy_hash, then verify the sender evidence: cert chains validated + anchored to the policy SATA key, report v2 policy_hash == SHA-384(policy) → recover SndrPub.
  3. Unmask masked_sealing_keyRcvrPriv (must be SdSealing); derive RcvrPub on-device.
  4. HPKE-Auth-open src_remote_backup (sender-auth SndrPub) → BKS3.
  5. reprovision_sd_from_bks3: recover SDMK from prev_sd_mk_backup, re-mask both backups at the current {svn, owner}, vault SDMK, mark the partition SD-initialized — undo-guarded. RcvrPriv, BKS3, SDMK, SDBMK are zeroized on every exit path.

Changes

  • Handler fw/core/lib/src/ddi/tbor/sd_restore_remote_backup.rs (new).
  • Wire schema reworked (was a stale placeholder): masked_sealing_key(180) · policy(484) · sender_evidence · src_remote_backup(161) · prev_sd_mk_backup(164, required). Host + fw schemas + round-trip unit tests.
  • Shared back-end: extracted reprovision_sd_from_bks3 into sd_backup.rs (recover SDMK + anti-rollback + re-mask + vault-commit); refactored SdRestoreLocalBackup to reuse it — both restores now share one provisioning path.
  • Dispatch wiring for 0x0C: mod.rs (dispatch arm + is_known_opcode/is_in_session/needs_session_id_cross_check) and op.rs from_tbor_opcode (required, else the SQE session-flag check rejects it as InvalidArg).
  • Docs: full docs/tbor-ddi/commands/sd_restore_remote_backup.md + README table row (drops "schema-only").

Tests

New emu integration tests (ddi/tbor/types/tests/commands/sd_restore_remote_backup.rs):

  • Round-trip — device 1 finalize + CreateSD → reboot → device 2 PartFinal(prev_local_mk_backup) restores PartLocalMK (so the captured sealing key unmasks) → HPKE-open restore returns non-zero refreshed local backups.
  • One-shot — restore onto an already-initialized SD → SdAlreadyInitialized.
  • Reject before finalizeInvalidArg.

Validation

  • cargo xtask nextest --features emu -p azihsm_ddi_tbor_types113/113 pass (109 prior + 4 new, no regression).
  • cargo xtask build -p azihsm_fw_hsm_std ✓ · uno cargo xtask clippy (core lib + uno PAL) ✓ · main cargo xtask clippy (full workspace) ✓.
  • cargo +nightly fmt + cargo xtask copyright clean.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
Copilot-Session: 0b09e50a-a9be-4bae-b347-d42dc775a258

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Implements firmware + host support for TBOR SdRestoreRemoteBackup (opcode 0x0C), enabling security-domain recovery from a remote HPKE-authenticated backup by combining sender-evidence verification with the existing SD provisioning/restore mechanics.

Changes:

  • Added the SdRestoreRemoteBackup handler, wired opcode/dispatch/session classification, and updated the wire schema to use masked_sealing_key, src_remote_backup, and required prev_sd_mk_backup.
  • Refactored SD restore provisioning into a shared sd_backup::reprovision_sd_from_bks3 path, and updated local restore to reuse it.
  • Added docs and emu integration tests for remote restore, plus minor test harness visibility adjustments.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
fw/core/lib/src/op.rs Adds SD_RESTORE_REMOTE_BACKUP to the in-session opcode classification.
fw/core/lib/src/ddi/tbor/sd_restore_remote_backup.rs New handler implementing remote SD restore: evidence verification + HPKE open + provisioning.
fw/core/lib/src/ddi/tbor/sd_restore_local_backup.rs Refactors local restore to reuse the shared provisioning function.
fw/core/lib/src/ddi/tbor/sd_backup.rs Extracts shared SD reprovisioning logic (reprovision_sd_from_bks3).
fw/core/lib/src/ddi/tbor/mod.rs Wires new opcode constant, dispatch arm, and opcode classifiers.
fw/core/ddi/tbor/types/src/sd_restore_remote_backup.rs Updates firmware-side TBOR wire schema and schema unit tests.
docs/tbor-ddi/README.md Updates command table entry to reflect handler is implemented (not schema-only).
docs/tbor-ddi/commands/sd_restore_remote_backup.md Adds full command documentation for remote restore flow, schema, and errors.
ddi/tbor/types/tests/commands/sd_restore_remote_backup.rs Adds new emu integration tests for remote restore (round-trip, one-shot, pre-finalize reject).
ddi/tbor/types/tests/commands/sd_create_remote_backup.rs Exposes evidence fields for reuse by remote restore tests.
ddi/tbor/types/tests/commands/mod.rs Registers the new remote restore integration test module.
ddi/tbor/types/src/sd_restore_remote_backup.rs Updates host-side request/response wrapper to match the new schema.

Comment thread docs/tbor-ddi/commands/sd_restore_remote_backup.md Outdated
Comment thread docs/tbor-ddi/commands/sd_restore_remote_backup.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

jaygmsft
jaygmsft previously approved these changes Jul 17, 2026
@vsonims
vsonims force-pushed the sd/restore-remote-backup branch 3 times, most recently from 401df3b to ce8c882 Compare July 19, 2026 03:17
@vsonims
vsonims changed the base branch from sd/restore-local-backup to main July 19, 2026 03:18
@vsonims
vsonims dismissed jaygmsft’s stale review July 19, 2026 03:18

The base branch was changed.

@vsonims
vsonims enabled auto-merge July 20, 2026 18:32
Restores a security domain from a **remote** backup (manticore §3.3.8):
the peer/migration recovery counterpart to SdRestoreLocalBackup. It is
SdResealRemoteBackup's HPKE-open front-end + the shared SD provisioning
back-end:-

  1. Gate to a Crypto-Officer Active session on an Initialized partition;
     fail-fast one-shot (SdAlreadyInitialized).
  2. Bind the caller policy to the partition policy_hash, then verify the
     sender evidence (cert chains anchored to the policy SATA key; report
     v2 policy_hash == SHA-384(policy)) → SndrPub.
  3. Unmask masked_sealing_key → RcvrPriv (must be SdSealing); derive
     RcvrPub on-device.
  4. HPKE-Auth-open src_remote_backup (sender-auth SndrPub) → BKS3.
  5. reprovision_sd_from_bks3: recover SDMK from prev_sd_mk_backup,
     re-mask both backups at the current {svn, owner}, vault SDMK, and
     mark the partition SD-initialized — undo-guarded. RcvrPriv, BKS3,
     SDMK, SDBMK scrubbed on every exit path.

Reworks the stale wire schema (masked_sealing_key(180); policy(484);
src_remote_backup(161); prev_sd_mk_backup(164) required) and extracts the
shared reprovision_sd_from_bks3 helper into sd_backup.rs, refactoring
SdRestoreLocalBackup to reuse it. Wires opcode 0x0C through dispatch,
op.rs (from_tbor_opcode), and the mod.rs classifiers.

Adds emu integration tests: create→reboot→PartFinal(restore
PartLocalMK)→restore-remote HPKE round-trip, one-shot rejection, and
reject-before-finalize. Full emu suite: 113/113. Updates the command doc
and README table.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0b09e50a-a9be-4bae-b347-d42dc775a258
@vsonims
vsonims force-pushed the sd/restore-remote-backup branch from ce8c882 to 2b03645 Compare July 20, 2026 18:35
@vsonims
vsonims added this pull request to the merge queue Jul 20, 2026
Merged via the queue into main with commit c34e5cc Jul 20, 2026
29 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.

3 participants