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 1024
All 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.pem
To create a self-signed certificate with the CSR, do this:
    openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem
Alternatively 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)

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 and host. (If host defaults to localhost.) options should be an object which specifies - key: A string or Buffer containing the private key of the server in PEM format. (Required) - cert: A string or Buffer containing the certificate key of the server in PEM format. - ca: An array of strings or Buffers 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 cleartext CryptoStream object. After the TLS/SSL handshake the callback is called. The callback will be called no matter if the server's certificate was authorized or not. It is up to the user to test s.authorized to see if the server certificate was signed by one of the specified CAs. If s.authorized === false then the error can be found in s.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