Expand description
Directional session keys, AAD-bound frames, replay protection, and deadlines for IPC connections (WBS-509/510/511, TD-ROB-16).
Wire design (v1):
- Handshake — the CLIENT sends the first frame (the same 4-byte
length-prefixed framing as everything else): a JSON
SessionHello { v: 1, cr: <hex 32B client random> }. The server repliesSessionAccept { v: 1, sr: <hex 32B server random> }. - Key schedule (WBS-509) — HKDF-SHA256 with the daemon auth token as
IKM and
client_random || server_randomas salt yields two DIRECTIONAL 32-byte keys (c2s,s2c); the client encrypts withc2s, the server withs2c, so a frame replayed into the opposite direction (reflection) fails authentication. - Frames (WBS-510) — nonce
4 zero bytes || u64 BE counterand AADSPIS || proto(u16 LE) || direction(u8) || counter(u64 LE): the ciphertext is bound to the protocol, the direction, and the counter. - Replay (WBS-511) — each direction’s counter must be STRICTLY increasing; a duplicate or lower counter is refused before delivery.
- Deadlines — every frame read is bounded by
SESSION_READ_DEADLINE(stalled peers cannot wedge the other side); frame bounds stay atMAX_MESSAGE_SIZE.
Compatibility: legacy (pre-session) clients speaking plaintext envelopes are accepted in PLAIN mode when the server negotiates (the first frame is not a SessionHello); plain mode is the ADR-007 migration window and is removed in 1.0. New clients ALWAYS negotiate.
Structs§
- Session
Accept - Handshake frame (server → client).
- Session
Crypto - Session crypto for ONE connection endpoint: seals in the endpoint’s send direction, opens in the peer’s.
- Session
Hello - Handshake frame (client → server).
Enums§
- Direction
- Which direction frames flow in. Directional keys (WBS-509): the client
encrypts with
c2s, the server withs2c.
Constants§
- SESSION_
PROTO_ VERSION - Session protocol version.
- SESSION_
READ_ DEADLINE - Bound on every frame read (deadlines, WBS-511).
Functions§
- client_
random_ of - derive_
directional_ keys - Derive the two directional keys (WBS-509).
tokenis the daemon auth token (32 random bytes, hex); the session randoms bind the keys to one specific session. - is_
session_ hello - True when the first plaintext frame is a SessionHello (server-side negotiation detection). A plaintext envelope frame is NOT a hello.
- new_
accept - Fresh server accept + its random.
- new_
hello - Fresh client hello + its random (kept by the client for key derivation).
- parse_
accept - parse_
hello - server_
random_ of