jue89 / node-openssl-dtls

DTLS1.2 bindings for node.js
MIT License
11 stars 6 forks source link

OpenSSL DTLS1.2 Bindings

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.

API

const DTLS = require('openssl-dtls');
const srv = DTLS.createServer(opts);

Spawns a new server. opts is an object:

Class: Server

Method: bind()

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.

Method: close()

srv.close([cb]);

Shuts down the server and calls cb once the underlying socket has been closed.

Event: connection

srv.on('connection', (info) => {...});

Is raised if a client has started a handshake. info:

Event: error

srv.on('error', (err, info) => {...});

Is raised if something went wrong. err is an instance of Error. info:

Event: secureConnection

srv.on('secureConnection', (peer) => {...});

Is raised once a handshake has been successfully finished. peer is an instance of Peer.

Class: Peer

Method: address()

const info = peer.address();

Returns the peers address. info:

Method: getCertChain()

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.

Method: send()

peer.send(message);

Sends message to the client. message has to be a Buffer.

Method: end()

peer.end();

Closes connection to peer.

Event: message

peer.on('message', (message) => {...});

Is raised if a message has been received from peer.

Event: close

peer.on('close', () => {...});

Is raised if the connection to peer has been closed.