fix(review): the last three esp32 TLS-only review minors #20

Merged
troed merged 3 commits from fix/fleet-tls-review-minors-esp32 into devel 2026-10-14 22:32:14 +02:00
Owner

fix(review): the last three esp32 TLS-only review minors

The esp32 half of the deferred review minors in HANDOVER.md §3.5 — the three
that esp32 PR #19 deliberately left behind, each for a stated reason. All three
are addressed here, and the reasons they were deferred are removed rather than
worked around.

A. Runtime provenance for dev trust material

OTA_TRUST_IS_DEV existed in the header but was never referenced by the
firmware
, so a flashed device gave no signal about which CA it pins — the one
thing a field diagnosis of a trust problem needs.

app_main() now logs it at boot:

#if defined(OTA_TRUST_IS_DEV)
    ESP_LOGW(TAG, "trust material: DEV (throwaway CA, no production keys) - do not release this firmware");
#else
    ESP_LOGI(TAG, "trust material: production");
#endif

Verified with two real idf.py builds, since the deferral reason was "needs
a main/ C change and a real idf.py build":

  • Production (tools/ota-keys/ present): configure generates production
    material, main.c.obj compiles, communicator.bin links.
  • Dev (production keys hidden, CONFIG_SERVER_HOST covered by the shared
    dev set): the DEV TRUST MATERIAL banner fires, the header carries
    #define OTA_TRUST_IS_DEV 1, main.c.obj compiles the ESP_LOGW branch,
    and the image links.

Both builds left the tree restored: the tracked main/ota_trust.h is back to the
placeholder and the production keys are back in tools/ota-keys/.

C. The release refusal now compares material, not markers

release_firmware.sh refused dev material with grep -q "#define OTA_TRUST_IS_DEV". A marker grep cannot tell two CAs apart: a stale header
left from another CA would still pass
and ship a fleet that trusts the wrong
root.

The check moves into the trust tool as a real, testable subcommand:

starfleet_trust.py verify-header --header main/ota_trust.h --ca tools/ota-keys/ca.pem

It checks presence (OTA_TRUST_PRESENT), the absence of the dev marker, and
that the header's embedded CA — parsed out of the C string literal and
unescaped — equals --ca. release_firmware.sh calls it against
tools/ota-keys/ca.pem.

The deferral reason was "needs shell-level verification the host suite cannot
give". Moving the logic into Python removes that: the behaviour is now
unit-tested (verify_header, embedded_ca_pem, and the CLI exit codes), and it
was also verified at the shell level — a generated production header passes
(exit 0), a header checked against a different CA exits 1.

B. The invariant fences are no longer greps-on-the-header

