Skip to content

feat: add ELF and MCUboot signing support with format abstraction (Phase 2)#55

Merged
avrabe merged 4 commits intomainfrom
feat/phase2-binary-signing
Mar 17, 2026
Merged

feat: add ELF and MCUboot signing support with format abstraction (Phase 2)#55
avrabe merged 4 commits intomainfrom
feat/phase2-binary-signing

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Mar 17, 2026

Summary

Phase 2 of the STPA-Sec implementation plan — extends sigil beyond WASM to sign ELF binaries and MCUboot firmware images.

New architecture

  • SignableArtifact trait — format-agnostic interface: compute_hash, attach_signature, detach_signature, serialize
  • FormatType enumWasm | Elf | Mcuboot with content type IDs, domain separation, and magic byte detection
  • Polyglot validation (SC-15) — declared format must match file magic bytes, preventing AS-17 format confusion attacks

ELF signing (format/elf.rs)

  • Section header consistency validation with overlap detection (SC-12, UCA-13)
  • Resource bounds: 256 MB max file size, 4096 max sections (UCA-17)
  • Full-file SHA-256 hashing to prevent section/program header divergence (AS-14)
  • Detached signature output (.sig file) — proper ELF section embedding is future work

MCUboot signing (format/mcuboot.rs)

  • Independent image size verification against ih_img_size header (SC-13, UCA-14)
  • Prevents partial-image signature attacks (AS-15)
  • Signature embedded in MCUboot TLV trailer with Ed25519 type
  • 16 MB max image size enforcement

CLI

# Sign an ELF binary (produces output.elf + output.elf.sig)
sigil sign -i firmware.elf -o signed.elf --format elf -k key.sec

# Sign MCUboot firmware (signature in TLV trailer)
sigil sign -i app.bin -o signed.bin --format mcuboot -k key.sec

# WASM remains the default (backwards compatible)
sigil sign -i module.wasm -o signed.wasm -k key.sec

Test plan

  • cargo test — 616 tests pass (26 new format tests)
  • cargo build — clean compilation with #![forbid(unsafe_code)]
  • CI: all checks should pass

🤖 Generated with Claude Code

avrabe and others added 4 commits March 17, 2026 07:43
…ase 2)

Introduce format-agnostic signing architecture and initial support for
ELF binary and MCUboot firmware image signing.

New modules:
- format/mod.rs: FormatType enum, SignableArtifact trait, format detection
  with polyglot file validation (SC-15, AS-17)
- format/elf.rs: ELF parser with section header consistency validation
  (SC-12), overlap detection (UCA-13), resource bounds (UCA-17), and
  full-file hashing (AS-14 defense)
- format/mcuboot.rs: MCUboot parser with independent image size
  verification (SC-13, UCA-14, AS-15)

CLI changes:
- New --format flag on sign and verify subcommands (wasm|elf|mcuboot)
- Format consistency validation (declared vs detected magic bytes)
- ELF signing produces detached .sig file
- MCUboot signing embeds signature in TLV trailer

Architecture:
- SignableArtifact trait: compute_hash, attach_signature, detach_signature,
  serialize, content_bytes — shared interface for all formats
- Domain separation per format: "wasmsig", "elfsig", "mcubootsig"
- Content type IDs: WASM=0x01, ELF=0x02, MCUboot=0x03
- Ed25519 signing core unchanged — format handlers only do parsing/hashing

26 new tests covering format detection, ELF parsing, MCUboot parsing,
resource bounds, and section overlap validation.

Implements: FEAT-2
Refs: SC-12, SC-13, SC-15, UCA-13, UCA-14, UCA-17, AS-14, AS-15, AS-17

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Complete the requirement → design → implementation → verification chain
for ELF and MCUboot signing:

Requirements: CR-12 (ELF section validation), CR-13 (MCUboot size
  verification), CR-14 (explicit format flag), CR-15 (resource bounds),
  CR-16 (domain-separated signing)
Design: CD-13 (SignableArtifact trait), CD-14 (ELF module), CD-15
  (MCUboot module), CD-16 (format detection)
Implementation: CI-1 (format/mod.rs), CI-2 (format/elf.rs),
  CI-3 (format/mcuboot.rs)
Verification: CV-12 (ELF tests), CV-13 (MCUboot tests), CV-14
  (format detection tests), CV-15 (fuzz targets, draft)

Total: 305 artifacts, 95.1% traceability coverage.

Implements: FEAT-2
Refs: SC-12, SC-13, SC-15, CR-12, CR-13, CR-14, CR-15, CR-16

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t CLI

Used rivet add/link/modify CLI commands to:
- Create REQ-11 (ELF and MCUboot E2E test requirement)
- Link REQ-3, REQ-4 to FEAT-2 (resolving orphan warnings)
- Link REQ-11 to FEAT-2

Refs: FEAT-2, REQ-3, REQ-4, REQ-11

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Configure synth as a rivet external and add traces-to links from sigil's
binary signing artifacts to synth's ELF backend and reproducibility
requirements:

  sigil:SC-12 → synth:ARCH-003 (ELF section validation depends on ELF output)
  sigil:H-15  → synth:ARCH-003, synth:NFR-002 (transcoding hazard)
  sigil:L-7   → synth:L-6, synth:ARCH-003 (attestation chain continuity)
  sigil:SC-14 → synth:FR-002, synth:VER-001 (chain maintenance)
  sigil:DF-13 → synth:ARCH-003, synth:NFR-002 (attestation data flow)

Reverse links added in synth repo:
  synth:ARCH-003 → sigil:CR-12, sigil:CD-14, sigil:FEAT-2
  synth:NFR-002  → sigil:L-7, sigil:SC-14

Refs: FEAT-2, SC-12, SC-14, H-15, L-7, DF-13

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit e481f1b into main Mar 17, 2026
12 checks passed
@avrabe avrabe deleted the feat/phase2-binary-signing branch March 17, 2026 18:32
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