fix(backend): the realtime transport is wss-only; the RPM requires the CA #4

Merged
troed merged 2 commits from feat/fleet-tls-piece-4-sailfish into main 2026-10-14 20:38:06 +02:00
Owner

fix(backend): the realtime transport is wss-only; the RPM requires the CA

Piece 4 (final piece) of the fleet TLS-only transport design —
docs/superpowers/specs/2026-10-14-fleet-tls-only-design.md (root repo). The
plan this implements:
docs/superpowers/plans/2026-10-14-fleet-tls-piece-4-sailfish-enforcement.md.

The defect (shared by three repos)

TLS material was optional and its absence silently degraded the realtime
transport to plaintext ws://. In this repo, qml/py/backend.py resolved a CA
as argument → STARFLEET_CA_BUNDLE → qml/py/starfleet-ca.pem, and when all
three missed it set ssl=None and dialled ws://. On 2026-10-14 that failure
mode cost a debugging session: the attached ESP32 died at the WebSocket upgrade
because the server served wss:// while the client spoke plaintext, and a
plaintext upgrade into a TLS listener is closed with zero bytes.

What changes

The client is wss-only (qml/py/backend.py). The CA is resolved once, before
any connection attempt. A CA that resolves to nothing is a hard connect error
naming STARFLEET_CA_BUNDLE; a CA that is unreadable or unloadable still aborts
exactly as before. scheme is deleted — the URL is now a wss:// literal and
ssl_ctx is always a real SSLContext by the time the loop runs, so there is no
branch left that can produce ws:// or ssl=None, including on the automatic
reconnect.

A blank error is now an error (_describe_connect_error). Pointing this
client at a plaintext server raises ConnectionResetError() with no arguments,
whose str() is empty — the UI would have shown a silent failure. The message
falls back to the exception's type name.

The test suite stops relying on the plaintext default. One module-scoped
autouse fixture gives every backend test a single ephemeral throwaway CA minted
with openssl, and the real-server fixtures now serve TLS from a leaf signed by
it — the design's "ephemeral, in-test self-signed certificate", never the shared
dev set. The test asserting the old plaintext behaviour was inverted, not
deleted
. Two tests were added for the cases the design's invariant implies:
a plaintext server with a CA configured, and a CA path that is a directory.

The package step requires the CA (src/src.pro). The install was
exists()-guarded, so an RPM built without qml/py/starfleet-ca.pem shipped an
app that aborts on first connect. A missing CA is now a qmake error() naming
the path. tests/test_packaging.py pins that structurally, because qmake and the
Sailfish SDK are not runnable on the host — it is a complement to the SDK build,
never the enforcement.

Dev runs use the shared dev set, either via STARFLEET_CA_BUNDLE=$HOME/dev/starfleet/.dev-trust/ca.pem
or by copying it to qml/py/starfleet-ca.pem before packaging (the dev set's
server.pem/server.key are what the computer server serves).

Verification

cd communicator-sailfish
/tmp/opencode/sailfish-venv/bin/python -m pytest tests/ -q -p no:cacheprovider
# 39 passed   (35 before this branch; 30 is the stale number in AGENTS.md)

openssl is now needed by most of the suite (it was already needed by the two
handshake tests); AGENTS.md says so.

Whole-branch review by a fresh reviewer: no Critical, no Important; it
re-ran the changed tests against the pre-change tree in a throwaway copy and
confirmed the Review Focus tests genuinely go red on regression. Four Minor
findings were deferred, not fixed (see the PR discussion / the executor ledger).