host/tests/test_tls_invariant.py's trust-header checks were string-shape
greps. They now compile the header with the C compiler (cc -std=c11 -Wall -Werror) and run a probe against it:

  • the committed header must be the placeholder and must fail to compile
    (the #error), replacing the "either placeholder or real material" shape
    test;
  • a generated production header compiles, defines OTA_TRUST_PRESENT and not
    OTA_TRUST_IS_DEV, and reports a 32-byte key and a non-empty CA;
  • a generated dev header compiles and defines both markers;
  • a header claiming #define OTA_TRUST_PRESENT 1 with no material fails to
    compile
    , because nothing declares the symbols the firmware uses — the exact
    gap the old shape check could not close.

The remaining checks stay static, by necessity rather than by preference:
ws_client.c and main/CMakeLists.txt are ESP-IDF-only and cannot be compiled
by the host suite. They are now documented as what they are — complements to
the idf.py build gate, never replacements for it. One is added for this
change: test_firmware_logs_dev_trust_provenance pins that the firmware
references OTA_TRUST_IS_DEV and logs it.

Review follow-up

Whole-branch review returned no Critical and no Important findings. The worthwhile
Minors were folded in as a follow-up commit: an argparse --help sentinel
regression this branch introduced (adding the fourth subcommand left --help
dumping the whole docstring), embedded_ca_pem hardened against a
commented-out initializer, CRLF normalisation in verify_header, and a stronger
item-A test that requires the guarded #if defined(OTA_TRUST_IS_DEV) form and both
log lines rather than bare substrings.

Verification

cd communicator-esp32/host/tests
python3 -m pytest -q     # 180 passed   (169 before this branch; 11 tests added)
  • py_compile on the changed Python, bash -n on the changed shell clean.
  • added-line hygiene scan (no /home/<user>, no internal IPs) clean.
  • production and dev idf.py build both green; working tree restored.

Not in this PR

The on-hardware dev-trust run (HANDOVER §3.3) remains deferred: it needs the
physical unit on /dev/ttyACM0, a human to hear the reply, and a mandatory
re-flash back to production trust afterwards.

# fix(review): the last three esp32 TLS-only review minors The esp32 half of the deferred review minors in `HANDOVER.md` §3.5 — the three that esp32 PR #19 deliberately left behind, each for a stated reason. All three are addressed here, and the reasons they were deferred are removed rather than worked around. ## A. Runtime provenance for dev trust material `OTA_TRUST_IS_DEV` existed in the header but was **never referenced by the firmware**, so a flashed device gave no signal about which CA it pins — the one thing a field diagnosis of a trust problem needs. `app_main()` now logs it at boot: ```c #if defined(OTA_TRUST_IS_DEV) ESP_LOGW(TAG, "trust material: DEV (throwaway CA, no production keys) - do not release this firmware"); #else ESP_LOGI(TAG, "trust material: production"); #endif ``` **Verified with two real `idf.py` builds**, since the deferral reason was "needs a `main/` C change and a real `idf.py` build": - **Production** (`tools/ota-keys/` present): configure generates production material, `main.c.obj` compiles, `communicator.bin` links. - **Dev** (production keys hidden, `CONFIG_SERVER_HOST` covered by the shared dev set): the `DEV TRUST MATERIAL` banner fires, the header carries `#define OTA_TRUST_IS_DEV 1`, `main.c.obj` compiles the `ESP_LOGW` branch, and the image links. Both builds left the tree restored: the tracked `main/ota_trust.h` is back to the placeholder and the production keys are back in `tools/ota-keys/`. ## C. The release refusal now compares material, not markers `release_firmware.sh` refused dev material with `grep -q "#define OTA_TRUST_IS_DEV"`. A marker grep cannot tell two CAs apart: a **stale header left from another CA would still pass** and ship a fleet that trusts the wrong root. The check moves into the trust tool as a real, testable subcommand: ``` starfleet_trust.py verify-header --header main/ota_trust.h --ca tools/ota-keys/ca.pem ``` It checks presence (`OTA_TRUST_PRESENT`), the absence of the dev marker, and that the header's embedded CA — parsed out of the C string literal and unescaped — equals `--ca`. `release_firmware.sh` calls it against `tools/ota-keys/ca.pem`. The deferral reason was "needs shell-level verification the host suite cannot give". Moving the logic into Python removes that: the behaviour is now unit-tested (`verify_header`, `embedded_ca_pem`, and the CLI exit codes), and it was **also** verified at the shell level — a generated production header passes (exit 0), a header checked against a different CA exits 1. ## B. The invariant fences are no longer greps-on-the-header `host/tests/test_tls_invariant.py`'s trust-header checks were string-shape greps. They now **compile the header with the C compiler** (`cc -std=c11 -Wall -Werror`) and run a probe against it: - the committed header must be the placeholder **and must fail to compile** (the `#error`), replacing the "either placeholder or real material" shape test; - a generated production header compiles, defines `OTA_TRUST_PRESENT` and not `OTA_TRUST_IS_DEV`, and reports a 32-byte key and a non-empty CA; - a generated dev header compiles and defines both markers; - a header claiming `#define OTA_TRUST_PRESENT 1` **with no material fails to compile**, because nothing declares the symbols the firmware uses — the exact gap the old shape check could not close. The remaining checks stay static, by necessity rather than by preference: `ws_client.c` and `main/CMakeLists.txt` are ESP-IDF-only and cannot be compiled by the host suite. They are now documented as what they are — complements to the `idf.py` build gate, never replacements for it. One is added for this change: `test_firmware_logs_dev_trust_provenance` pins that the firmware references `OTA_TRUST_IS_DEV` and logs it. ## Review follow-up Whole-branch review returned no Critical and no Important findings. The worthwhile Minors were folded in as a follow-up commit: an argparse `--help` sentinel regression this branch introduced (adding the fourth subcommand left `--help` dumping the whole docstring), `embedded_ca_pem` hardened against a commented-out initializer, CRLF normalisation in `verify_header`, and a stronger item-A test that requires the guarded `#if defined(OTA_TRUST_IS_DEV)` form and both log lines rather than bare substrings. ## Verification ```bash cd communicator-esp32/host/tests python3 -m pytest -q # 180 passed (169 before this branch; 11 tests added) ``` - `py_compile` on the changed Python, `bash -n` on the changed shell clean. - added-line hygiene scan (no `/home/<user>`, no internal IPs) clean. - production and dev `idf.py build` both green; working tree restored. ## Not in this PR The on-hardware dev-trust run (HANDOVER §3.3) remains deferred: it needs the physical unit on `/dev/ttyACM0`, a human to hear the reply, and a mandatory re-flash back to production trust afterwards.
The esp32 half of HANDOVER §3.5 that PR #19 deliberately left: the runtime
dev-trust provenance log, the grep-shaped invariant fences, and the narrow
release dev-refusal.

Runtime provenance (A). OTA_TRUST_IS_DEV was never referenced by the firmware,
so a flashed device gave no signal about which CA it pins. app_main() now logs
it: ESP_LOGW "trust material: DEV ..." when the header is dev-marked,
ESP_LOGI "trust material: production" otherwise. Verified with two real idf.py
builds -- production (tools/ota-keys/ present) and dev (keys hidden, dev set
generated, DEV TRUST MATERIAL banner) -- both compile main.c.

Release refusal widened (C). release_firmware.sh refused dev material with a
marker grep, which cannot tell two CAs apart: a stale header left from another
CA would still pass. The check moves into starfleet_trust.py as the testable
`verify-header` subcommand (presence, no dev marker, and the embedded CA must
equal --ca), and the script calls it against tools/ota-keys/ca.pem. Verified at
the shell level: a generated production header passes, a wrong CA exits 1.

Invariant fences reworked (B). test_tls_invariant.py's trust-header checks were
string-shape greps. They now compile the header with the C compiler
(cc -std=c11 -Wall -Werror) and run a probe: the committed placeholder must fail
to compile, a generated production/dev header must compile and report the right
markers plus a 32-byte key and a non-empty CA, and a header claiming
OTA_TRUST_PRESENT with no material must fail to compile. The remaining checks
stay static by necessity -- ws_client.c and the CMakeLists are ESP-IDF-only --
and are documented as complements, never replacements, for the idf.py build gate.

Verification: esp32 host suite 169 -> 177 passed (8 tests added); py_compile and
the added-line hygiene scan clean; both idf.py builds green.
Whole-branch review found no Critical and no Important items; these are the
worthwhile Minors, one of which was a regression this branch introduced.

- The argparse description sentinel still said "Three subcommands:", so after
  adding a fourth `--help` dumped the whole module docstring. It now splits on
  "Four subcommands:", and a test pins the short description.
- `embedded_ca_pem` now runs over comment-stripped text and anchors the
  initializer to a line start, so a commented-out `ota_trust_ca_pem[]` cannot
  satisfy it (defence in depth: the release path regenerates the header first).
- `verify_header` normalises CRLF in the expected CA file, so a Windows-saved
  `ca.pem` is not falsely refused.
- `test_firmware_logs_dev_trust_provenance` asserts the guarded form and both
  log lines, so naming the macro in a comment can no longer pass it.

180 passed (177 before); py_compile clean.
troed merged commit 25c961e006 into devel 2026-10-14 22:32:14 +02:00
troed deleted branch fix/fleet-tls-review-minors-esp32 2026-10-14 22:32:14 +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!20
No description provided.