DtlsClientConnection constructor

DtlsClientConnection({
  1. required DtlsClientContext context,
  2. String? hostname,
})

Create a DtlsClientConnection using a DtlsClientContext. The hostname is used for Server Name Indication and to verify the certificate.

Implementation

DtlsClientConnection({required DtlsClientContext context, String? hostname})
    : _ssl = lib.SSL_new(context._ctx) {
  lib.SSL_set_bio(_ssl, _rbio, _wbio);
  lib.BIO_ctrl(_rbio, BIO_C_SET_BUF_MEM_EOF_RETURN, -1, nullptr);
  lib.BIO_ctrl(_wbio, BIO_C_SET_BUF_MEM_EOF_RETURN, -1, nullptr);

  if (hostname != null) {
    final hostnameStr = hostname.toNativeUtf8();
    lib.X509_VERIFY_PARAM_set1_host(
        lib.SSL_get0_param(_ssl), hostnameStr.cast(), 0);
    lib.SSL_ctrl(_ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME,
        TLSEXT_NAMETYPE_host_name, hostnameStr.cast());
    malloc.free(hostnameStr);
  }
}