Skip to content

feat(core): wire module — sshtype, BPP framing, version exchange (M1) - #63

Merged
gonzafg2 merged 1 commit into
mainfrom
feat/m1-wire
Jun 12, 2026
Merged

gonzafg2 merged 1 commit into
mainfrom
feat/m1-wire

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

Summary

M1 of the walking skeleton (#9): the wire module — 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)

  • Bounds in the type signature: Reader requires an explicit caller-supplied bound on every variable-length read — there is no unbounded entry point to write. The test string_over_bound_is_rejected_before_reading_data proves the bound trips before any read/allocation of the attacker-declared size.
  • Pure and fuzzable: parsing never performs I/O; every function is &[u8] → Result. The Phase 3 fuzz harness plugs in directly.
  • No panics on input: all failures are typed WireError; indexing is always preceded by length checks (and unsafe is forbidden workspace-wide).
  • Strict, fail closed: non-canonical mpints rejected (RFC 4251 worked examples as tests), malformed name-lists rejected, SSH-1.99 rejected (zero legacy), packet_length validated 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: sends SSH-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

  • DCO + Conventional Commits + signed
  • fmt / clippy -D warnings (pedantic+nursery) / deny / 27 tests green

Refs #9.

…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]>
@claude

claude Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@gonzafg2
gonzafg2 merged commit 7f5d0a4 into main Jun 12, 2026
8 checks passed
@gonzafg2
gonzafg2 deleted the feat/m1-wire branch July 18, 2026 04:15
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