Upgrade a regular <code>net.Stream</code> connection to a secure <code>tls</code> connection.
This library has one method and accepts either an options hash or a prepared socket as the first argument. It returns a
The following options are supported:
socket- if not provided, a socket will be created using
host- used to perform automatic certificate identity checking, to guard against MITM attacks
port- only used to create a socket (along with the
socketis not provided
pair- if you want to provide your own
onSecure callback is optional and receives
null or an error object as the first argument (see below for error cases). Within the callback context,
this refers to the same
SecurePair object returned by
var net = ;var starttls = ;var options =port: 21host: examplecom;net;
You should always check for an error before writing to the stream to avoid man-in-the-middle attacks. Errors are produced in the following cases:
If you only pass a socket object, server identity checking will not be performed automatically. In that case you should perform the check manually.
See socks5-https-client for use-case.
make test or
npm test to run tests.
Portions of this code copyright (c) 2012, Andris Reinman and copyright (c) 2011, Nathan Rajlich.
Modified and redistributed under an MIT license.