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.
HKDF hkdf13_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.
DtlsTransport transport_DtlsTimerSink timer_DatagramEndpoint clientAddr_Dtls13ServerPhase phase_ushort messageSeq_ushort epoch_ulong recordSeq_SecureRandom rng_DtlsFlight pendingFlight_int retryCount_ubyte[32] clientRandom_ubyte[32] serverRandom_ubyte[] sharedSecret_ubyte[] receivedCookie_X25519PrivateKey ecdhePrivate_NamedGroup selectedGroup_DtlsVersion minVersion_DtlsVersion maxVersion_string[] alpnProtocols_SrtpProfile[] srtpProfiles_string negotiatedAlpn_CipherSuiteId negotiatedCipher_DtlsVersion negotiatedVersion_SrtpProfile negotiatedSrtpProfile_bool cidEnabled_ubyte localCidLength_DtlsConnectionId localCid_DtlsConnectionId peerCid_bool cidNegotiated_const(ubyte)[][] certChainDer_string privateKeyPem_Dtls13ServerKeySchedule keySchedule_DtlsTranscriptHash transcript_TlsAead writeAead_TlsAead readAead_ubyte[] cookieSecret_DtlsFragmentBuffer reassembly_ubyte[] pendingDatagram_bool sessionResumptionEnabled_uint ticketLifetimeSeconds_size_t maxEarlyDataSize_DtlsSessionCallback onSessionTicket_DtlsEarlyDataCallback onEarlyData_DtlsTicketKeyManager ticketKeyMgr_ubyte[] receivedPskTicket_ubyte[] receivedPskBinder_bool pskValid_ubyte[] pskFromTicket_TlsAead earlyDataAead_bool earlyDataReceived_size_t earlyDataBytesReceived_const(ubyte)[] chBody_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 presharedkey 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[] 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) @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.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.