Skip to content

feat(tbor): implement KeyReport command (attest a masked key)#537

Open
vsonims wants to merge 6 commits into
mainfrom
sd/key-report
Open

feat(tbor): implement KeyReport command (attest a masked key)#537
vsonims wants to merge 6 commits into
mainfrom
sd/key-report

Conversation

@vsonims

@vsonims vsonims commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add the TBOR KeyReport command (opcode 0x10): it takes a masked key (as produced by SdSealingKeyGen), unmasks it, derives its public component on-device, and returns a PID-signed COSE_Sign1 key-attestation report over it.

Handler (fw/core/lib/src/ddi/tbor/key_report.rs)

  • Gate: Crypto-Officer-only (InvalidPermissions); session Active; partition Initialized. Reuses SdSealingKeyGen's CO / masking-key gate helpers (now hoisted into the shared tbor module).
  • Unmask the masked blob → derive pub = priv · G via the new HsmEcc::ecc_pub_from_priv PAL method → build + sign the COSE_Sign1 report under the partition identity (PID) key.
  • Only ECC-private kinds are attestable; symmetric, RSA-private, and non-attestable kinds are rejected with the new UnsupportedKeyType error (a symmetric report would carry an empty COSE_Key that conveys no key type).

PAL + crypto

  • New HsmEcc::ecc_pub_from_priv (derive pub from an LE wire scalar) with std (pub_from_priv_le driver + round-trip tests) and Uno (pka.ecc_gen_pub_key) impls.
  • Uses the existing key-masking peek_metadata (scope routing) + unmask, and the key-report COSE builder (both already in main).

Schema + dispatch

  • fw + host KeyReport wire schemas; UnsupportedKeyType (0x08700103) error + TborStatus mirror.
  • Opcode 0x10 wired into the opcode table + the 6 dispatch/classifier sites (0x0A–0x0F are reserved by the SD backup schema family).

Tests + docs

  • emu tests: Ephemeral/Local happy paths (verify the COSE_Sign1 under the PID pubkey and cross-bind the attested key to the sealed pubkey), plus tamper / pre-finalize / CU-session / default-PSK rejects.
  • docs/tbor-ddi/commands/key_report.md.

Stacking

