ddn.net.dtls.server12
DTLS 1.2 server handshake state machine (RFC 6347).
Drives the DTLS 1.2 server handshake as a resumable state machine. The server handles multiple concurrent handshakes from different clients, each identified by their DatagramEndpoint. For each peer, the server:
- Receives ClientHello and optionally performs cookie exchange
- Sends ServerHello, Certificate, ServerKeyExchange, ServerHelloDone
- Receives ClientKeyExchange, ChangeCipherSpec, Finished
- Sends ChangeCipherSpec and Finished
Reuses cryptographic primitives from the TLS 1.2 implementation: PRF (Tls12Prf), AEAD (TlsAead), key exchange (X25519, ECDH P-256), certificate parsing, and signature generation.
Types 1
DTLS 1.2 server handshake engine.
Drives the server side of a DTLS 1.2 handshake over a datagram transport for a single peer. Uses flight-based retransmission with exponential backoff and supports the HelloVerifyRequest 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 Dtls12ServerPhase phase_private ushort messageSeq_Per-direction transmit counter (RFC 6347 §4.2.2).private ushort lastRecvSeq_message_seq from the most recently received handshake message, used when hashing inbound messages into the transcript.private ushort epoch_private ushort readEpoch_private ulong recordSeq_private int lastPeerMsgSeq_Highest fully processed peer handshake message_seq (RFC 6347 §4.2.2); -1 until the first message completes.private SecureRandom rng_private DtlsFlight pendingFlight_private int retryCount_private ubyte[32] clientRandom_private ubyte[32] serverRandom_private ubyte[] preMasterSecret_private ubyte[] masterSecret_private ubyte[] receivedCookie_private X25519PrivateKey ecdhePrivate_private EcdhP256 ecdheP256_private bool ecdheP256Valid_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 const(ubyte)[][] certChainDer_private string privateKeyPem_private PrivateKey privateKey_private SignatureScheme sigScheme_private Tls12Prf prf_private TranscriptHash transcript_private TlsAead writeAead_private TlsAead readAead_private ubyte[] cookieSecret_private DtlsFragmentBuffer reassembly_private ubyte[] pendingDatagram_void setSrtpProfiles(SrtpProfile[] profiles) @safe pure nothrowSets the DTLS-SRTP profiles to negotiate (RFC 5764).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 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.ubyte[] buildServerHello()Build a ServerHello handshake message.ubyte[] buildCertificate()Build a Certificate handshake message.ubyte[] buildServerKeyExchange()Build a ServerKeyExchange handshake message.void generateEphemeralKey(NamedGroup group, ref ubyte[] pubKeyBytes)Generate an ephemeral ECDHE key pair.ubyte[] signKeyExchange(const(ubyte)[] params)Sign the key exchange parameters.ubyte[] computeSignature(const(ubyte)[] message)Signs a message with the configured private key.ubyte[] buildServerHelloDone()Build a ServerHelloDone handshake message.bool processClientResponse(const(ubyte)[] datagram)Process a client response datagram.bool processHandshakePayload(const(ubyte)[] payload)Process a handshake payload from a DTLS record.bool dispatchHandshakeType(HandshakeType msgType, const(ubyte)[] body)Dispatch a handshake message by type.void processClientKeyExchange(const(ubyte)[] body)Process a ClientKeyExchange message.ubyte[] buildChangeCipherSpec()Build a ChangeCipherSpec record.void deriveKeyMaterial()Derives master secret and key material.void deriveKeys()Derives key material and switches the write epoch.ubyte[] buildFinished()Build a Finished handshake message.void processClientFinished(const(ubyte)[] body)Process a client Finished message body.const(ubyte)[] decryptRecordPayload(const(ubyte)[] payload,
DtlsRecordHeader header)Decrypts an encrypted DTLS 1.2 record payload using the read AEAD.void updateTranscript(HandshakeType msgType, ushort msgSeq,
const(ubyte)[] body)Update the handshake transcript hash.ubyte[] wrapHandshakeMessage(HandshakeType msgType, const(ubyte)[] body)Wrap a handshake message in a DTLS handshake header.ubyte[] wrapInRecord(ContentType contentType, const(ubyte)[] payload)Wrap a handshake message in a DTLS record.ubyte[] buildDtlsRecord(ContentType contentType, const(ubyte)[] payload)Build a complete DTLS record with 13-byte header.ubyte[] encryptRecord(ContentType contentType, const(ubyte)[] plaintext)Encrypt a record payload using the 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.void retransmitFlight()Retransmit the pending flight.Dtls12ServerPhase 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.ulong recordSeq() @property const @safe pure nothrow @nogcReturns: The next outgoing record sequence number for the current epoch.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.2 server handshake engine.Variables 1
DTLS_1_2_RECORD_VERSION = [0xFE, 0xFD]DTLS 1.2 record version used on the wire.