ddn.net.dtls.context

Native DTLS context implementation.

Holds DTLS configuration (certificates, keys, protocol versions, verification settings) and creates DtlsEngine instances for client and server connections.

Contexts are created once via createDtlsContext() and reused for many DTLS engines.

Types 1

Pure D DTLS context backed by ddn-crypto primitives.

Stores shared configuration that is applied to every engine created by clientEngine() or serverEngine().

Example:

auto ctx = createDtlsContext();
ctx.trustStore.loadSystemCerts();
ctx.setCertificateChain(pemData);
ctx.setPrivateKey(pemKey);
auto engine = ctx.serverEngine(transport, timer);

Fields
private NativeTlsTrustStore trustStore_
private TlsVerifyMode verifyMode_
private DtlsVerifyCallback verifyCallback_
private DtlsVersion minVersion_
private DtlsVersion maxVersion_
private string[] alpnProtocols_
private string certChainPem_
private const(ubyte)[][] certChainDer_
private string privateKeyPem_
private string privateKeyPassword_
private ubyte[] privateKeyDer_
private bool cidEnabled_
private ubyte cidLength_
private bool sessionResumption_
private size_t maxEarlyData_
private SrtpProfile[] srtpProfiles_
Methods
void setCertificateChain(const(char)[] pemData)Sets the certificate chain from PEM-encoded data.
void setCertificateChainDer(const(ubyte[])[] derCertificates)Sets the certificate chain from DER-encoded certificates.
void setPrivateKey(const(char)[] pemData, const(char)[] password = null)Sets the private key from PEM-encoded data.
void setPrivateKeyDer(const(ubyte)[] derData, const(char)[] password = null)Sets the private key from DER-encoded data.
TlsTrustStore trustStore() @propertyReturns: The trust store for adding trusted CA certificates.
void setVerifyMode(TlsVerifyMode mode) @safe pure nothrow @nogcSets the certificate verification mode.
void setVerifyCallback(DtlsVerifyCallback callback) @safe pure nothrowSets a custom certificate verification callback.
void setMinVersion(DtlsVersion ver) @safe pure nothrow @nogcSets the minimum DTLS version.
void setMaxVersion(DtlsVersion ver) @safe pure nothrow @nogcSets the maximum DTLS version.
void setAlpnProtocols(const(string)[] protocols) @safe pure nothrowSets the ALPN protocols to offer/accept.
void setConnectionId(bool enable, ubyte cidLength = 8) @safe pure nothrow @nogc
void setSessionResumption(bool enable, size_t maxEarlyData = 16384) @safe pure nothrow @nogc
void setSrtpProfiles(const(SrtpProfile[]) profiles) @safe pure nothrowSets the DTLS-SRTP profiles to negotiate (RFC 5764).
DtlsEngine clientEngine(DtlsTransport transport, DtlsTimerSink timer, string serverName)Creates a DTLS client engine with this context's configuration.
DtlsEngine serverEngine(DtlsTransport transport, DtlsTimerSink timer)Creates a DTLS server engine with this context's configuration.
private void applyConfig(NativeDtlsEngine engine)Apply stored configuration to a newly created engine.
private const(ubyte)[][] resolvedCertChainDer()Resolves the certificate chain to DER form.
private string resolvedPrivateKeyPem()Resolves the private key to PEM form.
Constructors
this()Constructs a NativeDtlsContext with secure defaults.