USE AT YOUR OWN RISK!
DTLS protocol implementation for Node.js written in TypeScript. This library provides the missing native DTLS support for Node.js client-side applications. It contains no server-side implementation.
Although great care has been taken to properly implement the required encryption and validation, there's no explicit protection against TLS attacks. Thus it is not advised to use it for security-critical applications. This libary's main goal is to allow using protocols that require DTLS.
var dtls = require("node-dtls-client");
const socket = dtls
// create a socket and initialize the secure connection
.createSocket(options /* DtlsOptions */)
// subscribe events
.on("connected", () => {/* start sending data */})
.on("error", (e /* Error */) => { })
.on("message", (msg /* Buffer */) => { })
.on("close", () => { })
;
The DtlsOptions
object looks as follows:
{
type: "udp4",
address: "ip or host",
port: 5684,
psk: { "psk_hint": "PSK" },
timeout: 1000, // in ms, optional, minimum 100, default 1000
ciphers: [ /* ... */ ], // optional array of (D)TLS cipher suites, e.g. ["TLS_PSK_WITH_AES_128_CCM"]
listenPort: 2345 // optional local port number to listen at, default: chosen at random
compat: { // optional compat options
/**
* The IKEA gateway v1.15.x has a bug where the Server Hello reuses the sequence number of the Hello Verify Request.
* This flag can be set to true to work around it.
*/
resetAntiReplayWindowBeforeServerHello: true,
}
}
The ciphers
property allows specifying which cipher suites should be advertised as supported. If this property is not provided, all supported ciphers are used by default. Use this if you want to force specific cipher suites for the communication.
The currently supported cipher suites are limited to those with PSK key exchange:
"TLS_PSK_WITH_3DES_EDE_CBC_SHA"
"TLS_PSK_WITH_AES_128_CBC_SHA"
"TLS_PSK_WITH_AES_256_CBC_SHA"
"TLS_PSK_WITH_AES_128_CBC_SHA256"
"TLS_PSK_WITH_AES_256_CBC_SHA384"
"TLS_PSK_WITH_AES_128_GCM_SHA256"
"TLS_PSK_WITH_AES_256_GCM_SHA384"
"TLS_PSK_WITH_AES_128_CCM_8"
"TLS_PSK_WITH_AES_256_CCM_8"
PRs for other key exchange methods are welcome!
socket.send(data /* Buffer */, [callback]);
The events are defined as follows:
connected
: A secure connection has been established. Start sending data in the callbackerror
: An error has happened. This usually means the handshake was not successfulmessage
: The socket received some data.close
: The connection was closed successfully.
- alert protocol implementation (partially supported)
- cipher suites with non-PSK key exchange algorithms:
dhe_dss
|dhe_rsa
|rsa
|dh_dss
|dh_rsa
|dhe_psk
|rsa_psk
- packet retransmission
- session renegotiation
- other compression algorithms except NULL
PRs adding support for these are welcome!
- Updated the
node-aead-crypto
dependency for proper Electron support
- Fixed the check for Electron runtime
- Workaround for a bug in IKEA gateway firmware
v1.15.x
- Require Node.js 12+
- Added the ability to specify the local listen port
- Add support for DTLS 1.3 alerts
node-aead-crypto
is now an optional dependency- Remove
strictPropertyInitialization
since it doesn't work withoutstrictNullChecks
- Potentially breaking change: No longer use
node-aead-crypto
on NodeJS 10+
- Check connection options before creating a new socket
- Improve testing setup, use CircleCI for deployment
- Support NodeJS 10
- Suppress spurious errors from DNS lookup after the connection has already timed out
- Fixed cipher parameters of 3DES and 256-bit AES (AEAD) cipher suites.
- Added the possibility to limit the cipher suites to use
- Removed possible sources of infinite loops
- Fix error handling while trying to connect to a non-available endpoint
- add partial alert protocol implementation
- publish to npm
- bugfixes
- improved error and timeout handling in the socket wrapper.
- initial release.
- https://github.com/thoukydides - Thanks for noticing the errors in the 3DES and 256-bit AES (AEAD) cipher suites.
The MIT License (MIT)
Copyright (c) 2017-2023 AlCalzone d.griesel@gmx.net
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.