Skip to content

P32: in-binary TLS — sc+https:// via rustls (crates/tlsio) - #42

Merged
tonibergholm merged 14 commits into
mainfrom
p32-tls
Jul 10, 2026
Merged

tonibergholm merged 14 commits into
mainfrom
p32-tls

Conversation

@tonibergholm

Copy link
Copy Markdown
Member

Closes #39 (audit High #1 — plaintext bearer tokens + repo traffic on sc+http://). Part of the #24 audit-response map. Decisions locked in #26/#35; research in docs/research/tls-options-sc-http.md; ADR-0042.

What ships

  • New quarantine crate crates/tlsio (scl-tlsio) — the only crate linking rustls (0.23, ring provider, default-features = false), rcgen, ring, rustls-pki-types. Dependency leaf; only repo depends on it. Blocking Read+Write TLS streams with split halves, a hand-written pin-only TOFU ServerCertVerifier (handshake signatures still verified — pinned-cert replay MITM rejected), self-signed cert mint/load, SPKI-SHA-256 fingerprints (sha256:<hex>, openssl-verifiable).
  • Client: sc+https://host[:port]/repo (default port 8730) on clone/fetch/push/remote add. Accept-new TOFU: first connect pins into ~/.config/sc/known_hosts and announces loudly; mismatch always hard-fails naming the file, both fingerprints, and the recovery. SC_HTTPS_FINGERPRINT pre-pins (never persisted), SC_HTTPS_STRICT=1 refuses unknown hosts (fail-closed parse), SC_HTTPS_KNOWN_HOSTS overrides the path. No application byte crosses before pin disposition is settled.
  • Server: sc serve --http <addr> <path> --tls [--tls-cert <pem> --tls-key <pem>] — auto-mints a long-validity identity into .sc/serve-tls/ (key 0600; the key IS the identity), banner prints the fingerprint; new sc serve fingerprint [<path>] (mints if missing). The 30s opening timeout also bounds the TLS handshake; P31 session timeouts work through the TLS halves.
  • Gate tightening (deliberate pre-1.0 break, decision 5): a non-loopback bind is allowed iff --read-only, --allow-public, or --tls + ≥1 serve token. Plaintext + tokens-only is now refused (error names --tls); a justified plaintext public bind with tokens configured warns that tokens cross in cleartext.
  • Unchanged: PROTOCOL_VERSION stays 3; opening codec, serve_tokens, and all of wire.rs byte-for-byte; existing sc+http:// remotes keep working.
  • Docs: ADR-0042 (dep rationale ring vs aws-lc-rs, TOFU trust model, quarantine); THREAT-MODEL transport rewrite documenting BOTH reverse-proxy legs + residual plaintext-token paths; CLAUDE.md/ROADMAP.

Deviations from the phase spec (recorded in ADR-0042)

  • Under TLS the --max-connections busy-shed closes silently instead of sending a 503 — a readable 503 would require a TLS handshake on the accept thread, breaking P31's accepts-never-block property (spec §3 amended).

Proof

  • demo/run_tls_demo.sh — TLS round trip with a signed ~1 MiB blob under SC_PACK_CHUNK=4096, full TOFU lifecycle (pin/quiet/mismatch/strict/pre-pin), tightened gate, zero .sc/tmp residue, run twice.
  • crates/cli/tests/https_remote.rs — clone + push + fetch acceptance over sc+https://, byte-for-byte, key-swap mismatch hard-fail.
  • 670 workspace tests green, clippy -D warnings clean, all prior demos green (run_http_auth_demo.sh extended to prove the gate narrowing).
  • Nine per-task reviews + a final whole-branch review (verdict: ready to merge; its three Important findings fixed and re-verified in the fix-wave commit).

https://claude.ai/code/session_01LhadyW9scQL95h3ag9yySB

… tokens justify only with --tls (P32 gate)

bind_is_allowed gains a `tls: bool` parameter and tightens the lattice:
non-loopback is allowed iff --read-only, --allow-public, or (tls &&
>=1 configured serve token). A configured token no longer justifies a
PLAINTEXT public bind (the P29 rule) since the token itself would then
cross the wire in the clear -- deliberate, narrow pre-1.0 break (decision
5 of issue #39 / ADR-0042). auth_is_mandatory is unchanged; its doc
comment now notes the TLS+tokens case rides the same fail-closed rule.
serve_http's refusal message names --tls as the third justification.
… rewrite, roadmap

Documents the P32 in-binary TLS phase (sc+https://, crates/tlsio, accept-new
TOFU pinning, the tightened non-loopback bind gate) closing ADR-0036's "no
TLS" boundary and the audit's High #1: ADR-0042, CLAUDE.md's workspace
layout/dependency rule/commands/Phase 32 section/forward-reference updates,
a rewritten THREAT-MODEL transport section covering both confidential
transports and both reverse-proxy legs, ROADMAP's shipped-in-P32 entry and
follow-ons, and the P32 spec's busy-shed amendment. Extends
demo/run_http_auth_demo.sh with a step proving the P29→P32 gate narrowing
(tokens alone no longer justify a plaintext public bind; --tls + a token
does).
Closes the P32 final whole-branch review's findings: stale CLAUDE.md gate
text (I1), SC_HTTPS_STRICT failing open on unrecognized values (I2), the
THREAT-MODEL + serve-startup warning for residual plaintext-token exposure
on --read-only/--allow-public public binds (I3), missing test asserts in
scl-tlsio (T1), enforcement-implying doc-comment wording in the CLI (T7),
missing P31/P32 ROADMAP rows (T9), and four named P32 follow-ons recorded
in ROADMAP Deferred (Recommendation 2).
@tonibergholm
tonibergholm merged commit aa73a3e into main Jul 10, 2026
6 checks passed
@tonibergholm
tonibergholm deleted the p32-tls branch July 10, 2026 15:01
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.

P32: in-binary TLS — sc+https:// via rustls (crates/tlsio)

1 participant