The following chart shows the availability of each TLS module API function on each platform.
| Linux (Ubuntu) |
Tizen (Raspberry Pi) |
Raspbian (Raspberry Pi) |
Nuttx (STM32F4-Discovery) |
TizenRT (Artik053) |
|
|---|---|---|---|---|---|
| tls.connect | X | O | O | O | O |
| tls.write | X | O | O | O | O |
| tls.pause | X | O | O | O | O |
| tls.end | X | O | O | O | O |
| tls.resume | X | O | O | O | O |
| tls.pause | X | O | O | O | O |
Transport Layer Security makes secure communication over sockets possible.
The TLSSocket is responsible for all TLS negotiations and data encryption on a net.Socket.
Just like net.Socket it uses a Stream.duplex interface.
socket{net.Socket | stream.Duplex}options{Object}session{Buffer} Optional,Bufferinstance containing a TLS session.
Note: tls.connect() must be used to create the socket.
options{Object}host{string} Host the client should connect to, defaults to 'localhost'.port{number} Port the client should connect to.socket{stream.Duplex} Optional, typically an instance ofnet.Socket. If this options is specified, host and port are ignored. The user passing the options is responsible for it connecting to the server.tls.connectwon't callnet.connecton it.rejectUnauthorized{boolean} Whether the server certificate should be verified against the list of supplied CAs. Anerrorevent is emitted if verifications fails;err.codecontains the MbedTLS error code. Defaults tofalse. NOT READYservername{string} Server name for the SNI (Server name Indication) TLS extension. NOT READYsession{Buffer} ABuffercontaining a TLS session. NOT READYminDHSize{number} The minimum size of the DH parameter in bits to accept a TLS connection. If a server offers a DH parameter with a size less than specified, the TLS connection is destroyed and an error is thrown. Defaults to1024.lookup{Function} Custom lookup. Defaults todns.lookup().
callback{Function} The callback function will be added as a listener for thesecureConnectevent.
Returns a tls.TLSSocket object.
Example
var tls = require('tls');
var opts = {
host: '127.0.0.1',
port: 443,
rejectUnauthorized: true
}
var socket = tls.connect(opts, function() {
socket.write('Hello IoT.js');
socket.end();
});port{number} Port the client should connect to.host{string} Host the client should connect to, defaults to 'localhost'.options{Object} Seetls.connect().callback{Function} Seetls.connect().
Same as tls.connect() except that port and host can be provided as arguments instead of options. A port or host option, if specified, will take precedence over any port or host argument.
Example
var tls = require('tls');
var socket = tls.connect(443, 'localhost', function() {
socket.write('Hello IoT.js');
socket.end();
});Returns an object containing the bound address, family name, and port of the socket.{port: 443, family: 'IPv4', address: '127.0.0.1'}
Returns the reason why the peer's certificate has not been verified.
Returns true if the peer certificate was signed by one of the CAs specified when creating the tls.TLSSocket instance, otherwise false.
Always returns true, can be used to distinguish TLS sockets from regular net.Sockets.
Returns a string containing the negotiated SSL/TLS protocol version of the connection. If the handshaking has not been complete, unknown will be returned. The value null will be returned for server sockets or disconnected client sockets.
Returns a string representing the local IP address.
Returns a number representing the local port.
Returns a string representing the remote IP address.
Returns a string representing the remote IP family.
Returns a number representing the remote port.