ddn.net.dtls.session

DTLS 1.3 session resumption and 0-RTT early data (RFC 9147 §8).

Implements session ticket management for DTLS 1.3 session resumption. After a successful handshake, the server issues a NewSessionTicket containing an encrypted PSK that the client can use to resume the session in a subsequent connection.

Key components:

  • DtlsSessionTicket: Ticket encryption/decryption using AES-GCM
  • DtlsReplayCache: Anti-replay protection for 0-RTT early data
  • DtlsSessionStore: Client-side session ticket storage

Types 4

Encrypted session ticket for DTLS 1.3 resumption.

The ticket contains:

  • Encrypted PSK and metadata (encrypted with server's ticket key)
  • Ticket nonce (for key derivation)
  • Lifetime and early data limits
Fields
ubyte[] nonce
ubyte[] ciphertext
uint lifetimeSeconds
size_t maxEarlyDataSize
ushort cipherSuite

Session ticket encryption key manager.

Server-side component that manages ticket encryption keys. Keys are rotated periodically for forward secrecy.

Methods
void rotateKey()Rotates to a new ticket encryption key.
ubyte[] activeKey()Returns: the active encryption key.
DtlsEncryptedTicket encryptTicket(const(ubyte)[] psk, ushort cipherSuite, uint lifetimeSeconds, size_t maxEarlyData)Encrypts session data into a ticket.
auto decryptTicket(DtlsEncryptedTicket ticket)Decrypts a session ticket.
Constructors
this(SecureRandom rng, Duration rotationInterval = dur!"hours"(1))Constructs a ticket key manager.

Anti-replay cache for 0-RTT early data.

Tracks seen session tickets to prevent replay attacks. Supports multiple strategies as defined by EarlyDataReplayProtection.

Methods
bool checkAndRecord(const(ubyte)[] ticket)Checks if a ticket has been seen (replay check).
void prune()Prunes expired entries (for TIME_WINDOWED mode).
Constructors
this(EarlyDataReplayProtection mode = EarlyDataReplayProtection.SINGLE_USE_TICKETS, Duration timeWindow = dur!"seconds"(DtlsSessionConstants.DEFAULT_EARLY_DATA_WINDOW_S))Constructs a replay cache.

Client-side session store.

Stores session tickets received from servers for later resumption. Supports multiple server endpoints with at most one active session per endpoint.

Methods
void store(scope ref const DtlsSessionInfo session)Stores a session ticket.
DtlsSessionInfo * get(DatagramEndpoint serverAddr)Retrieves a session for the given server.
void remove(DatagramEndpoint serverAddr)Removes a stored session.
size_t count() @property const @safe pure nothrow @nogcReturns: the number of stored sessions.
void prune()Removes all expired sessions.
Constructors
this(Duration maxSessionAge = dur!"hours"(24))Constructs a session store.