Skip to main content

Module cookie

Module cookie 

Source
Available on crate feature link only.
Expand description

The SYN Cookie and the Listener’s stateless identifiers — draft-sharabayko-srt-01 §4.3.1.1 (“a cookie that is crafted based on host, port and current time with 1 minute accuracy”; private/specs-verified/rules/srt-rules.md).

The draft names the cookie’s inputs, not an algorithm. Here the cookie is a keyed MAC — HMAC-SHA-256 under the listener’s secret — over the peer’s full address (family, IP, port), the Caller’s Socket ID and a coarse time bucket, so a cookie obtained from one source proves nothing for another, and it expires once its bucket is two old. This crate never reads a clock: the caller supplies the bucket (UNIX time / 60) and the secret (from a CSPRNG, replaced periodically).

Structs§

CookieOrigin
The key and the bucket a validated cookie was issued under.

Functions§

derive_cookie
The SYN Cookie for peer and the Caller’s caller_socket_id in time_bucket, under secret. Never 0 (that value means “no cookie yet”).
derive_listener_ids
The Listener’s per-connection Socket ID and Initial Sequence Number for a cookie issued over the same inputs: a stateless Listener has nowhere to keep what its INDUCTION answer carried, so the CONCLUSION recomputes it. Domain-separated from the cookie, so a Caller that has seen its cookie cannot compute them. The Socket ID is never 0 (no socket assigned).
validate_cookie
Whether cookie was issued to peer and caller_socket_id under one of secrets, in now_bucket or the bucket before it, compared in constant time. A cookie two buckets old is refused.