{"id":21331168,"url":"https://github.com/netbeast/react-native-dtls","last_synced_at":"2025-09-05T01:39:03.203Z","repository":{"id":147464757,"uuid":"100570547","full_name":"netbeast/react-native-dtls","owner":"netbeast","description":null,"archived":false,"fork":false,"pushed_at":"2017-08-17T08:48:52.000Z","size":119,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-16T00:42:01.325Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/netbeast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SecurityParameterContainer.js","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-17T06:41:32.000Z","updated_at":"2017-11-05T07:34:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"e9b65e39-24d4-4df0-99fb-19e4284f9f5a","html_url":"https://github.com/netbeast/react-native-dtls","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/netbeast/react-native-dtls","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeast%2Freact-native-dtls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeast%2Freact-native-dtls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeast%2Freact-native-dtls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeast%2Freact-native-dtls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netbeast","download_url":"https://codeload.github.com/netbeast/react-native-dtls/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeast%2Freact-native-dtls/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273699715,"owners_count":25152284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T22:29:46.647Z","updated_at":"2025-09-05T01:39:03.148Z","avatar_url":"https://github.com/netbeast.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nnode-dtls\n=========\n### DTLS implementation in JavaScript (Work in progress)\n\n[![Travis build](https://travis-ci.org/Rantanen/node-dtls.svg?branch=master)](https://travis-ci.org/Rantanen/node-dtls)\n[![Test Coverage](https://codeclimate.com/github/Rantanen/node-dtls/badges/coverage.svg)](https://codeclimate.com/github/Rantanen/node-dtls/coverage)\n[![Code Climate](https://codeclimate.com/github/Rantanen/node-dtls/badges/gpa.svg)](https://codeclimate.com/github/Rantanen/node-dtls)\n\nDatagram Transport Layer Security (DTLS) Protocol implementation for Node.js\nwritten in JavaScript.\n\nWhile Node.js still lacks support for DTLS protocol, this library attempts to\nfix the issue. This is in no way a security implementation as it's main goal is\nto allow using protocols that _require_ DTLS. While the library implements the\nproper DTLS encryption and validation, there has been no effort to protect it\nagainst well known TLS attacks.\n\n#### Example\n\n##### Server\n\n```javascript\nvar dtls = require( 'dtls' );\nvar fs = require( 'react-native-level-fs' );\n\nvar pem = fs.readFileSync( 'server.pem' );\n\nvar server = dtls.createServer({ type: 'udp4', key: pem, cert: pem });\nserver.bind( 4433 );\n\nserver.on( 'secureConnection', function( socket ) {\n\n  console.log( 'New connection from ' +\n    [ socket.rinfo.address, socket.rinfo.port ].join(':') );\n\n  socket.on( 'message', function( message ) {\n    \n    // Echo the message back\n    socket.send( message );\n  });\n});\n```\n\n##### Client\n\n```javascript\nvar dtls = require( '../' );\n\ndtls.setLogLevel( dtls.logLevel.FINE );\n\nvar client = dtls.connect( 4433, 'example.org', 'udp4', function() {\n    client.send( new Buffer( 'foo\\n' ) );\n});\n\nclient.on( 'message', function( msg ) {\n    console.log( msg );\n});\n```\n\n#### Current state\n\n\n- [x] DTLS 1.2 handshake in server role\n- [x] DTLS 1.2 handshake in client role\n  - Still some problems when it comes to receiving messages. Not very confident.\n- [x] Handle application data\n- [x] Proper API to handle sessions/messages outside the node-dtls internals.\n- [ ] DTLS 1.0 handshake in server role\n  - There shouldn't be _too_ many changes. Main one is propably the PRF hash.\n- [ ] Handle renegotiation\n- [ ] Robustness\n  - [x] Handshake reassembly/buffering/reordering\n  - [x] Retransmission\n  - [ ] Handle alert-messages\n  - [ ] Validate handshake state and expected messages\n\n## API\n\n#### dtls.setLogLevel( level )\n\n- `level` - [logg](https://github.com/dpup/node-logg) log level. For convenience possible log levels are also available in `dtls.logLevel.*`\n\nSets the global node-dtls logging level.\n\nnode-dtls uses /logg/ for logging and tracing various dtls events. This function can be used to alter the amount of information that is logged during the DTLS handshake/session. In future logging will most likely be disabled by default, but for now the default log level (FINE) is quite verbose.\n\n-----\n\n#### dtls.createServer(options[, callback])\n\n- `options` - Server options, see below.\n- `callback` - Optional callback registered to the `secureConnect` event.\n\nCreates a `dtls.DtlsServer`.\n\nMimics the Node.js [tls.createServer](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) function. Although given DTLS is a datagram protocol, the actual network object is created with [dgram.createSocket()](https://nodejs.org/api/dgram.html#dgram_dgram_createsocket_options_callback).\n\n`options` object is a rough combination of the option objects of `tls.createServer()` and `dgram.createSocket()`. DTLS-specific options are parsed by the `dtls.DtlsServer` and the dgram-options are passed directly to `dgram.createSocket()`.\n\n- `type` - _Required._ `dgram` socket type. Passed to `dgram.createSocket()`.\n- `key` - _Required._ The server private key in PEM format.\n- `cert` - _Required._ The server certificate in PEM format.\n\n##### Example\n\n```javascript\nvar dtls = require( 'dtls' );\nvar fs = require( 'react-native-level-fs' );\n    \nvar pem = fs.readFileSync( 'server.pem' );\n    \nvar server = dtls.createServer({ type: 'udp4', cert: pem, key: pem });\nserver.bind( 4433 );\n    \nserver.on( 'secureConnection', function( socket ) {\n  console.log( 'New secure connection: ' +\n    [ socket.rinfo.address, socket.rinfo.port ].join( ':' ) );\n});\n```\n\nThe server.pem certificate can be created with\n\n    openssl req -x509 -nodes -newkey rsa:2048 -keyout server.pem -out server.pem\n\n-----\n\n#### dtls.connect( port, address, type, callback )\n\n- `port` - Remote port to connect to.\n- `address` - Remote address to connect to.\n- `type` - Datagram socket type: `udp4` or `udp6`. Ssee [`dgram`](https://nodejs.org/api/dgram.html) for full explanation.\n- `callback` - Callback for when the handshake is ready.\n\nInitiates a connection to a remote server and returns the `dtls.DtlsSocket`.\n\n##### Example\n\n```javascript\nvar dtls = require( 'dtls' );\n\nvar client = dtls.connect( 4433, 'example.org', 'udp4', function() {\n    client.send( new Buffer( 'foo\\n' ) );\n});\n\nclient.on( 'message', function( msg ) {\n    console.log( msg );\n});\n```\n\n-----\n\n### Class: dtls.DtlsServer\n\nServer accepting DTLS connections. Created with `dtls.createServer`\n\n-----\n\n#### Event: 'secureConnection'\n\n- `socket` - dtls.DtlsSocket\n\nEmitted after the `DtlsSocket` has finished handshaking a connection and is ready for use.\n\n-----\n\n#### server.bind();\n\n- `port` - UDP port to listen to. This is passed over to `socket.bind()` of the underlying `dgram.Socket`\n\nStarts listening to the defined port. Delegated to `dgram.Socket#bind()`\n\n-----\n-----\n\n### Class: dtls.DtlsSocket\n\nA single DTLS session between a local and remote endpoints. Acquired through the `server::secureConnection` event.\n\n----\n\n#### Event: 'secureConnect'\n\nEmitted after the `DtlsSocket` has finished handshaking a connection.\n\nThis method is emitted after the server sends the `Finished` handshake message. As datagram protocols aren't reliable transports, the handshake might still be in progress if that last handshake message was lost. It is recommended that the client initiates the actual application communication as the client gets confirmation on when the handshake has been completed.\n\n_Note:_ that usually it is impossible to catch this event as it is raised before the user has a reference to the socket. Use `server::secureConnection` event instead.\n\n-----\n\n#### Event: 'message'\n\n- `buffer` - Application data within a [`Buffer`](https://nodejs.org/api/buffer.html#buffer_class_buffer).\n\nEmitted when the socket has received and decrypted application data from the remote endpoint.\n\n##### Example\n\n```javascript\nvar server = dtls.createServer({\n    type: 'udp4',\n    key: pem,\n    cert: pem\n});\nserver.bind( 4433 );\n\nserver.on( 'secureConnection', function( socket ) {\n  socket.on( 'message', function( message ) {\n    console.log( 'In: ' + message.toString( 'ascii' ) );\n  });\n});\n```\n\n-----\n\n#### socket.send( buffer[, offset][, length][, callback] )\n\n- `buffer` - `Buffer` object to send.\n- `offset` - Offset in the buffer where the message starts. Optional.\n- `length` - Number of bytes in the message. Optional.\n- `calback` - called when the message has been sent. Optional.\n\nSends application data to the remote endpoint.\n\n##### Example\n\n```javascript\nvar server = dtls.createServer({\n    type: 'udp4',\n    key: pem,\n    cert: pem\n});\nserver.bind( 4433 );\n\nserver.on( 'secureConnection', function( socket ) {\n  socket.send( new Buffer( 'Hello!\\n', 'ascii' ) );\n});\n```\n\n-----\n\n## References\n\n[Datagram Transport Layer Security Version 1.2, RFC 6347]\n(https://tools.ietf.org/html/rfc6347)\n\n[The Transport Layer Security (TLS) Protocol Version 1.2, RFC 5246]\n(https://tools.ietf.org/html/rfc5246)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetbeast%2Freact-native-dtls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetbeast%2Freact-native-dtls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetbeast%2Freact-native-dtls/lists"}