Skip to content

Reuse std.crypto.tls; remove duplicated TLS plumbing#27

Merged
endel merged 2 commits into
mainfrom
refactor/dedupe-tls-stdlib
May 18, 2026
Merged

Reuse std.crypto.tls; remove duplicated TLS plumbing#27
endel merged 2 commits into
mainfrom
refactor/dedupe-tls-stdlib

Conversation

@endel
Copy link
Copy Markdown
Owner

@endel endel commented May 18, 2026

Summary

QUIC borrows only the TLS 1.3 handshake (carried in CRYPTO frames, RFC 9001), but several handshake primitives and protocol constants were hand-rolled despite std.crypto.tls already defining them authoritatively. This branch removes that duplication across both TLS paths (QUIC + legacy HTTP/1) with no behavior change.

Commits

Commit Change
7511f88 Delegate hkdfExpandLabel/empty-hash/Finished-HMAC to std.crypto.tls; collapse the duplicate hkdf wrappers and deriveHpKeyPaddedV (~80 lines)
ac209ed QUIC TLS constants → std.crypto.tls enums directly; cert-verify switches on typed SignatureScheme; negotiated_group typed as NamedGroup
5f76908 RFC 9001 §4.8 CRYPTO_ERROR mapping → tls.Alert.Description (magic alert codes gone)
3f8cdc0 Legacy http1/tls.zigstd.crypto.tls enums + tls.Alert; dropped 4 dead constants
ed6775d readU16/writeU16std.mem.readInt/writeInt (was reinvented bit-math, duplicated across both files)

What was deliberately not done

  • tls.Decoder for handshake parsing — abstraction is shaped for the std client's record-fill loop; would churn ~94 sites of already-bounds-checked, fuzz-tested parsing for cosmetic gain.
  • make* crypto-context family — the layering is idiomatic Zig default-arg simulation; the only real dup is ~10 lines over two intentionally-distinct structs.
  • Unifying the tls13.zig / http1/tls.zig handshake message codec — the two-file split is correct (record layer vs. CRYPTO frames genuinely differ; crypto core is already shared). Message-codec consolidation is a separate scoped project (needs http1 test coverage + builder parameterization first), not a tidy-up.

No second source of truth for any TLS protocol value remains in either TLS path.

Verification

  • zig build test --summary all: 522/522 at every commit
  • zig build: client/server binaries clean

🤖 Generated with Claude Code

endel added 2 commits May 18, 2026 10:04
RFC 9218 §4.2 default is non-incremental (sequential). Flip the
SendStream default and have WebTransport bidi/uni opens explicitly
set incremental=true, since WT streams have no defined inter-stream
ordering and round-robin interleaving matches the quicperf path.

Browser demo: allow empty cert hash to rely on CA trust, and use
datagrams.createWritable() fallback for the Safari 26.4 API change.

Assisted-by: Claude Opus 4.7
QUIC borrows only the TLS 1.3 handshake (carried in CRYPTO frames,
RFC 9001), but several handshake primitives and protocol constants
were hand-rolled despite std.crypto.tls already defining them
authoritatively. Remove that duplication across both TLS paths
(QUIC + legacy HTTP/1) with no behavior change.

- hkdfExpandLabel / empty-transcript-hash / Finished HMAC now
  delegate to std.crypto.tls; the two duplicate hkdf wrappers and
  deriveHpKeyPaddedV are collapsed (~80 lines).
- QUIC TLS constants reference std.crypto.tls enums directly;
  verifyCertificateVerifySignature switches on a typed
  SignatureScheme; negotiated_group is typed NamedGroup.
- RFC 9001 §4.8 CRYPTO_ERROR mapping uses tls.Alert.Description
  instead of magic alert-code integers.
- Legacy http1/tls.zig uses std.crypto.tls enums + tls.Alert;
  4 dead constants dropped.
- readU16/writeU16 delegate to std.mem.readInt/writeInt (was
  reinvented bit-math duplicated across both files).

Deliberately not done: tls.Decoder rewrite (abstraction shaped
for std client's record loop; ~94 sites of already-bounds-checked
fuzz-tested parsing), make* context family (idiomatic Zig
default-arg layering), and unifying the tls13.zig/http1 handshake
message codec (the record-layer vs CRYPTO-frame split is correct;
codec consolidation is a separate scoped project needing http1
test coverage first).

No second source of truth for any TLS protocol value remains in
either path. Tests 522/522, client/server build clean.

Assisted-by: Claude Opus 4.7
@endel endel force-pushed the refactor/dedupe-tls-stdlib branch from ed6775d to 386b73e Compare May 18, 2026 17:10
@endel endel merged commit 4dc13f7 into main May 18, 2026
2 checks passed
@endel endel deleted the refactor/dedupe-tls-stdlib branch May 18, 2026 17:38
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