Skip to content

SFT-7497: input validation in the firmware header path - #63

Closed
Jacksper13 wants to merge 1 commit into
mainfrom
fix/firmware-header-fail-closed
Closed

Jacksper13 wants to merge 1 commit into
mainfrom
fix/firmware-header-fail-closed

Conversation

@Jacksper13

@Jacksper13 Jacksper13 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Tightens input handling in foundation-firmware so malformed local input produces an error rather than an unwind.

  • The public key index bound is derived from the key array as a strict upper bound, and MAX_PUBLIC_KEYS's doc now says what it is — the number of keys, so a valid index is strictly less than it.
  • public_key1() and public_key2() return Option<PublicKey> through a single checked lookup.
  • verify_signature() verifies the header and returns VerifySignatureError::InvalidHeader rather than asserting on it.
  • The CLI checks the file is at least HEADER_LEN bytes before slicing it.

Nothing that verified successfully before changes.

Downstream

VerifySignatureError gains a variant. passport2's extmod/foundation-rust/src/firmware.rs matches on it exhaustively, so bumping this dependency there needs an arm for InvalidHeader — mapping it to whatever FirmwareResult the header errors already use.

public_key1() / public_key2() change return type. Nothing outside this crate calls them today.

Tests

In firmware/tests/test-vectors.rs, built by mutating the parsed VALID_HEADER rather than adding fixtures: boundary and extreme indexes for both key fields, every in-range index, a user-signed header, and empty and truncated input.

SFT-7497

@Jacksper13 Jacksper13 changed the title SFT-7497: reject out of range key indexes and short files instead of panicking SFT-7497: input validation in the firmware header path Sep 29, 2026
Tighten input handling so malformed local input produces an error rather
than an unwind.

MAX_PUBLIC_KEYS is the number of Foundation keys, so derive the index
bound from the array as a strict upper bound and say so in its doc. Make
the lookups return Option through a single checked helper.
verify_signature() now verifies the header and returns
VerifySignatureError::InvalidHeader rather than asserting on it, and maps
a None lookup onto the matching index error.

The CLI checks the file is at least HEADER_LEN bytes before slicing it.

Nothing that verified successfully before changes.

Note for downstream: VerifySignatureError gains a variant, and
public_key1()/public_key2() return Option.
@Jacksper13
Jacksper13 force-pushed the fix/firmware-header-fail-closed branch from ddb842e to 8f6a19c Compare September 29, 2026 12:52
@Jacksper13

Jacksper13 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Closed in favour of a clean branch.

@Jacksper13 Jacksper13 closed this Sep 29, 2026
@Jacksper13
Jacksper13 deleted the fix/firmware-header-fail-closed branch September 29, 2026 13:22
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.

1 participant