Repository navigation
feat(core): wire module — sshtype, BPP framing, version exchange (M1) - #63
Merged
Merged
Conversation
…ange The entry of the pre-authentication path (threat model 4.1), with the security rules as structural properties rather than conventions: - Reader: zero-copy parser over byte slices where EVERY variable-length read takes an explicit caller-supplied bound — the no-unbounded-allocation rule is the API's type signature, not a guideline. No panics on input; all failures are typed WireError. Pure functions, fuzzable by construction. - sshtype primitives (RFC 4251 sec. 5): byte/boolean/uint32/uint64/ string/name-list/mpint. Strict parsing, fail closed: non-canonical mpints (redundant leading zero, negative, non-empty zero) and malformed name-lists (non-ASCII, empty names, stray commas) are rejected, not normalised. - Binary Packet Protocol framing (RFC 4253 sec. 6), plaintext phase: encode with random padding (getrandom), packet_length validated against the 35000 hard cap and block alignment BEFORE any allocation — the first attacker-controlled length the server observes is bounded at the door. - Version exchange (RFC 4253 sec. 4.2): SSH-2.0 only (SSH-1.99 compatibility marker rejected — zero legacy), peer line bounded byte-by-byte at 255, integrated into the connection handler: the server now sends its banner, validates the peer's, and closes (KEXINIT picks up from here in M2). - getrandom 0.3 added (workspace-pinned): BPP padding now, KEXINIT cookie in M2. Tests: 23 unit (round-trips per type, RFC 4251 worked examples for mpint, truncation/oversize/misalignment/padding attacks, bound-trips- before-data proof, identification edge cases) + 4 integration over real TCP, including the threat-model 5.1.3 slow-handshake scenario promised in the #62 review (client sends nothing, server cuts at the budget) and the oversized-line cut. Refs #9 (M1 of the walking skeleton). Signed-off-by: Gonzalo Fleming <[email protected]>
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
M1 of the walking skeleton (#9): the
wiremodule — the entry of the pre-authentication path. sshtype primitives (RFC 4251 §5), Binary Packet Protocol framing (RFC 4253 §6, plaintext phase), and the version exchange (RFC 4253 §4.2) integrated into the connection handler: the server now speaks its first protocol bytes.Security design (threat model §4.1, as structure)
Readerrequires an explicit caller-supplied bound on every variable-length read — there is no unbounded entry point to write. The teststring_over_bound_is_rejected_before_reading_dataproves the bound trips before any read/allocation of the attacker-declared size.&[u8] → Result. The Phase 3 fuzz harness plugs in directly.WireError; indexing is always preceded by length checks (andunsafeis forbidden workspace-wide).SSH-1.99rejected (zero legacy),packet_lengthvalidated against the 35 000 cap and block alignment before anything else — it is the first attacker-controlled length the server ever sees.Wire behaviour change
handle()now: sendsSSH-2.0-quantumssh_0.0.1, reads the peer's identification (one line, ≤255 bytes, byte-bounded), logs it at debug, closes cleanly. M2 continues from this exact point with KEXINIT.Dependency delta
getrandom 0.3(workspace-pinned,default-features = false): OS randomness for BPP padding now and the KEXINIT cookie in M2. Justification per CLAUDE.md rule #4: unavoidable for protocol-mandated unpredictable fields; RustCrypto-adjacent, tiny, no transitive surprises.Tests
23 unit + 4 integration (real TCP): version exchange round-trip, accept-loop survival, the §5.1.3 slow-handshake scenario promised in the #62 review (silent client cut at the budget), malformed identification, and the 255-byte line cut (accepting EOF or RST — the kernel answers in-flight bytes with RST when we fail-close, which is the correct posture).
Checklist
fmt/clippy -D warnings(pedantic+nursery) /deny/ 27 tests greenRefs #9.