Namespace node.tls
Use require('tls')
to access this module.
The tls
module uses OpenSSL to provide Transport Layer Security and/or
Secure Socket Layer: encrypted stream communication.
TLS/SSL is a public/private key infrastructure. Each client and each
server must have a private key. A private key is created like this
openssl genrsa -out ryans-key.pem 1024All severs and some clients need to have a certificate. Certificates are public keys signed by a Certificate Authority or self-signed. The first step to getting a certificate is to create a "Certificate Signing Request" (CSR) file. This is done with:
openssl req -new -key ryans-key.pem -out ryans-csr.pemTo create a self-signed certificate with the CSR, do this:
openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pemAlternatively you can send the CSR to a Certificate Authority for signing. (TODO: docs on creating a CA, for now interested users should just look at
test/fixtures/keys/Makefile
in the Node source code)
- Defined in: node.tls.js
Method Summary
Method Attributes | Method Name and Description |
---|---|
static |
node.tls.connect(port, options, cb)
Creates a new client connection to the given
port and host . |
static |
node.tls.createSecurePair(credentials, isServer, requestCert, rejectUnauthorized)
|
static |
node.tls.createServer(options, listener)
|
Method Detail
-
static node.tls.connect(port, options, cb)Creates a new client connection to the given
port
andhost
. (Ifhost
defaults tolocalhost
.)options
should be an object which specifies -key
: A string orBuffer
containing the private key of the server in PEM format. (Required) -cert
: A string orBuffer
containing the certificate key of the server in PEM format. -ca
: An array of strings orBuffer
s of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. These are used to authorize connections.tls.connect()
returns a cleartextCryptoStream
object. After the TLS/SSL handshake thecallback
is called. Thecallback
will be called no matter if the server's certificate was authorized or not. It is up to the user to tests.authorized
to see if the server certificate was signed by one of the specified CAs. Ifs.authorized === false
then the error can be found ins.authorizationError
.- Parameters:
- {string} port
- {Object} options
- {function(Error?|...[*]):undefined=} cb
-
static node.tls.createSecurePair(credentials, isServer, requestCert, rejectUnauthorized)
- Parameters:
- {string} credentials
- {boolean} isServer
- {string} requestCert
- {string} rejectUnauthorized
-
static node.tls.createServer(options, listener)
- Parameters:
- {Object} options
- {string} listener