⚠️ Stacked on SdSealingKeyGen (#536) — KeyReport reuses its masking-key gate helpers and consumes its masked-key output. This PR's first commit is the SdSealingKeyGen command (#536); it will drop out once #536 merges, leaving only the KeyReport commit. Review the KeyReport commit in isolation with git show <keyreport-sha>.

Firmware size

Validation

  • Full host workspace + Uno firmware (thumbv7em) builds.
  • tbor-emu: 95/95 (7 KeyReport tests).
  • clippy -D warnings + nightly fmt clean.

Copilot AI review requested due to automatic review settings July 11, 2026 15:47

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

Adds TBOR support for attesting masked keys via a new KeyReport command, including firmware handlers, PAL ECC support to derive public keys from private scalars, and host-side schemas/tests/docs to exercise and document the new opcodes.

Changes:

  • Implement TBOR SdSealingKeyGen (0x09) and KeyReport (0x10) firmware handlers and wire them into TBOR dispatch/session classification.
  • Extend ECC PAL with ecc_pub_from_priv (std + uno) and add supporting driver logic + tests.
  • Add/refresh host TBOR schemas, status mirrors, emulator integration tests, and documentation for both commands.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
fw/plat/uno/fw/pal/src/crypto/ecc.rs Adds Uno PAL impl for ecc_pub_from_priv via PKA base-point multiplication.
fw/plat/uno/fw/crates/key_vault/src/kind.rs Adds SdSealing key-kind length entry and updates tests/table sizing.
fw/plat/std/pal/src/ecc.rs Adds Std PAL impl for ecc_pub_from_priv delegating to driver.
fw/plat/std/pal/src/drivers/vault.rs Adds SdSealing size mapping for std vault driver and updates tests.
fw/plat/std/pal/src/drivers/ecc.rs Implements pub_from_priv_le and adds round-trip tests vs generated pubkeys.
fw/pal/traits/src/vault.rs Introduces HsmVaultKeyKind::SdSealing and updates the key-kind category docs.
fw/pal/traits/src/error.rs Adds UnsupportedKeyScope / UnsupportedKeyType error codes.
fw/pal/traits/src/crypto/ecc.rs Extends HsmEcc trait with ecc_pub_from_priv and wire-endianness contract.
fw/core/lib/src/op.rs Marks new TBOR opcodes as in-session for session control.
fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs New firmware handler to generate P-384 sealing keypair and return masked key + pubkey.
fw/core/lib/src/ddi/tbor/mod.rs Adds new TBOR opcodes, shared CO-session gating helpers, and dispatch wiring.
fw/core/lib/src/ddi/tbor/key_report.rs New firmware handler to unmask a key, derive pubkey, and return PID-signed COSE_Sign1 report.
fw/core/ddi/tbor/types/src/sd_sealing_key_gen.rs Defines firmware-side SdSealingKeyGen wire schema + pinned length constants/tests.
fw/core/ddi/tbor/types/src/lib.rs Exposes the new firmware-side key_report module/types.
fw/core/ddi/tbor/types/src/key_report.rs Defines firmware-side KeyReport wire schema + pinned max/len constants/tests.
docs/tbor-ddi/README.md Updates opcode table to include landed SdSealingKeyGen and new KeyReport entry.
docs/tbor-ddi/commands/sd_sealing_key_gen.md Updates SdSealingKeyGen documentation to reflect masked-key + pubkey response.
docs/tbor-ddi/commands/key_report.md Adds new KeyReport command documentation (request/response/errors/flow).
ddi/tbor/types/tests/commands/sd_sealing_key_gen.rs Adds emu integration tests for SdSealingKeyGen happy-path + reject paths.
ddi/tbor/types/tests/commands/mod.rs Registers new SdSealingKeyGen and KeyReport test modules.
ddi/tbor/types/tests/commands/key_report.rs Adds emu integration tests verifying KeyReport COSE_Sign1 and binding to sealed pubkey.
ddi/tbor/types/src/status.rs Adds host TborStatus mirrors for new error codes.
ddi/tbor/types/src/sd_sealing_key_gen.rs Updates host wrapper to return masked key + pubkey (no key handle).
ddi/tbor/types/src/lib.rs Exposes the new host-side key_report module/types.
ddi/tbor/types/src/key_report.rs Adds host wrapper types for KeyReport request/response.

Comment thread fw/core/lib/src/ddi/tbor/mod.rs Outdated
Comment thread fw/pal/traits/src/vault.rs Outdated
Comment thread fw/pal/traits/src/vault.rs
Comment thread fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs Outdated
Comment thread fw/core/lib/src/ddi/tbor/key_report.rs Outdated
Comment thread ddi/tbor/types/src/status.rs
Copilot AI review requested due to automatic review settings July 11, 2026 15:53

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 25 out of 25 changed files in this pull request and generated 2 comments.

Comment thread fw/core/lib/src/ddi/tbor/key_report.rs
Comment thread fw/core/lib/src/ddi/tbor/key_report.rs Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 15:58

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 25 out of 25 changed files in this pull request and generated 3 comments.

Comment thread fw/core/lib/src/ddi/tbor/key_report.rs
Comment thread fw/core/lib/src/ddi/tbor/key_report.rs Outdated
Comment thread fw/plat/uno/fw/pal/src/crypto/ecc.rs
Copilot AI review requested due to automatic review settings July 11, 2026 16:09

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 25 out of 25 changed files in this pull request and generated 2 comments.

Comment thread fw/core/lib/src/ddi/tbor/key_report.rs
Comment thread fw/plat/std/pal/src/drivers/ecc.rs
Copilot AI review requested due to automatic review settings July 11, 2026 16:14

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 25 out of 25 changed files in this pull request and generated 1 comment.

Comment thread fw/plat/std/pal/src/drivers/ecc.rs Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 16:19

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 25 out of 25 changed files in this pull request and generated 4 comments.

Comment thread fw/core/lib/src/ddi/tbor/key_report.rs Outdated
Comment thread fw/core/lib/src/ddi/tbor/key_report.rs
Comment thread fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs
Comment thread fw/pal/traits/src/crypto/ecc.rs Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 16:24

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 25 out of 25 changed files in this pull request and generated no new comments.

@vsonims

vsonims commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

# Conflicts:
#	ddi/tbor/types/src/status.rs
#	ddi/tbor/types/tests/commands/sd_sealing_key_gen.rs
#	fw/core/lib/src/ddi/tbor/mod.rs
#	fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs
#	fw/core/lib/src/op.rs
#	fw/pal/traits/src/error.rs

Co-authored-by: vsonims <39780523+vsonims@users.noreply.github.com>

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflicts by merging origin/main into this branch and fixing all conflicted files in commit 4cc00d2b.

Copilot AI review requested due to automatic review settings July 13, 2026 23:21
@vsonims vsonims removed the request for review from Copilot July 13, 2026 23:21
@vsonims vsonims enabled auto-merge July 13, 2026 23:24
@vsonims vsonims marked this pull request as draft July 13, 2026 23:29
auto-merge was automatically disabled July 13, 2026 23:29

Pull request was converted to draft

@vsonims vsonims marked this pull request as ready for review July 13, 2026 23:29
Copilot AI review requested due to automatic review settings July 13, 2026 23:29

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 19 out of 19 changed files in this pull request and generated 1 comment.

Comment thread fw/core/lib/src/ddi/tbor/key_report.rs
Move the kind→curve mapping out of the KeyReport handler into a new
tbor-side from_pal helper (mirrors mbor::from_pal but stays independent
of it), including the SdSealing→P384 case that MBOR's table lacks.

Borrow report_data straight from the request buffer instead of
allocating + copying into scoped scratch; key_report's validate()
already enforces the exact KEY_REPORT_DATA_LEN, so the manual length
check was redundant too.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 13, 2026 23:37
Encode the KeyReport TBOR response header with fips_approved=false, matching
every other TBOR handler (api_rev, part_final, part_init, psk_change,
sd_sealing_key_gen, session_*). KeyReport is not a FIPS-approved operation,
so the previous `true` incorrectly set the header's FIPS flag.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 20 out of 20 changed files in this pull request and generated 2 comments.

Comment thread fw/core/lib/src/ddi/tbor/key_report.rs
Comment thread fw/core/ddi/tbor/types/src/key_report.rs Outdated
Copilot AI review requested due to automatic review settings July 13, 2026 23:42
The response_round_trips_report schema test encoded the KeyReport response
with fips_approved=true; real handlers always encode false, so match that in
the test to avoid baking the wrong header flag into examples.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 20 out of 20 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 13, 2026 23:46
Comment thread ddi/tbor/types/tests/commands/key_report.rs

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 20 out of 20 changed files in this pull request and generated 1 comment.

Comment thread fw/core/lib/src/ddi/tbor/mod.rs
// right masking key before unmasking.
let masked_key = req.masked_key();
let report_data = req.report_data();
let scope = peek_metadata(masked_key)?.usage_flags().scope();

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.

Should you be validating the tag before doing peek metadata?

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.

6 participants