This module enables your application to listen for incoming DTLS1.2 connections. It uses OpenSSL 1.1.1, which is shipped with Node.js version 10 up to version 16.
const DTLS = require('openssl-dtls');
const srv = DTLS.createServer(opts);
Spawns a new server. opts
is an object:
key
: Buffer. The server's private key in PEM format. Mandatory.cert
: Buffer. The server's certificate in PEM format. Mandatory.ca
: Buffer. CA certificate for validation of client certificates. Optional.requestCert
: Boolean. Request certificate from client. Default: false.rejectUnauthorized
: Boolean. Reject invalid client certificates. Default: false.mtu
: Number. The wire's MTU. Default: 1500 Ethernet MTU - 40 IPv6 Header - 8 UDP Header = 1452.ciphers
: String. Allowed ciphers. Further details: OpenSSL Cipher List Format. Optional.socket
: Instances ofdgram.Socket
. By default a new'udp6'
dgram socket will be created.handshakeTimeout
: Duration in milliseconds how long a DTLS handshake can take until it will be aborted and the state is removed. Default: 30 * 1000msconnectionTimeout
: Duration in milliseconds how long a DTLS connection can stay established without any received data until the connection is closed. Default: 10 * 60 * 1000msretransmitTimeout
: Number or Function. A number states the initial retransmit timeout in microseconds that is doubled in every iteration. Function:(lastTimeout) => nextTimeout
, wherelastTimeout
is zero in the first iteration. Default:1000000
.
srv.bind(...);
Proxy method for the bind()
method of the socket
specified with DTLS.createServer()
. If you haven't specified anything, have a look into the documentation of UDP/Datagram.
srv.close([cb]);
Shuts down the server and calls cb
once the underlying socket has been closed.
srv.on('connection', (info) => {...});
Is raised if a client has started a handshake. info
:
address
: Remote address.port
: Remote port.
srv.on('error', (err, info) => {...});
Is raised if something went wrong. err
is an instance of Error. info
:
address
: Remote address.port
: Remote port.
srv.on('secureConnection', (peer) => {...});
Is raised once a handshake has been successfully finished. peer
is an instance of Peer.
const info = peer.address();
Returns the peers address. info
:
address
: Remote address.port
: Remote port.
const chain = peer.getCertChain();
Returns the peers certificate chain. chain
is a Buffer containing the certificates in PEM format. If no certificates has been prensented by the client, chain
is and empty Buffer.
peer.send(message);
Sends message
to the client. message
has to be a Buffer.
peer.end();
Closes connection to peer
.
peer.on('message', (message) => {...});
Is raised if a message
has been received from peer
.
peer.on('close', () => {...});
Is raised if the connection to peer
has been closed.