fix(tools): trust-tool review minors (no silent re-key, unique staging, stricter fences) #19

Merged
troed merged 1 commit from fix/trust-tool-review-minors into devel 2026-10-14 20:37:41 +02:00
Owner

fix(tools): trust-tool review minors (no silent re-key, unique staging, stricter fences)

The communicator-esp32 half of the deferred review minors recorded in the
fleet TLS-only handover (HANDOVER.md §3.5). All of these were triaged "ship,
not blocking" during pieces 1 and 2; this addresses the six that live in the
fleet trust authority and its fences.

What changes

A complete set is never silently re-keyed (the most serious of the set).
ensure treated a set whose MANIFEST could not be parsed as "no set" and
regenerated it. Regenerating changes the CA a flashed device has pinned, so a
corrupt MANIFEST would have quietly bricked the fleet's trust relationship. It
now returns unreadable — exit 2, printing the --regenerate remedy — and only
an explicit --regenerate re-keys. header --allow-dev has the same hole fixed
differently: it no longer consults the MANIFEST at all, because rendering a
header needs presence and the leaf is what decides whether a SAN is covered.

ensure's refusals print a remedy naming --regenerate, as header's
already did. Previously a refusal was a bare TRUST: refused with no next step.

Concurrent ensure runs cannot collide. Staging used fixed siblings
(.dev-trust.tmp, .dev-trust.old), so two builds sharing a trust directory
would delete each other's half-written material. Staging names now carry the pid
and a random suffix.

SAN parsing is anchored and shared. _SAN_LABEL was unanchored, so a label
occurring inside a value was eaten (a URI SAN https://host/DNS:x lost
/DNS:x). Parsing is now a pure san_values() — unit-testable without openssl —
and missing_sans() replaces the try/except that _cmd_header had duplicated
from covers().

Two fences are harder to fool. The placeholder's prose no longer spells out
the markers it lacks, so a checker that greps for a marker without its
#define prefix cannot be satisfied by the file's own comment. And the invariant
fence now verifies that a header claiming presence really carries a PEM CA and a
32-byte public key, instead of inferring "placeholder" from the bare string
#error.

Verification

cd communicator-esp32/host/tests && python3 -m pytest -q
# 169 passed   (158 before this branch; 11 tests added, 8 of them watched fail first)

Not in this PR

Four items from the same §3.5 list remain, deliberately:

  • the firmware has no runtime provenance log for OTA_TRUST_IS_DEV — this needs a
    main/ C change and a real idf.py build to verify;
  • the invariant tests remain static fences (there is no C unit harness) — a
    genuine rework, not a fix;
  • the release dev-refusal is still a marker grep — widening it to compare the
    embedded material against tools/ota-keys/ needs shell-level verification the
    host suite cannot give;
  • the dev banner stays message(STATUS): main/CMakeLists.txt documents that
    idf.py does not surface WARNING from a component's CMakeLists, so "make it a
    warning" would make it invisible. No change is the correct answer here.
# fix(tools): trust-tool review minors (no silent re-key, unique staging, stricter fences) The `communicator-esp32` half of the deferred review minors recorded in the fleet TLS-only handover (`HANDOVER.md` §3.5). All of these were triaged "ship, not blocking" during pieces 1 and 2; this addresses the six that live in the fleet trust authority and its fences. ## What changes **A complete set is never silently re-keyed** (the most serious of the set). `ensure` treated a set whose `MANIFEST` could not be parsed as "no set" and regenerated it. Regenerating changes the CA a flashed device has pinned, so a corrupt MANIFEST would have quietly bricked the fleet's trust relationship. It now returns `unreadable` — exit 2, printing the `--regenerate` remedy — and only an explicit `--regenerate` re-keys. `header --allow-dev` has the same hole fixed differently: it no longer consults the MANIFEST at all, because rendering a header needs presence and the *leaf* is what decides whether a SAN is covered. **`ensure`'s refusals print a remedy** naming `--regenerate`, as `header`'s already did. Previously a refusal was a bare `TRUST: refused` with no next step. **Concurrent `ensure` runs cannot collide.** Staging used fixed siblings (`.dev-trust.tmp`, `.dev-trust.old`), so two builds sharing a trust directory would delete each other's half-written material. Staging names now carry the pid and a random suffix. **SAN parsing is anchored and shared.** `_SAN_LABEL` was unanchored, so a label occurring *inside* a value was eaten (a URI SAN `https://host/DNS:x` lost `/DNS:x`). Parsing is now a pure `san_values()` — unit-testable without openssl — and `missing_sans()` replaces the `try/except` that `_cmd_header` had duplicated from `covers()`. **Two fences are harder to fool.** The placeholder's prose no longer spells out the markers it lacks, so a checker that greps for a marker *without* its `#define` prefix cannot be satisfied by the file's own comment. And the invariant fence now verifies that a header claiming presence really carries a PEM CA and a 32-byte public key, instead of inferring "placeholder" from the bare string `#error`. ## Verification ```bash cd communicator-esp32/host/tests && python3 -m pytest -q # 169 passed (158 before this branch; 11 tests added, 8 of them watched fail first) ``` ## Not in this PR Four items from the same §3.5 list remain, deliberately: - the firmware has no runtime provenance log for `OTA_TRUST_IS_DEV` — this needs a `main/` C change and a real `idf.py` build to verify; - the invariant tests remain static fences (there is no C unit harness) — a genuine rework, not a fix; - the release dev-refusal is still a marker grep — widening it to compare the embedded material against `tools/ota-keys/` needs shell-level verification the host suite cannot give; - the dev banner stays `message(STATUS)`: `main/CMakeLists.txt` documents that idf.py does not surface `WARNING` from a component's CMakeLists, so "make it a warning" would make it *invisible*. No change is the correct answer here.
Review minors from pieces 1 and 2 of the fleet TLS work.

- `ensure` returns `unreadable` (exit 2, with the `--regenerate` remedy) for a set
  that is present and complete but whose MANIFEST cannot be read. It used to treat
  that as "no set" and regenerate -- silently changing the CA a flashed device has
  pinned. `header --allow-dev` no longer consults the MANIFEST at all: it needs
  only presence, and the leaf itself is what covers a SAN.
- `ensure`'s refusals now print the `--regenerate` remedy, as `header`'s did.
- `generate` stages in unique sibling directories (`<dir>.tmp.<pid>.<rand>`), so
  two concurrent runs can no longer delete each other's material mid-write.
- `_SAN_LABEL` is anchored, and SAN parsing is a pure `san_values()`; a new
  `missing_sans()` replaces the try/except `_cmd_header` duplicated from `covers()`.
- the placeholder's prose no longer spells out the markers it lacks, so a checker
  greping for a marker without its `#define` prefix is not satisfied by the comment.
- the invariant fence checks that a header claiming presence really carries a PEM CA
  and a 32-byte key, instead of keying "placeholder" off the bare string `#error`.

Verified: host suite 169 passed (158 before this branch; 11 tests added).
troed merged commit 0ee0748c8e into devel 2026-10-14 20:37:41 +02:00
troed deleted branch fix/trust-tool-review-minors 2026-10-14 20:37:41 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starfleet/communicator-esp32!19
No description provided.