ddn.net.dtls.server13
DTLS 1.3 server handshake state machine (RFC 9147).
Drives the DTLS 1.3 server handshake as a resumable state machine. The server handles handshakes from a single client, identified by their DatagramEndpoint. The server:
- Receives ClientHello and optionally performs HelloRetryRequest
- Sends ServerHello, EncryptedExtensions, Certificate, CertificateVerify, Finished
- All messages after ServerHello are encrypted with handshake traffic keys
- Receives client Finished and derives application traffic keys
Uses Tls13KeySchedule for cryptographic key derivation, DtlsTranscriptHash for transcript hashing, and Dtls13ServerKeySchedule for the "dtls13" HKDF label prefix.
Types 2
DTLS 1.3 key schedule with "dtls13" HKDF label prefix.
Overrides hkdfExpandLabel to use "dtls13" instead of "tls13 " per RFC 9147 §5.
private HKDF hkdf13_private size_t hashLen13_void setCipherSuite(ushort cipherSuite)Reconfigures the hash algorithm based on the negotiated cipher suite.ubyte[] hkdfExpandLabel(const(ubyte)[] secret, string label,
const(ubyte)[] context, size_t length)HKDF-Expand-Label with "dtls13" prefix for DTLS 1.3.this()Constructs a DTLS 1.3 key schedule.DTLS 1.3 server handshake engine.
Drives the server side of a DTLS 1.3 handshake over a datagram transport for a single peer. Uses flight-based retransmission with exponential backoff and supports the HelloRetryRequest cookie exchange for DoS mitigation.
Call processDatagram() when data arrives from a client. The server will advance its state machine and send responses as needed.
private DtlsTransport transport_private DtlsTimerSink timer_private DatagramEndpoint clientAddr_private Dtls13ServerPhase phase_private ushort messageSeq_private ushort epoch_private ulong recordSeq_private SecureRandom rng_private DtlsFlight pendingFlight_private int retryCount_private ubyte[32] clientRandom_private ubyte[32] serverRandom_private ubyte[] sharedSecret_private ubyte[] receivedCookie_private X25519PrivateKey ecdhePrivate_private NamedGroup selectedGroup_private DtlsVersion minVersion_private DtlsVersion maxVersion_private string[] alpnProtocols_private SrtpProfile[] srtpProfiles_private string negotiatedAlpn_private CipherSuiteId negotiatedCipher_private DtlsVersion negotiatedVersion_private SrtpProfile negotiatedSrtpProfile_private bool cidEnabled_private ubyte localCidLength_private DtlsConnectionId localCid_private DtlsConnectionId peerCid_private bool cidNegotiated_private const(ubyte)[][] certChainDer_private string privateKeyPem_private PrivateKey privateKey_private SignatureScheme sigScheme_private Dtls13ServerKeySchedule keySchedule_private DtlsTranscriptHash transcript_private ubyte[] appTrafficHash_Transcript hash through the server Finished (RFC 8446 §7.1: application traffic secrets bind here, before the client Finished enters the transcript).private TlsAead writeAead_private TlsAead readAead_private ubyte[] cookieSecret_private DtlsFragmentBuffer reassembly_private ubyte[] pendingDatagram_private bool sessionResumptionEnabled_private uint ticketLifetimeSeconds_private size_t maxEarlyDataSize_private DtlsSessionCallback onSessionTicket_private DtlsEarlyDataCallback onEarlyData_private DtlsTicketKeyManager ticketKeyMgr_private ubyte[] receivedPskTicket_private ubyte[] receivedPskBinder_private bool pskValid_private ubyte[] pskFromTicket_private TlsAead earlyDataAead_private bool earlyDataReceived_private size_t earlyDataBytesReceived_private const(ubyte)[] chBody_void setSrtpProfiles(SrtpProfile[] profiles) @safe pure nothrowSets the DTLS-SRTP profiles to negotiate (RFC 5764).void setCidConfig(bool enabled, ubyte cidLength = DtlsCidConstants.DEFAULT_CID_LENGTH) @safe pure nothrow @nogcEnables Connection ID and sets the local CID length.void setOnSessionTicket(DtlsSessionCallback callback) @safe pure nothrowSets the callback for issued session tickets.bool sessionResumptionEnabled() @property const @safe pure nothrow @nogcReturns: Whether session resumption is enabled.TlsProgress processDatagram(const(ubyte)[] data) @trustedProcess a received datagram and advance the handshake.bool processClientHello(const(ubyte)[] datagram)Process a ClientHello datagram.bool parseClientHelloPayload(const(ubyte)[] payload)Parse a ClientHello handshake payload.void selectCipherSuite(const(ubyte)[] cipherSuites)Select a cipher suite from the client's offered list.void parseClientHelloExtensions(const(ubyte)[] extData)Parse extensions from a ClientHello.void parsePskExtension(const(ubyte)[] data)Parses the pre_shared_key extension from ClientHello.bool validatePskBinder(const(ubyte)[] clientHelloBody)Validates the PSK binder against the ClientHello transcript.bool pskValid() @property const @safe pure nothrow @nogcReturns: Whether a valid PSK was received from the client.void setTicketKeyManager(DtlsTicketKeyManager mgr) @safe pure nothrowSets the ticket key manager for session resumption.void initEarlyDataKeys()Initializes early traffic keys from the validated PSK.bool processEarlyDataRecord(const(ubyte)[] recordData, DtlsReplayCache replayCache = null)Attempts to decrypt an early data record.bool earlyDataReceived() @property const @safe pure nothrow @nogcReturns: true if early data was received.size_t earlyDataBytesReceived() @property const @safe pure nothrow @nogcReturns: total bytes of early data received.void negotiateAlpn(const(ubyte)[] alpnData)Negotiate ALPN from the client's extension data.void parseSupportedGroups(const(ubyte)[] groupsData)Parse supported groups extension to select ECDHE group.void parseKeyShare(const(ubyte)[] ksData)Parse key_share extension to extract client's ephemeral public key.void parseSupportedVersions(const(ubyte)[] svData)Parse supported_versions extension to confirm DTLS 1.3 support.ubyte[] buildHelloRetryRequest(DtlsVersion dtlsVer, ushort msgSeq,
const(ubyte)[] cookie)Build a HelloRetryRequest handshake message.ubyte[] buildServerHello()Build a ServerHello handshake message.ubyte[] buildEncryptedExtensions()Build an EncryptedExtensions handshake message.ubyte[] buildCertificate()Build a Certificate handshake message.ubyte[] buildCertificateVerify()Build a CertificateVerify handshake message.ubyte[] signCertificateVerify(const(ubyte)[] message)Sign the CertificateVerify message content.ubyte[] computeSignature(const(ubyte)[] message)Signs a message with the configured private key.ubyte[] buildFinished()Build a Finished handshake message.ubyte[] buildNewSessionTicket(DtlsTicketKeyManager ticketKeyMgr)Builds a NewSessionTicket message for session resumption.bool sendNewSessionTicket(DtlsTicketKeyManager ticketKeyMgr)Builds, encrypts, and sends a NewSessionTicket to the client.bool processClientFinished(const(ubyte)[] datagram)Process a client Finished datagram.ubyte[] decryptRecordPayload(const(ubyte)[] payload, DtlsRecordHeader header)Decrypt a record payload using the read AEAD.bool processClientFinishedPayload(const(ubyte)[] payload)Process a decrypted client Finished payload.void generateEphemeralKey(NamedGroup group, ref ubyte[] pubKeyBytes)Generate an ephemeral ECDHE key pair.void performKeyExchange(NamedGroup group, const(ubyte)[] peerPubKey)Perform ECDHE key exchange with the client's public key.void deriveHandshakeKeys()Derives handshake traffic keys from the shared secret.void deriveAppKeys()Derives application traffic keys.size_t cipherKeyLength(CipherSuiteId cs) static @safe pure nothrow @nogcReturns the AEAD key length for the given cipher suite.ubyte[] wrapHandshakeMessage(HandshakeType msgType, const(ubyte)[] body)Wraps a handshake message body in a DTLS handshake header.ubyte[] wrapInRecord(ContentType contentType, const(ubyte)[] payload)Wraps a handshake message in a DTLS record.ubyte[] buildDtlsRecord(ContentType contentType, const(ubyte)[] payload)Builds a complete DTLS record with 13-byte header.ubyte[] encryptRecord(ContentType contentType, const(ubyte)[] plaintext)Encrypts a record payload using the current write AEAD.const(ubyte)[] receiveDatagram()Receive a datagram from pending buffer or transport.void sendDatagram(const(ubyte)[] data)Send a datagram via the transport.void sendFlight(ubyte[][] records)Send a flight of records as a single datagram.void scheduleRetransmit()Schedule retransmission timer for the current flight.void retransmitFlight()Retransmit the pending flight.Dtls13ServerPhase phase() @property const @safe pure nothrow @nogcReturns: The current handshake phase.CipherSuiteId negotiatedCipher() @property const @safe pure nothrow @nogcReturns: The negotiated cipher suite.DtlsVersion negotiatedVersion() @property const @safe pure nothrow @nogcReturns: The negotiated DTLS version.SrtpProfile negotiatedSrtpProfile() @property const @safe pure nothrow @nogcReturns: The negotiated DTLS-SRTP profile (`SrtpProfile.init` when SRTP was not negotiated).this(DtlsTransport transport, DtlsTimerSink timer,
DatagramEndpoint clientAddr, const(ubyte)[] cookieSecret,
const(ubyte)[][] certChainDer, string privateKeyPem)Constructs a DTLS 1.3 server handshake engine.Variables 1
DTLS_1_3_RECORD_VERSION = [0xFE, 0xFD]DTLS 1.3 record version used on the wire.
DTLS 1.3 uses the same record layer version as DTLS 1.2 (0xFEFD) for backwards compatibility per RFC 9147.