Notes

  • The design's ordering is complete with this PR: generator (piece 1, esp32) →
    esp32 enforcement (#17) → computer enforcement (#19/#20) → sailfish.
  • qml/py/starfleet-ca.pem stays gitignored and is never committed.
  • This PR is opened against main — this repo has no devel.
# fix(backend): the realtime transport is wss-only; the RPM requires the CA Piece 4 (final piece) of the fleet TLS-only transport design — `docs/superpowers/specs/2026-10-14-fleet-tls-only-design.md` (root repo). The plan this implements: `docs/superpowers/plans/2026-10-14-fleet-tls-piece-4-sailfish-enforcement.md`. ## The defect (shared by three repos) TLS material was *optional* and its absence silently degraded the realtime transport to plaintext `ws://`. In this repo, `qml/py/backend.py` resolved a CA as argument → `STARFLEET_CA_BUNDLE` → `qml/py/starfleet-ca.pem`, and when all three missed it set `ssl=None` and dialled `ws://`. On 2026-10-14 that failure mode cost a debugging session: the attached ESP32 died at the WebSocket upgrade because the server served `wss://` while the client spoke plaintext, and a plaintext upgrade into a TLS listener is closed with zero bytes. ## What changes **The client is wss-only** (`qml/py/backend.py`). The CA is resolved once, before any connection attempt. A CA that resolves to nothing is a hard connect error naming `STARFLEET_CA_BUNDLE`; a CA that is unreadable or unloadable still aborts exactly as before. `scheme` is deleted — the URL is now a `wss://` literal and `ssl_ctx` is always a real `SSLContext` by the time the loop runs, so there is no branch left that can produce `ws://` or `ssl=None`, including on the automatic reconnect. **A blank error is now an error** (`_describe_connect_error`). Pointing this client at a plaintext server raises `ConnectionResetError()` with no arguments, whose `str()` is empty — the UI would have shown a *silent* failure. The message falls back to the exception's type name. **The test suite stops relying on the plaintext default.** One module-scoped autouse fixture gives every backend test a single ephemeral throwaway CA minted with `openssl`, and the real-server fixtures now serve TLS from a leaf signed by it — the design's "ephemeral, in-test self-signed certificate", never the shared dev set. The test asserting the old plaintext behaviour was **inverted, not deleted**. Two tests were added for the cases the design's invariant implies: a plaintext server with a CA configured, and a CA path that is a directory. **The package step requires the CA** (`src/src.pro`). The install was `exists()`-guarded, so an RPM built without `qml/py/starfleet-ca.pem` shipped an app that aborts on first connect. A missing CA is now a qmake `error()` naming the path. `tests/test_packaging.py` pins that structurally, because qmake and the Sailfish SDK are not runnable on the host — it is a complement to the SDK build, never the enforcement. Dev runs use the shared dev set, either via `STARFLEET_CA_BUNDLE=$HOME/dev/starfleet/.dev-trust/ca.pem` or by copying it to `qml/py/starfleet-ca.pem` before packaging (the dev set's `server.pem`/`server.key` are what the `computer` server serves). ## Verification ```bash cd communicator-sailfish /tmp/opencode/sailfish-venv/bin/python -m pytest tests/ -q -p no:cacheprovider # 39 passed (35 before this branch; 30 is the stale number in AGENTS.md) ``` `openssl` is now needed by most of the suite (it was already needed by the two handshake tests); `AGENTS.md` says so. Whole-branch review by a fresh reviewer: **no Critical, no Important**; it re-ran the changed tests against the pre-change tree in a throwaway copy and confirmed the Review Focus tests genuinely go red on regression. Four Minor findings were deferred, not fixed (see the PR discussion / the executor ledger). ## Notes - The design's ordering is complete with this PR: generator (piece 1, esp32) → esp32 enforcement (#17) → `computer` enforcement (#19/#20) → sailfish. - `qml/py/starfleet-ca.pem` stays gitignored and is never committed. - This PR is opened against `main` — this repo has no `devel`.
troed merged commit 35f2ed15e2 into main 2026-10-14 20:38:06 +02:00
troed deleted branch feat/fleet-tls-piece-4-sailfish 2026-10-14 20:38:07 +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-sailfish!4
No description provided.