@nodertc/dtls
使用纯 js 实现的基于数据报传输层安全协议版本 1.2 进行安全的 UDP 通信。 遵循RFC6347、RFC7627。
特性
- 没有本地依赖!
- 现代安全密码(默认情况下)
- 进出分片/进出重传
- 合并传出的握手
用法
npm i @nodertc/dtls const dtls = require('@nodertc/dtls'); const socket = dtls.connect({ type: 'udp4', remotePort: 4444, remoteAddress: '127.0.0.1', }); socket.on('error', err => { console.error(err); }); socket.on('data', data => { console.log('got message "%s"', data.toString('ascii')); socket.close(); }); socket.once('connect', () => { socket.write('Hello from Node.js!'); });
支持的密码:
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (nodejs v11.2+ only)
- TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (nodejs v11.2+ only)
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- TLS_RSA_WITH_AES_128_GCM_SHA256
- TLS_RSA_WITH_AES_256_GCM_SHA384
- TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 (nodejs v11.2+ only)
- TLS_PSK_WITH_AES_128_GCM_SHA256
- TLS_PSK_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256
API
请参考自述文件。
如何调试?
启动 dtls 服务器:
docker run -it --name dtlsd --rm -e <span class="pl-s"><span class="pl-pds">"</span>GNUTLS_DEBUG_LEVEL=2<span class="pl-pds">"</span></span> -e <span class="pl-s"><span class="pl-pds">"</span>PRIORITY=NORMAL:+AEAD:+ECDHE-RSA:+VERS-DTLS1.2<span class="pl-pds">"</span></span> -e <span class="pl-s"><span class="pl-pds">"</span>KEYFILE=key-rsa.pem<span class="pl-pds">"</span></span> -e <span class="pl-s"><span class="pl-pds">"</span>CERTFILE=cert-rsa.pem<span class="pl-pds">"</span></span> -p 4444:4444/udp nodertc/dtls-server:1
启动缺省客户端
npm start
许可
MIT, 2018 - 2019 © Dmitriy Tsvettsikh
(The first version translated by vz on 2020.08.01)