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.
DtlsTransport transport_DtlsTimerSink timer_DatagramEndpoint clientAddr_Dtls12ServerPhase phase_ushort messageSeq_ushort epoch_ulong recordSeq_SecureRandom rng_DtlsFlight pendingFlight_int retryCount_ubyte[32] clientRandom_ubyte[32] serverRandom_ubyte[] preMasterSecret_ubyte[] masterSecret_ubyte[] receivedCookie_X25519PrivateKey ecdhePrivate_NamedGroup selectedGroup_DtlsVersion minVersion_DtlsVersion maxVersion_string[] alpnProtocols_SrtpProfile[] srtpProfiles_string negotiatedAlpn_CipherSuiteId negotiatedCipher_DtlsVersion negotiatedVersion_SrtpProfile negotiatedSrtpProfile_const(ubyte)[][] certChainDer_string privateKeyPem_Tls12Prf prf_TranscriptHash transcript_TlsAead writeAead_TlsAead readAead_ubyte[] cookieSecret_DtlsFragmentBuffer reassembly_ubyte[] pendingDatagram_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[] 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 deriveKeys()Derive master secret and key material.ubyte[] buildFinished()Build a Finished handshake message.void updateTranscript(HandshakeType msgType, 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.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.