{ "source": "doc/api/tls.markdown", "modules": [ { "textRaw": "TLS (SSL)", "name": "tls_(ssl)", "stability": 2, "stabilityText": "Stable", "desc": "
Use require('tls')
to access this module.\n\n
The tls
module uses OpenSSL to provide Transport Layer Security and/or\nSecure Socket Layer: encrypted stream communication.\n\n
TLS/SSL is a public/private key infrastructure. Each client and each\nserver must have a private key. A private key is created like this:\n\n
\nopenssl genrsa -out ryans-key.pem 2048
\nAll servers and some clients need to have a certificate. Certificates are public\nkeys signed by a Certificate Authority or self-signed. The first step to\ngetting a certificate is to create a "Certificate Signing Request" (CSR)\nfile. This is done with:\n\n
\nopenssl req -new -sha256 -key ryans-key.pem -out ryans-csr.pem
\nTo create a self-signed certificate with the CSR, do this:\n\n
\nopenssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem
\nAlternatively you can send the CSR to a Certificate Authority for signing.\n\n
\nFor Perfect Forward Secrecy, it is required to generate Diffie-Hellman\nparameters:\n\n
\nopenssl dhparam -outform PEM -out dhparam.pem 2048
\nTo create .pfx or .p12, do this:\n\n
\nopenssl pkcs12 -export -in agent5-cert.pem -inkey agent5-key.pem \\\n -certfile ca-cert.pem -out agent5.pfx
\nin
: certificateinkey
: private keycertfile
: all CA certs concatenated in one file like\ncat ca1-cert.pem ca2-cert.pem > ca-cert.pem
The TLS protocol lets the client renegotiate certain aspects of the TLS session.\nUnfortunately, session renegotiation requires a disproportional amount of\nserver-side resources, which makes it a potential vector for denial-of-service\nattacks.\n\n
\nTo mitigate this, renegotiations are limited to three times every 10 minutes. An\nerror is emitted on the [tls.TLSSocket][] instance when the threshold is\nexceeded. The limits are configurable:\n\n
\ntls.CLIENT_RENEG_LIMIT
: renegotiation limit, default is 3.
tls.CLIENT_RENEG_WINDOW
: renegotiation window in seconds, default is\n10 minutes.
Don't change the defaults unless you know what you are doing.\n\n
\nTo test your server, connect to it with openssl s_client -connect address:port
\nand tap R<CR>
(that's the letter R
followed by a carriage return) a few\ntimes.\n\n\n
NPN (Next Protocol Negotiation) and SNI (Server Name Indication) are TLS\nhandshake extensions allowing you:\n\n
\nThe term "[Forward Secrecy]" or "Perfect Forward Secrecy" describes a feature of\nkey-agreement (i.e. key-exchange) methods. Practically it means that even if the\nprivate key of a (your) server is compromised, communication can only be\ndecrypted by eavesdroppers if they manage to obtain the key-pair specifically\ngenerated for each session.\n\n
\nThis is achieved by randomly generating a key pair for key-agreement on every\nhandshake (in contrary to the same key for all sessions). Methods implementing\nthis technique, thus offering Perfect Forward Secrecy, are called "ephemeral".\n\n
\nCurrently two methods are commonly used to achieve Perfect Forward Secrecy (note\nthe character "E" appended to the traditional abbreviations):\n\n
\nEphemeral methods may have some performance drawbacks, because key generation\nis expensive.\n\n\n
\n" } ], "modules": [ { "textRaw": "Modifying the Default TLS Cipher suite", "name": "modifying_the_default_tls_cipher_suite", "desc": "Node.js is built with a default suite of enabled and disabled TLS ciphers.\nCurrently, the default cipher suite is:\n\n
\nECDHE-RSA-AES128-GCM-SHA256:\nECDHE-ECDSA-AES128-GCM-SHA256:\nECDHE-RSA-AES256-GCM-SHA384:\nECDHE-ECDSA-AES256-GCM-SHA384:\nDHE-RSA-AES128-GCM-SHA256:\nECDHE-RSA-AES128-SHA256:\nDHE-RSA-AES128-SHA256:\nECDHE-RSA-AES256-SHA384:\nDHE-RSA-AES256-SHA384:\nECDHE-RSA-AES256-SHA256:\nDHE-RSA-AES256-SHA256:\nHIGH:\n!aNULL:\n!eNULL:\n!EXPORT:\n!DES:\n!RC4:\n!MD5:\n!PSK:\n!SRP:\n!CAMELLIA
\nThis default can be overriden entirely using the --tls-cipher-list
command\nline switch. For instance, the following makes\nECDHE-RSA-AES128-GCM-SHA256:!RC4
the default TLS cipher suite:\n\n
node --tls-cipher-list="ECDHE-RSA-AES128-GCM-SHA256:!RC4"
\nNote that the default cipher suite included within Node.js has been carefully\nselected to reflect current security best practices and risk mitigation.\nChanging the default cipher suite can have a significant impact on the security\nof an application. The --tls-cipher-list
switch should by used only if\nabsolutely necessary.\n\n
Returns an array with the names of the supported SSL ciphers.\n\n
\nExample:\n\n
\nvar ciphers = tls.getCiphers();\nconsole.log(ciphers); // ['AES128-SHA', 'AES256-SHA', ...]
\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "tls.createServer(options[, secureConnectionListener])",
"type": "method",
"name": "createServer",
"desc": "Creates a new [tls.Server][]. The connectionListener
argument is\nautomatically set as a listener for the [secureConnection][] event. The\noptions
object has these possibilities:\n\n
pfx
: A string or Buffer
containing the private key, certificate and\nCA certs of the server in PFX or PKCS12 format. (Mutually exclusive with\nthe key
, cert
and ca
options.)
key
: A string or Buffer
containing the private key of the server in\nPEM format. (Could be an array of keys). (Required)
passphrase
: A string of passphrase for the private key or pfx.
cert
: A string or Buffer
containing the certificate key of the server in\nPEM format. (Could be an array of certs). (Required)
ca
: An array of strings or Buffer
s of trusted certificates in PEM\nformat. If this is omitted several well known "root" CAs will be used,\nlike VeriSign. These are used to authorize connections.
crl
: Either a string or list of strings of PEM encoded CRLs (Certificate\nRevocation List)
ciphers
: A string describing the ciphers to use or exclude, separated by\n:
. The default cipher suite is:
ECDHE-RSA-AES128-GCM-SHA256:\nECDHE-ECDSA-AES128-GCM-SHA256:\nECDHE-RSA-AES256-GCM-SHA384:\nECDHE-ECDSA-AES256-GCM-SHA384:\nDHE-RSA-AES128-GCM-SHA256:\nECDHE-RSA-AES128-SHA256:\nDHE-RSA-AES128-SHA256:\nECDHE-RSA-AES256-SHA384:\nDHE-RSA-AES256-SHA384:\nECDHE-RSA-AES256-SHA256:\nDHE-RSA-AES256-SHA256:\nHIGH:\n!aNULL:\n!eNULL:\n!EXPORT:\n!DES:\n!RC4:\n!MD5:\n!PSK:\n!SRP:\n!CAMELLIA
\nThe default cipher suite prefers GCM ciphers for [Chrome's 'modern\ncryptography' setting] and also prefers ECDHE and DHE ciphers for Perfect\nForward secrecy, while offering some backward compatibiltity.
\n128 bit AES is preferred over 192 and 256 bit AES in light of [specific\nattacks affecting larger AES key sizes].
\nOld clients that rely on insecure and deprecated RC4 or DES-based ciphers\n(like Internet Explorer 6) aren't able to complete the handshake with the default\nconfiguration. If you absolutely must support these clients, the\n[TLS recommendations] may offer a compatible cipher suite. For more details\non the format, see the [OpenSSL cipher list format documentation].
\necdhCurve
: A string describing a named curve to use for ECDH key agreement\nor false to disable ECDH.
Defaults to prime256v1
(NIST P-256). Use [crypto.getCurves()][] to obtain\na list of available curve names. On recent releases,\nopenssl ecparam -list_curves
will also display the name and description of\neach available elliptic curve.
dhparam
: A string or Buffer
containing Diffie Hellman parameters,\nrequired for Perfect Forward Secrecy. Use openssl dhparam
to create it.\nIts key length should be greater than or equal to 1024 bits, otherwise\nit throws an error. It is strongly recommended to use 2048 bits or\nmore for stronger security. If omitted or invalid, it is silently\ndiscarded and DHE ciphers won't be available.
handshakeTimeout
: Abort the connection if the SSL/TLS handshake does not\nfinish in this many milliseconds. The default is 120 seconds.
A 'clientError'
is emitted on the tls.Server
object whenever a handshake\ntimes out.
honorCipherOrder
: When choosing a cipher, use the server's preferences\ninstead of the client preferences. Default: true
.
requestCert
: If true
the server will request a certificate from\nclients that connect and attempt to verify that certificate. Default:\nfalse
.
rejectUnauthorized
: If true
the server will reject any connection\nwhich is not authorized with the list of supplied CAs. This option only\nhas an effect if requestCert
is true
. Default: false
.
NPNProtocols
: An array or Buffer
of possible NPN protocols. (Protocols\nshould be ordered by their priority).
SNICallback(servername, cb)
: A function that will be called if client\nsupports SNI TLS extension. Two argument will be passed to it: servername
,\nand cb
. SNICallback
should invoke cb(null, ctx)
, where ctx
is a\nSecureContext instance.\n(You can use tls.createSecureContext(...)
to get proper\nSecureContext). If SNICallback
wasn't provided - default callback with\nhigh-level API will be used (see below).
sessionTimeout
: An integer specifying the seconds after which TLS\nsession identifiers and TLS session tickets created by the server are\ntimed out. See [SSL_CTX_set_timeout] for more details.
ticketKeys
: A 48-byte Buffer
instance consisting of 16-byte prefix,\n16-byte hmac key, 16-byte AES key. You could use it to accept tls session\ntickets on multiple instances of tls server.
NOTE: Automatically shared between cluster
module workers.
sessionIdContext
: A string containing an opaque identifier for session\nresumption. If requestCert
is true
, the default is MD5 hash value\ngenerated from command-line. Otherwise, the default is not provided.
secureProtocol
: The SSL method to use, e.g. SSLv3_method
to force\nSSL version 3. The possible values depend on your installation of\nOpenSSL and are defined in the constant [SSL_METHODS][].
Here is a simple example echo server:\n\n
\nvar tls = require('tls');\nvar fs = require('fs');\n\nvar options = {\n key: fs.readFileSync('server-key.pem'),\n cert: fs.readFileSync('server-cert.pem'),\n\n // This is necessary only if using the client certificate authentication.\n requestCert: true,\n\n // This is necessary only if the client uses the self-signed certificate.\n ca: [ fs.readFileSync('client-cert.pem') ]\n};\n\nvar server = tls.createServer(options, function(socket) {\n console.log('server connected',\n socket.authorized ? 'authorized' : 'unauthorized');\n socket.write("welcome!\\n");\n socket.setEncoding('utf8');\n socket.pipe(socket);\n});\nserver.listen(8000, function() {\n console.log('server bound');\n});
\nOr\n\n
\nvar tls = require('tls');\nvar fs = require('fs');\n\nvar options = {\n pfx: fs.readFileSync('server.pfx'),\n\n // This is necessary only if using the client certificate authentication.\n requestCert: true,\n\n};\n\nvar server = tls.createServer(options, function(socket) {\n console.log('server connected',\n socket.authorized ? 'authorized' : 'unauthorized');\n socket.write("welcome!\\n");\n socket.setEncoding('utf8');\n socket.pipe(socket);\n});\nserver.listen(8000, function() {\n console.log('server bound');\n});
\nYou can test this server by connecting to it with openssl s_client
:\n\n\n
openssl s_client -connect 127.0.0.1:8000
\n",
"signatures": [
{
"params": [
{
"name": "options"
},
{
"name": "secureConnectionListener",
"optional": true
}
]
}
]
},
{
"textRaw": "tls.connect(options[, callback])",
"type": "method",
"name": "connect",
"desc": "Creates a new client connection to the given port
and host
(old API) or\noptions.port
and options.host
. (If host
is omitted, it defaults to\nlocalhost
.) options
should be an object which specifies:\n\n
host
: Host the client should connect to
port
: Port the client should connect to
socket
: Establish secure connection on a given socket rather than\ncreating a new socket. If this option is specified, host
and port
\nare ignored.
path
: Creates unix socket connection to path. If this option is\nspecified, host
and port
are ignored.
pfx
: A string or Buffer
containing the private key, certificate and\nCA certs of the client in PFX or PKCS12 format.
key
: A string or Buffer
containing the private key of the client in\nPEM format. (Could be an array of keys).
passphrase
: A string of passphrase for the private key or pfx.
cert
: A string or Buffer
containing the certificate key of the client in\nPEM format. (Could be an array of certs).
ca
: An array of strings or Buffer
s of trusted certificates in PEM\nformat. If this is omitted several well known "root" CAs will be used,\nlike VeriSign. These are used to authorize connections.
ciphers
: A string describing the ciphers to use or exclude, separated by\n:
. Uses the same default cipher suite as tls.createServer
.
rejectUnauthorized
: If true
, the server certificate is verified against\nthe list of supplied CAs. An 'error'
event is emitted if verification\nfails; err.code
contains the OpenSSL error code. Default: true
.
NPNProtocols
: An array of strings or Buffer
s containing supported NPN\nprotocols. Buffer
s should have following format: 0x05hello0x05world
,\nwhere first byte is next protocol name's length. (Passing array should\nusually be much simpler: ['hello', 'world']
.)
servername
: Servername for SNI (Server Name Indication) TLS extension.
checkServerIdentity(servername, cert)
: Provide an override for checking\nserver's hostname against the certificate. Should return an error if verification\nfails. Return undefined
if passing.
secureProtocol
: The SSL method to use, e.g. SSLv3_method
to force\nSSL version 3. The possible values depend on your installation of\nOpenSSL and are defined in the constant [SSL_METHODS][].
session
: A Buffer
instance, containing TLS session.
The callback
parameter will be added as a listener for the\n['secureConnect'][] event.\n\n
tls.connect()
returns a [tls.TLSSocket][] object.\n\n
Here is an example of a client of echo server as described previously:\n\n
\nvar tls = require('tls');\nvar fs = require('fs');\n\nvar options = {\n // These are necessary only if using the client certificate authentication\n key: fs.readFileSync('client-key.pem'),\n cert: fs.readFileSync('client-cert.pem'),\n\n // This is necessary only if the server uses the self-signed certificate\n ca: [ fs.readFileSync('server-cert.pem') ]\n};\n\nvar socket = tls.connect(8000, options, function() {\n console.log('client connected',\n socket.authorized ? 'authorized' : 'unauthorized');\n process.stdin.pipe(socket);\n process.stdin.resume();\n});\nsocket.setEncoding('utf8');\nsocket.on('data', function(data) {\n console.log(data);\n});\nsocket.on('end', function() {\n server.close();\n});
\nOr\n\n
\nvar tls = require('tls');\nvar fs = require('fs');\n\nvar options = {\n pfx: fs.readFileSync('client.pfx')\n};\n\nvar socket = tls.connect(8000, options, function() {\n console.log('client connected',\n socket.authorized ? 'authorized' : 'unauthorized');\n process.stdin.pipe(socket);\n process.stdin.resume();\n});\nsocket.setEncoding('utf8');\nsocket.on('data', function(data) {\n console.log(data);\n});\nsocket.on('end', function() {\n server.close();\n});
\n",
"signatures": [
{
"params": [
{
"name": "port"
},
{
"name": "host",
"optional": true
},
{
"name": "options",
"optional": true
},
{
"name": "callback",
"optional": true
}
]
},
{
"params": [
{
"name": "options"
},
{
"name": "callback",
"optional": true
}
]
}
]
},
{
"textRaw": "tls.connect(port[, host][, options][, callback])",
"type": "method",
"name": "connect",
"desc": "Creates a new client connection to the given port
and host
(old API) or\noptions.port
and options.host
. (If host
is omitted, it defaults to\nlocalhost
.) options
should be an object which specifies:\n\n
host
: Host the client should connect to
port
: Port the client should connect to
socket
: Establish secure connection on a given socket rather than\ncreating a new socket. If this option is specified, host
and port
\nare ignored.
path
: Creates unix socket connection to path. If this option is\nspecified, host
and port
are ignored.
pfx
: A string or Buffer
containing the private key, certificate and\nCA certs of the client in PFX or PKCS12 format.
key
: A string or Buffer
containing the private key of the client in\nPEM format. (Could be an array of keys).
passphrase
: A string of passphrase for the private key or pfx.
cert
: A string or Buffer
containing the certificate key of the client in\nPEM format. (Could be an array of certs).
ca
: An array of strings or Buffer
s of trusted certificates in PEM\nformat. If this is omitted several well known "root" CAs will be used,\nlike VeriSign. These are used to authorize connections.
ciphers
: A string describing the ciphers to use or exclude, separated by\n:
. Uses the same default cipher suite as tls.createServer
.
rejectUnauthorized
: If true
, the server certificate is verified against\nthe list of supplied CAs. An 'error'
event is emitted if verification\nfails; err.code
contains the OpenSSL error code. Default: true
.
NPNProtocols
: An array of strings or Buffer
s containing supported NPN\nprotocols. Buffer
s should have following format: 0x05hello0x05world
,\nwhere first byte is next protocol name's length. (Passing array should\nusually be much simpler: ['hello', 'world']
.)
servername
: Servername for SNI (Server Name Indication) TLS extension.
checkServerIdentity(servername, cert)
: Provide an override for checking\nserver's hostname against the certificate. Should return an error if verification\nfails. Return undefined
if passing.
secureProtocol
: The SSL method to use, e.g. SSLv3_method
to force\nSSL version 3. The possible values depend on your installation of\nOpenSSL and are defined in the constant [SSL_METHODS][].
session
: A Buffer
instance, containing TLS session.
The callback
parameter will be added as a listener for the\n['secureConnect'][] event.\n\n
tls.connect()
returns a [tls.TLSSocket][] object.\n\n
Here is an example of a client of echo server as described previously:\n\n
\nvar tls = require('tls');\nvar fs = require('fs');\n\nvar options = {\n // These are necessary only if using the client certificate authentication\n key: fs.readFileSync('client-key.pem'),\n cert: fs.readFileSync('client-cert.pem'),\n\n // This is necessary only if the server uses the self-signed certificate\n ca: [ fs.readFileSync('server-cert.pem') ]\n};\n\nvar socket = tls.connect(8000, options, function() {\n console.log('client connected',\n socket.authorized ? 'authorized' : 'unauthorized');\n process.stdin.pipe(socket);\n process.stdin.resume();\n});\nsocket.setEncoding('utf8');\nsocket.on('data', function(data) {\n console.log(data);\n});\nsocket.on('end', function() {\n server.close();\n});
\nOr\n\n
\nvar tls = require('tls');\nvar fs = require('fs');\n\nvar options = {\n pfx: fs.readFileSync('client.pfx')\n};\n\nvar socket = tls.connect(8000, options, function() {\n console.log('client connected',\n socket.authorized ? 'authorized' : 'unauthorized');\n process.stdin.pipe(socket);\n process.stdin.resume();\n});\nsocket.setEncoding('utf8');\nsocket.on('data', function(data) {\n console.log(data);\n});\nsocket.on('end', function() {\n server.close();\n});
\n",
"signatures": [
{
"params": [
{
"name": "port"
},
{
"name": "host",
"optional": true
},
{
"name": "options",
"optional": true
},
{
"name": "callback",
"optional": true
}
]
}
]
},
{
"textRaw": "new tls.TLSSocket(socket, options)",
"type": "method",
"name": "TLSSocket",
"desc": "Construct a new TLSSocket object from existing TCP socket.\n\n
\nsocket
is an instance of [net.Socket][]\n\n
options
is an object that might contain following properties:\n\n
secureContext
: An optional TLS context object from\n tls.createSecureContext( ... )
isServer
: If true - TLS socket will be instantiated in server-mode
server
: An optional [net.Server][] instance
requestCert
: Optional, see [tls.createSecurePair][]
rejectUnauthorized
: Optional, see [tls.createSecurePair][]
NPNProtocols
: Optional, see [tls.createServer][]
SNICallback
: Optional, see [tls.createServer][]
session
: Optional, a Buffer
instance, containing TLS session
requestOCSP
: Optional, if true
- OCSP status request extension would\nbe added to client hello, and OCSPResponse
event will be emitted on socket\nbefore establishing secure communication
Creates a credentials object, with the optional details being a\ndictionary with keys:\n\n
\npfx
: A string or buffer holding the PFX or PKCS12 encoded private\nkey, certificate and CA certificateskey
: A string holding the PEM encoded private keypassphrase
: A string of passphrase for the private key or pfxcert
: A string holding the PEM encoded certificateca
: Either a string or list of strings of PEM encoded CA\ncertificates to trust.crl
: Either a string or list of strings of PEM encoded CRLs\n(Certificate Revocation List)ciphers
: A string describing the ciphers to use or exclude.\nConsult\nhttp://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT\nfor details on the format.honorCipherOrder
: When choosing a cipher, use the server's preferences\ninstead of the client preferences. For further details see tls
module\ndocumentation.If no 'ca' details are given, then Node.js will use the default\npublicly trusted list of CAs as given in\n
\nhttp://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt.\n\n\n
\n", "signatures": [ { "params": [ { "name": "details" } ] } ] }, { "textRaw": "tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized])", "type": "method", "name": "createSecurePair", "desc": "Creates a new secure pair object with two streams, one of which reads/writes\nencrypted data, and one reads/writes cleartext data.\nGenerally the encrypted one is piped to/from an incoming encrypted data stream,\nand the cleartext one is used as a replacement for the initial encrypted stream.\n\n
\ncredentials
: A secure context object from tls.createSecureContext( ... )
isServer
: A boolean indicating whether this tls connection should be\nopened as a server or a client.
requestCert
: A boolean indicating whether a server should request a\ncertificate from a connecting client. Only applies to server connections.
rejectUnauthorized
: A boolean indicating whether a server should\nautomatically reject clients with invalid certificates. Only applies to\nservers with requestCert
enabled.
tls.createSecurePair()
returns a SecurePair object with cleartext
and\nencrypted
stream properties.\n\n
NOTE: cleartext
has the same APIs as [tls.TLSSocket][]\n\n
Wrapper for instance of [net.Socket][], replaces internal socket read/write\nroutines to perform transparent encryption/decryption of incoming/outgoing data.\n\n
\n" }, { "textRaw": "Class: SecurePair", "type": "class", "name": "SecurePair", "desc": "Returned by tls.createSecurePair.\n\n
\n", "events": [ { "textRaw": "Event: 'secure'", "type": "event", "name": "secure", "desc": "The event is emitted from the SecurePair once the pair has successfully\nestablished a secure connection.\n\n
\nSimilarly to the checking for the server 'secureConnection' event,\npair.cleartext.authorized should be checked to confirm whether the certificate\nused properly authorized.\n\n
\n", "params": [] } ] }, { "textRaw": "Class: tls.Server", "type": "class", "name": "tls.Server", "desc": "This class is a subclass of net.Server
and has the same methods on it.\nInstead of accepting just raw TCP connections, this accepts encrypted\nconnections using TLS or SSL.\n\n
function (tlsSocket) {}
\n\n
This event is emitted after a new connection has been successfully\nhandshaked. The argument is an instance of [tls.TLSSocket][]. It has all the\ncommon stream methods and events.\n\n
\nsocket.authorized
is a boolean value which indicates if the\nclient has verified by one of the supplied certificate authorities for the\nserver. If socket.authorized
is false, then\nsocket.authorizationError
is set to describe how authorization\nfailed. Implied but worth mentioning: depending on the settings of the TLS\nserver, you unauthorized connections may be accepted.\nsocket.npnProtocol
is a string containing selected NPN protocol.\nsocket.servername
is a string containing servername requested with\nSNI.\n\n\n
function (exception, tlsSocket) { }
\n\n
When a client connection emits an 'error' event before secure connection is\nestablished - it will be forwarded here.\n\n
\ntlsSocket
is the [tls.TLSSocket][] that the error originated from.\n\n\n
function (sessionId, sessionData, callback) { }
\n\n
Emitted on creation of TLS session. May be used to store sessions in external\nstorage. callback
must be invoked eventually, otherwise no data will be\nsent or received from secure connection.\n\n
NOTE: adding this event listener will have an effect only on connections\nestablished after addition of event listener.\n\n\n
\n", "params": [] }, { "textRaw": "Event: 'resumeSession'", "type": "event", "name": "resumeSession", "desc": "function (sessionId, callback) { }
\n\n
Emitted when client wants to resume previous TLS session. Event listener may\nperform lookup in external storage using given sessionId
, and invoke\ncallback(null, sessionData)
once finished. If session can't be resumed\n(i.e. doesn't exist in storage) one may call callback(null, null)
. Calling\ncallback(err)
will terminate incoming connection and destroy socket.\n\n
NOTE: adding this event listener will have an effect only on connections\nestablished after addition of event listener.\n\n\n
\n", "params": [] }, { "textRaw": "Event: 'OCSPRequest'", "type": "event", "name": "OCSPRequest", "desc": "function (certificate, issuer, callback) { }
\n\n
Emitted when the client sends a certificate status request. You could parse\nserver's current certificate to obtain OCSP url and certificate id, and after\nobtaining OCSP response invoke callback(null, resp)
, where resp
is a\nBuffer
instance. Both certificate
and issuer
are a Buffer
\nDER-representations of the primary and issuer's certificates. They could be used\nto obtain OCSP certificate id and OCSP endpoint url.\n\n
Alternatively, callback(null, null)
could be called, meaning that there is no\nOCSP response.\n\n
Calling callback(err)
will result in a socket.destroy(err)
call.\n\n
Typical flow:\n\n
\nOCSPRequest
to it (via status info\nextension in ClientHello.)OCSPRequest
event listener if presentcertificate
or issuer
and performs an\n[OCSP request] to the CAOCSPResponse
from CA and sends it back to client via\ncallback
argumentNOTE: issuer
could be null, if the certificate is self-signed or if the issuer\nis not in the root certificates list. (You could provide an issuer via ca
\noption.)\n\n
NOTE: adding this event listener will have an effect only on connections\nestablished after addition of event listener.\n\n
\nNOTE: you may want to use some npm module like [asn1.js] to parse the\ncertificates.\n\n\n
\n", "params": [] } ], "methods": [ { "textRaw": "server.listen(port[, hostname][, callback])", "type": "method", "name": "listen", "desc": "Begin accepting connections on the specified port
and hostname
. If the\nhostname
is omitted, the server will accept connections on any IPv6 address\n(::
) when IPv6 is available, or any IPv4 address (0.0.0.0
) otherwise. A\nport value of zero will assign a random port.\n\n
This function is asynchronous. The last parameter callback
will be called\nwhen the server has been bound.\n\n
See net.Server
for more information.\n\n\n
Stops the server from accepting new connections. This function is\nasynchronous, the server is finally closed when the server emits a 'close'
\nevent. Optionally, you can pass a callback to listen for the 'close'
event.\n\n
Returns the bound address, the address family name and port of the\nserver as reported by the operating system. See [net.Server.address()][] for\nmore information.\n\n
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "server.getTicketKeys()", "type": "method", "name": "getTicketKeys", "desc": "Returns Buffer
instance holding the keys currently used for\nencryption/decryption of the [TLS Session Tickets][]\n\n
Updates the keys for encryption/decryption of the [TLS Session Tickets][].\n\n
\nNOTE: the buffer should be 48 bytes long. See server ticketKeys
option for\nmore information oh how it is going to be used.\n\n
NOTE: the change is effective only for the future server connections. Existing\nor currently pending server connections will use previous keys.\n\n
\n", "signatures": [ { "params": [ { "name": "keys" } ] } ] }, { "textRaw": "server.addContext(hostname, context)", "type": "method", "name": "addContext", "desc": "Add secure context that will be used if client request's SNI hostname is\nmatching passed hostname
(wildcards can be used). context
can contain\nkey
, cert
, ca
and/or any other properties from tls.createSecureContext
\noptions
argument.\n\n
Set this property to reject connections when the server's connection count\ngets high.\n\n
\n" }, { "textRaw": "server.connections", "name": "connections", "desc": "The number of concurrent connections on the server.\n\n\n
\n" } ] }, { "textRaw": "Class: CryptoStream", "type": "class", "name": "CryptoStream", "stability": 0, "stabilityText": "Deprecated: Use [tls.TLSSocket][] instead.", "desc": "This is an encrypted stream.\n\n
\n", "properties": [ { "textRaw": "cryptoStream.bytesWritten", "name": "bytesWritten", "desc": "A proxy to the underlying socket's bytesWritten accessor, this will return\nthe total bytes written to the socket, including the TLS overhead.\n\n
\n" } ] }, { "textRaw": "Class: tls.TLSSocket", "type": "class", "name": "tls.TLSSocket", "desc": "This is a wrapped version of [net.Socket][] that does transparent encryption\nof written data and all required TLS negotiation.\n\n
\nThis instance implements a duplex [Stream][] interfaces. It has all the\ncommon stream methods and events.\n\n
\n", "events": [ { "textRaw": "Event: 'secureConnect'", "type": "event", "name": "secureConnect", "desc": "This event is emitted after a new connection has been successfully handshaked.\nThe listener will be called no matter if the server's certificate was\nauthorized or not. It is up to the user to test tlsSocket.authorized
\nto see if the server certificate was signed by one of the specified CAs.\nIf tlsSocket.authorized === false
then the error can be found in\ntlsSocket.authorizationError
. Also if NPN was used - you can check\ntlsSocket.npnProtocol
for negotiated protocol.\n\n
function (response) { }
\n\n
This event will be emitted if requestOCSP
option was set. response
is a\nbuffer object, containing server's OCSP response.\n\n
Traditionally, the response
is a signed object from the server's CA that\ncontains information about server's certificate revocation status.\n\n
Static boolean value, always true
. May be used to distinguish TLS sockets\nfrom regular ones.\n\n
A boolean that is true
if the peer certificate was signed by one of the\nspecified CAs, otherwise false
\n\n
The reason why the peer's certificate has not been verified. This property\nbecomes available only when tlsSocket.authorized === false
.\n\n
The string representation of the remote IP address. For example,\n'74.125.127.100'
or '2001:4860:a005::68'
.\n\n
The string representation of the remote IP family. 'IPv4'
or 'IPv6'
.\n\n
The numeric representation of the remote port. For example, 443
.\n\n
The string representation of the local IP address.\n\n
\n" }, { "textRaw": "tlsSocket.localPort", "name": "localPort", "desc": "The numeric representation of the local port.\n\n
\n" } ], "methods": [ { "textRaw": "tlsSocket.getPeerCertificate([ detailed ])", "type": "method", "name": "getPeerCertificate", "desc": "Returns an object representing the peer's certificate. The returned object has\nsome properties corresponding to the field of the certificate. If detailed
\nargument is true
- the full chain with issuer
property will be returned,\nif false
- only the top certificate without issuer
property.\n\n
Example:\n\n
\n{ subject:\n { C: 'UK',\n ST: 'Acknack Ltd',\n L: 'Rhys Jones',\n O: 'node.js',\n OU: 'Test TLS Certificate',\n CN: 'localhost' },\n issuerInfo:\n { C: 'UK',\n ST: 'Acknack Ltd',\n L: 'Rhys Jones',\n O: 'node.js',\n OU: 'Test TLS Certificate',\n CN: 'localhost' },\n issuer:\n { ... another certificate ... },\n raw: < RAW DER buffer >,\n valid_from: 'Nov 11 09:52:22 2009 GMT',\n valid_to: 'Nov 6 09:52:22 2029 GMT',\n fingerprint: '2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF',\n serialNumber: 'B9B0D332A1AA5635' }
\nIf the peer does not provide a certificate, it returns null
or an empty\nobject.\n\n
Returns an object representing the cipher name and the SSL/TLS\nprotocol version of the current connection.\n\n
\nExample:\n{ name: 'AES256-SHA', version: 'TLSv1/SSLv3' }\n\n
\nSee SSL_CIPHER_get_name() and SSL_CIPHER_get_version() in\nhttp://www.openssl.org/docs/ssl/ssl.html#DEALING_WITH_CIPHERS for more\ninformation.\n\n
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "tlsSocket.renegotiate(options, callback)", "type": "method", "name": "renegotiate", "desc": "Initiate TLS renegotiation process. The options
may contain the following\nfields: rejectUnauthorized
, requestCert
(See [tls.createServer][]\nfor details). callback(err)
will be executed with null
as err
,\nonce the renegotiation is successfully completed.\n\n
NOTE: Can be used to request peer's certificate after the secure connection\nhas been established.\n\n
\nANOTHER NOTE: When running as the server, socket will be destroyed\nwith an error after handshakeTimeout
timeout.\n\n
Set maximum TLS fragment size (default and maximum value is: 16384
, minimum\nis: 512
). Returns true
on success, false
otherwise.\n\n
Smaller fragment size decreases buffering latency on the client: large\nfragments are buffered by the TLS layer until the entire fragment is received\nand its integrity is verified; large fragments can span multiple roundtrips,\nand their processing can be delayed due to packet loss or reordering. However,\nsmaller fragments add extra TLS framing bytes and CPU overhead, which may\ndecrease overall server throughput.\n\n
\n", "signatures": [ { "params": [ { "name": "size" } ] } ] }, { "textRaw": "tlsSocket.getSession()", "type": "method", "name": "getSession", "desc": "Return ASN.1 encoded TLS session or undefined
if none was negotiated. Could\nbe used to speed up handshake establishment when reconnecting to the server.\n\n
NOTE: Works only with client TLS sockets. Useful only for debugging, for\nsession reuse provide session
option to tls.connect
.\n\n
Return TLS session ticket or undefined
if none was negotiated.\n\n
Returns the bound address, the address family name and port of the\nunderlying socket as reported by the operating system. Returns an\nobject with three properties, e.g.\n{ port: 12346, family: 'IPv4', address: '127.0.0.1' }
\n\n