ddn.net.dtls.cookie

DTLS cookie exchange for DoS mitigation.

Implements the cookie generation and verification mechanism described in RFC 6347 §4.2.1 (DTLS 1.2 HelloVerifyRequest). Cookies prevent spoofed-source denial-of-service attacks by requiring the client to prove it can receive at the claimed address before the server commits expensive resources.

Cookie computation: HMAC-SHA256(serverSecret, clientAddress || clientRandom)

Types 1

Parsed HelloVerifyRequest message (RFC 6347 §4.2.1).

Contains the server's DTLS version and a cookie that the client must echo back in its retried ClientHello.

Fields
DtlsVersion serverVersionServer's DTLS version.
const(ubyte)[] cookieCookie bytes to echo back.
Methods
HelloVerifyRequest parse(const(ubyte)[] data) @safe pure nothrow @nogcParses a HelloVerifyRequest handshake body (after the 12-byte DTLS handshake header has been stripped).
bool valid() @property const @safe pure nothrow @nogcReturns: true if this instance was successfully parsed.

Functions 5

fnubyte[] generateCookie(const(ubyte)[] serverSecret, DatagramEndpoint clientAddr, const(ubyte)[] clientRandom)Generates a stateless cookie for DTLS HelloVerifyRequest.
fnbool verifyCookie(const(ubyte)[] cookie, const(ubyte)[] serverSecret, DatagramEndpoint clientAddr, const(ubyte)[] clientRandom)Verifies a cookie received from a client.
fnubyte[] buildHelloVerifyRequest(DtlsVersion serverVersion, ushort messageSeq, const(ubyte)[] cookie)Builds a HelloVerifyRequest message with DTLS handshake header.
fnubyte[] generateCookieSecret(SecureRandom rng)Generates a random cookie secret for server use.
fnconst(ubyte)[] extractClientHelloCookie(const(ubyte)[] clientHelloBody) @safe pure nothrowExtracts the cookie from a DTLS ClientHello message.

Variables 2

enumvarCOOKIE_SECRET_SIZE = 32

Size of the server cookie secret key in bytes.

enumvarMAX_COOKIE_SIZE = 255

Maximum cookie size in bytes (per RFC 6347 §4.2.1: opaque cookie<0..2^8-1>).