{"name":"starttls","description":"Upgrade a regular `net.Stream` connection to a secure `tls` connection.","version":"0.1.2","main":"index.js","homepage":"https://github.com/mattcg/starttls","implements":["CommonJS/Modules/1.0"],"contributors":[{"name":"Nathan Rajlich","email":"nathan@tootallnate.net"},{"name":"Andris Reinman","email":"andris.reinman@gmail.com"},{"name":"Matthew Caruana Galizia","email":"m@m.cg"}],"keywords":["tls","stream","net","upgrade","ssl"],"bugs":{"url":"https://github.com/mattcg/starttls/issues"},"repositories":[{"type":"git","url":"https://github.com/mattcg/starttls.git"}],"engines":{"node":"0.x"},"licenses":[{"type":"MIT","url":"http://opensource.org/licenses/MIT"}],"_id":"starttls@0.1.2","dist":{"shasum":"2aa307a27ac9e0e50d2d66ff1bfb5efa69ad84ef","tarball":"http://registry-npm.ywwl.com/starttls/download/starttls-0.1.2.tgz","integrity":"sha512-QOaC3V9YBePwoHXq+tBgel0X7uskvKep2bOJryvSgdlwFtFUGFOP+ueFQcIbNqb+RmS9Jcszskw2aAwr0OVlwQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC2MGtT6EpS8IlTqfDb324yLgg3yr2XvyjBb0RzCI0kgAiACNLY8GprTGMHTFugoxWBq069ZJYb7pObn2jU2K6rr6A=="}],"size":2131,"noattachment":false,"key":"/starttls/-/starttls-0.1.2.tgz"},"_from":".","_npmVersion":"1.2.11","_npmUser":{"name":"mcg","email":"m@m.cg"},"maintainers":[{"name":"mcg","email":"m@m.cg"}],"directories":{},"readme":"# Start TLS #\n\n[![Build Status](https://travis-ci.org/mattcg/starttls.png?branch=master)](https://travis-ci.org/mattcg/starttls)\n\nUpgrade a regular [`net.Stream`](http://nodejs.org/api/net.html#net_class_net_socket) connection to a secure [`tls`](http://nodejs.org/api/tls.html) connection.\n\nBased on code by [Andris Reinman](https://github.com/andris9/rai/blob/master/lib/starttls.js), itself based on an older version by [Nathan Rajlich](https://gist.github.com/TooTallNate/848444).\n\n## Usage ##\n\nThis library has one method and accepts either an options hash or a prepared socket as the first argument. It returns a [`SecurePair`](http://nodejs.org/api/tls.html#tls_class_securepair).\n\n### starttls(options, [onSecure]), starttls(socket, [onSecure]) ###\n\nThe following options are supported:\n\n- `socket` - if not provided, a socket will be created using [`net.createConnection`](http://nodejs.org/api/net.html#net_net_createconnection_options_connectionlistener)\n- `host` - used to perform automatic certificate identity checking, to guard against MITM attacks\n- `port` - only used to create a socket (along with the `host` option) if `socket` is not provided\n- `pair` - if you want to provide your own [`SecurePair`](http://nodejs.org/api/tls.html#tls_class_securepair) object\n\nThe `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`](http://nodejs.org/api/tls.html#tls_class_securepair) object returned by `starttls`.\n\n```javascript\nvar net = require('net');\nvar starttls = require('starttls');\nvar options = {\n\tport: 21,\n\thost: example.com\n};\n\nnet.createConnection(options, function() {\n\toptions.socket = this;\n\tstarttls(options, function(err) {\n\t\tif (err) {\n\n\t\t\t// Something bad happened!\n\t\t\treturn;\n\t\t}\n\n\t\tthis.cleartext.write('garbage');\n\t});\n});\n```\n\nYou 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:\n\n- the certificate authority authorization check failed or was negative\n- the server identity check was negative\n\nIf you only pass a socket object, server identity checking will not be performed automatically. In that case you should perform the check manually.\n\n```javascript\nstarttls(socket, function(err) {\n\tif (!tls.checkServerIdentity(host, this.cleartext.getPeerCertificate())) {\n\n\t\t// Hostname mismatch!\n\t\t// Report error and end connection...\n\t}\n});\n```\n\n## Example ##\n\nSee [socks5-https-client](https://github.com/mattcg/socks5-https-client) for use-case.\n\n## Tests ##\n\nRun `make test` or `npm test` to run tests.\n\n## License ##\n\nPortions of this code copyright (c) 2012, Andris Reinman and copyright (c) 2011, Nathan Rajlich.\n\nModified and redistributed under an [MIT license](http://mattcg.mit-license.org/).\n","publish_time":1362704205663,"_cnpm_publish_time":1362704205663,"dist-tags":{"latest":"1.0.1"}}