{
  "_from": "starttls@0.x",
  "_id": "starttls@0.2.1",
  "_location": "/keybase/socks5-https-client/starttls",
  "_npmUser": {
    "email": "m@m.cg",
    "name": "mcg"
  },
  "_npmVersion": "1.3.8",
  "_phantomChildren": {},
  "_requiredBy": [
    "/keybase/socks5-https-client"
  ],
  "_resolved": "https://registry.npmjs.org/starttls/-/starttls-0.2.1.tgz",
  "_shasum": "b98d3e5e778d46f199c843a64f889f0347c6d19a",
  "_shrinkwrap": null,
  "bugs": {
    "url": "https://github.com/mattcg/starttls/issues"
  },
  "contributors": [
    {
      "name": "Nathan Rajlich",
      "email": "nathan@tootallnate.net"
    },
    {
      "name": "Andris Reinman",
      "email": "andris.reinman@gmail.com"
    },
    {
      "name": "Matthew Caruana Galizia",
      "email": "m@m.cg"
    }
  ],
  "dependencies": {},
  "description": "Upgrade a regular `net.Stream` connection to a secure `tls` connection.",
  "devDependencies": {
    "mocha": "1.x"
  },
  "directories": {},
  "dist": {
    "shasum": "b98d3e5e778d46f199c843a64f889f0347c6d19a",
    "tarball": "http://registry.npmjs.org/starttls/-/starttls-0.2.1.tgz"
  },
  "engines": {
    "node": "0.x"
  },
  "homepage": "https://github.com/mattcg/starttls",
  "implements": [
    "CommonJS/Modules/1.0"
  ],
  "keywords": [
    "net",
    "ssl",
    "stream",
    "tls",
    "upgrade"
  ],
  "licenses": [
    {
      "type": "MIT",
      "url": "http://opensource.org/licenses/MIT"
    }
  ],
  "main": "lib/starttls.js",
  "maintainers": [
    {
      "name": "mcg",
      "email": "m@m.cg"
    }
  ],
  "name": "starttls",
  "optionalDependencies": {},
  "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",
  "readmeFilename": "README.md",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/mattcg/starttls.git"
  },
  "scripts": {
    "test": "make test"
  },
  "version": "0.2.1"
}
