Repository navigation
Net: an RFC 6455 WebSocket codec, sans-IO, for Open Watch Party - #1273
Conversation
The WebSocket upgrade proves the server read the client's key with Sec-WebSocket-Accept, the base64 of SHA-1 over the key and the RFC 6455 GUID. The crate has no hashing dependency, so SHA-1 is written out next to sha256.rs, as one function over a byte slice: the accept key is its only consumer and hashes a few dozen bytes once per connection. Graded by the RFC 3174 vectors (one block, the 56-byte message whose padding takes a second block, a million 'a's, the 640-byte repetition) and the empty message's FIPS 180-4 value. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
Open Watch Party (plxnative#1090) talks JSON over WebSocket, and the televisions' libcurl has no WebSocket API before 7.86, so the protocol is ours, over the CONNECT_ONLY socket the transport will open. This is the half that does no IO: bytes in, events and bytes to write out. It lives in plx_net under the transport, so the OWP crate above sees only text messages and close codes. - handshake: the upgrade request (the process User-Agent, through user_agent_header_line), a key from a nonce the caller supplies, and the RFC 6455 section 4.1 checks on the answer: 101, Upgrade and Connection tokens without case, exactly one Sec-WebSocket-Accept equal to ours, no extension or subprotocol we did not ask for. The head is read across any split and refused past 16 KiB; the bytes after it are frames. - frames: the encoder masks with a key the caller supplies, and the parser reads across any split and refuses, from the first two bytes, reserved bits, unknown opcodes, a masked server frame, a fragmented or long control frame, a 64-bit length with its top bit set and a length past the caller's limit, so no payload is buffered for a frame it will refuse. - connection: pings answered with the same payload, fragments joined around control frames, text checked as UTF-8 as fragments arrive and again whole, a message past the limit refused, the server's close echoed with its code, and our close waiting for the server's. A violation sends the close code RFC 6455 gives it (1002, 1007, 1009) and ends the connection; nothing is read or sent after the end. The masking keys and the nonce come from the caller (the transport reads them from /dev/urandom), so the tests are exact: the section 5.7 examples encode and parse byte for byte, the masked pong included, and the section 1.3 accept is reproduced. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
The target drives a Connection with what libFuzzer writes: after a valid upgrade answer (frames), or from the first byte (the answer itself). It feeds the same bytes whole and in pieces whose size the first byte picks, and asserts the two runs give the same events and the same bytes to send. Then it asserts what the codec promises: Opened first and only once, nothing after Closed or Failed, no message past the limit, and what the client wrote parses back as unfragmented pongs and at most one close, which comes last and only when the connection ended after opening. tools/fuzz-hud.py builds its seeds from RFC 6455 frames (the section 5.7 examples, fragments around a ping, closes, invalid text, a length past the limit, an upgrade accepted and one refused) and a byte dictionary. fuzz.yml runs it on a PR that touches the codec, SHA-1 or base64, and offers it to a dispatch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
|
A note for part 2, from #1270 (opt-in bundled curl 8.23 / OpenSSL 3.5 behind
Both only matter if #1270 lands. I'm happy to adjust either side. |
GLinnik21
left a comment
There was a problem hiding this comment.
The split into a codec PR and a transport PR still makes sense. Please fix the frame-length and HTTP upgrade validation issues below and add focused regression tests in this PR. We reproduced the malformed frame and handshake cases against this commit in a standalone WSL harness.
For part 2, please keep the plan from #1090 and attach the Autobahn client report for the actual CONNECT_ONLY transport. Please include the suite version and explain any skipped or non-strict cases. Prior test plan
RFC 6455 section 5.2 asks for the minimal number of bytes. A 16-bit length under 126 or a 64-bit length under 65536 is now NonMinimalLength, which fails the connection with 1002. The 125/126 and 65535/65536 transitions stay covered. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
…mpty The client offers neither, so RFC 6455 sections 4.2.2 and 9.1 leave no room for either response header; a blank one used to open the connection. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
A field value is opaque bytes (RFC 9110 section 5.5), so a 101 with an unrelated field carrying obs-text such as 0xe9 now opens instead of failing the whole upgrade. A field name must be a non-empty token (RFC 9112 section 5), so "Not A Field: y", a folded line and a bare CR in a field are Malformed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
… form Connection::open used to accept any visible ASCII, so "relay.example/path" as the host and "/v1/ws#fragment" as the path built a request. The host must now be a reg-name, an IPv4 address or a bracketed IP literal with an optional numeric port, and the path an absolute path with an optional query, both by the RFC 3986 character sets with percent-encoding checked (RFC 6455 sections 3 and 4.1). A fragment is refused, a query is kept. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
…uest close() while Connecting marked the codec closed but left the upgrade GET in the outgoing buffer, so a transport that took it afterwards would still send it. The unsent request is now dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
|
Thanks for reproducing these. The five threads are addressed in 23d2172, 269c18f, 1f19777, 99b27b8 and a3f475c, one commit each, each with its regression test seen failing first. On a3f475c:
For part 2, the Autobahn client report will cover the real @fraygox, thanks for the notes on #1270. Nothing changes here, and both points will hold in the transport PR:
Whichever of the two lands second makes the change: on my side if #1270 is in by then, on yours otherwise, with the same lines #1270 adds to |
GLinnik21
left a comment
There was a problem hiding this comment.
Verified the requested codec fixes and the IPv6 host regression at 29c1317e. The focused WSL tests, no-default-features check, and GitHub CI passed. The Autobahn client run remains part of the transport PR as agreed in #1090.
Part 1 of 4 for Open Watch Party (#1090), as agreed there: the WebSocket codec, SHA-1 and a
ws_framefuzz target. The CONNECT_ONLY transport over libcurl is part 2. The OWP client crate is parts 3 and 4.Why
OWP is JSON over
wss://. The sets' libcurl (7.53.1 on the oldest) predates libcurl's WebSocket API (7.86), so RFC 6455 is ours, over the socketCURLOPT_CONNECT_ONLYhands back. The spike in #1090 ran that against the public relay with libcurl 8.5.0 and 7.53.1. This PR is the half that does no IO. Bytes come in, events and bytes to write come out, and the transport will drive it.What
plx_base::sha1: SHA-1 next tosha256.rs, forSec-WebSocket-Accept, graded by the RFC 3174 vectors.plx_net::ws, under the transport, so the OWP crate above sees only text messages and close codes:handshake: the upgrade request with the process User-Agent (user_agent_header_line), its key from a caller-supplied nonce, and the §4.1 checks on the answer. These are 101, theUpgrade/Connectiontokens case-insensitive, exactly one matchingSec-WebSocket-Accept, and noSec-WebSocket-ExtensionsorSec-WebSocket-Protocolfield at all, even an empty one, since we ask for neither. The head is read as bytes across any split and refused past 16 KiB. Field names must be tokens. A bare CR or a NUL is refused, and any other value byte is opaque except in the four fields the checks read.frame: an encoder that masks with a caller-supplied key, and a parser that reads across any split. From the header alone, before any payload is buffered, it refuses:usize).connection:openbuilds a request only for a host that is an HTTP authority (a reg-name or IP address with an optional port, no userinfo) and a path that is an origin form (path and query, no fragment);ws_frameinfuzz/: the same bytes fed whole and split at a fuzzer-chosen stride must give the same events and the same bytes out. The target also asserts what the codec promises:Openedfirst and once, nothing after the end, no message past the limit, and what the client wrote parses back as pongs plus at most one close, last. Seeds and a dictionary come fromtools/fuzz-hud.py, andmax_lenis above the 16 KiB head limit.fuzz.ymlruns it for changes to the codec, SHA-1 or base64.Nonces and masking keys come from the caller (part 2 reads them from
/dev/urandom), so the tests are exact. The §5.7 examples encode and parse byte for byte, masked pong included, and the §1.3 accept is reproduced.Checks
On the committed tree, WSL2 x86_64:
make checkon a3f475c: 39 suites, 24650 passed, 0 failed, 198 ignored.make check-nodef: clean.cargo check --lib --target armv7-unknown-linux-gnueabi -p plx_base -p plx_net: clean (only the usualneon/soft-floatnotes).make test-crate C=plx_net T=ws::: 33 passed.C=plx_base T=sha1: 2 passed.tools/fuzz-hud.py run --secs 600 ws_frameonnightly-2026-10-03, after the review fixes: 5,083,897 runs, coverage 792, no crash.pr-reviewer: one round. Its points are in this branch: pongs while our close waits, the 32-bit length overflow,max_lenabove the head limit and an executable bit the editor had dropped.doc-claim-auditor: its three findings are fixed (netcrate description,docs/module-layers.mdtable, the fuzz tree's size note in the Makefile).No FFI,
dynlib!or curl change here, so nofw-compat-reviewer. That review comes with part 2.The fuzz tree gains one binary:
ws_frameadds 83 MiB on Linux x86_64. The Makefile note anddocs/agent-reference.mdsay so, andDISK_NEED = 3.3still covers 3.1 GiB plus that.make build-benchThe PR touches
Makefile,.github/workflows/fuzz.ymlandfuzz/Cargo.toml. The review fixes afterdf2cacbdtouch onlyrust-modules/net/src/ws/, so this table still applies. Base279b66d9against this branchdf2cacbd, one after the other on the same machine (rustc 1.99.1, x86_64, 16 cores, WSL2), 3 interleaved runs per scenario, rustc front end serial. The table shows the median, with min–max in brackets.279b66d9df2cacbdplx_basecbuf.rs, non-incrementalplx_machinelandgate.rsplx_platformdevcaps.rsplx_gfxoverdraw.rsplx_netstream_redirect.rsplx_uidwell.rsplx_plexretry.rsplx_telemetrywindow.rsplx_datatape.rsplx_sessionscripted.rsplx_mediaunits.rsplx_appkitskip_pill.rsplx_screensclock_readout.rsplx_uilib.rs, non-incrementalplx_basecbuf.rs, incrementalplx_uilib.rs, incrementalEvery branch median is inside the base's min–max. The branch reads a few percent slower across the board, but that includes rows whose crates this PR does not touch (
plx_screens, the app crate alone). So I read it as drift between the two sittings, not as a cost of the change. The unit suite has 30 more tests (2 SHA-1, 28 codec) in the same time. The ARM row is skipped because this checkout has no ARM archive: the webOS NDK has no Linux x86_64 build, somakecannot run here.Refs #1090.
🤖 Generated with Claude Code