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)
struct HelloVerifyRequest
Types 1
structHelloVerifyRequest
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
fn
ubyte[] generateCookie(const(ubyte)[] serverSecret, DatagramEndpoint clientAddr,
const(ubyte)[] clientRandom)Generates a stateless cookie for DTLS HelloVerifyRequest.fn
bool verifyCookie(const(ubyte)[] cookie, const(ubyte)[] serverSecret,
DatagramEndpoint clientAddr, const(ubyte)[] clientRandom)Verifies a cookie received from a client.fn
ubyte[] buildHelloVerifyRequest(DtlsVersion serverVersion, ushort messageSeq,
const(ubyte)[] cookie)Builds a HelloVerifyRequest message with DTLS handshake header.fn
const(ubyte)[] extractClientHelloCookie(const(ubyte)[] clientHelloBody) @safe pure nothrowExtracts the cookie from a DTLS ClientHello message.Variables 2
enumvar
COOKIE_SECRET_SIZE = 32Size of the server cookie secret key in bytes.
enumvar
MAX_COOKIE_SIZE = 255Maximum cookie size in bytes (per RFC 6347 §4.2.1: opaque cookie<0..2^8-1>).