{ "type": "module", "source": "doc/api/tls.md", "modules": [ { "textRaw": "TLS (SSL)", "name": "tls_(ssl)", "introduced_in": "v0.10.0", "stability": 2, "stabilityText": "Stable", "desc": "

Source Code: lib/tls.js

\n

The tls module provides an implementation of the Transport Layer Security\n(TLS) and Secure Socket Layer (SSL) protocols that is built on top of OpenSSL.\nThe module can be accessed using:

\n
const tls = require('tls');\n
", "modules": [ { "textRaw": "TLS/SSL concepts", "name": "tls/ssl_concepts", "desc": "

The TLS/SSL is a public/private key infrastructure (PKI). For most common\ncases, each client and server must have a private key.

\n

Private keys can be generated in multiple ways. The example below illustrates\nuse of the OpenSSL command-line interface to generate a 2048-bit RSA private\nkey:

\n
openssl genrsa -out ryans-key.pem 2048\n
\n

With TLS/SSL, all servers (and some clients) must have a certificate.\nCertificates are public keys that correspond to a private key, and that are\ndigitally signed either by a Certificate Authority or by the owner of the\nprivate key (such certificates are referred to as \"self-signed\"). The first\nstep to obtaining a certificate is to create a Certificate Signing Request\n(CSR) file.

\n

The OpenSSL command-line interface can be used to generate a CSR for a private\nkey:

\n
openssl req -new -sha256 -key ryans-key.pem -out ryans-csr.pem\n
\n

Once the CSR file is generated, it can either be sent to a Certificate\nAuthority for signing or used to generate a self-signed certificate.

\n

Creating a self-signed certificate using the OpenSSL command-line interface\nis illustrated in the example below:

\n
openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem\n
\n

Once the certificate is generated, it can be used to generate a .pfx or\n.p12 file:

\n
openssl pkcs12 -export -in ryans-cert.pem -inkey ryans-key.pem \\\n      -certfile ca-cert.pem -out ryans.pfx\n
\n

Where:

\n", "miscs": [ { "textRaw": "Perfect forward secrecy", "name": "Perfect forward secrecy", "type": "misc", "desc": "

The term forward secrecy or perfect forward secrecy describes a feature\nof key-agreement (i.e., key-exchange) methods. That is, the server and client\nkeys are used to negotiate new temporary keys that are used specifically and\nonly for the current communication session. Practically, this means that even\nif the server's private key is compromised, communication can only be decrypted\nby eavesdroppers if the attacker manages to obtain the key-pair specifically\ngenerated for the session.

\n

Perfect forward secrecy is achieved by randomly generating a key pair for\nkey-agreement on every TLS/SSL handshake (in contrast to using the same key for\nall sessions). Methods implementing this technique are called \"ephemeral\".

\n

Currently two methods are commonly used to achieve perfect forward secrecy (note\nthe character \"E\" appended to the traditional abbreviations):

\n\n

Ephemeral methods may have some performance drawbacks, because key generation\nis expensive.

\n

To use perfect forward secrecy using DHE with the tls module, it is required\nto generate Diffie-Hellman parameters and specify them with the dhparam\noption to tls.createSecureContext(). The following illustrates the use of\nthe OpenSSL command-line interface to generate such parameters:

\n
openssl dhparam -outform PEM -out dhparam.pem 2048\n
\n

If using perfect forward secrecy using ECDHE, Diffie-Hellman parameters are\nnot required and a default ECDHE curve will be used. The ecdhCurve property\ncan be used when creating a TLS Server to specify the list of names of supported\ncurves to use, see tls.createServer() for more info.

\n

Perfect forward secrecy was optional up to TLSv1.2, but it is not optional for\nTLSv1.3, because all TLSv1.3 cipher suites use ECDHE.

" }, { "textRaw": "ALPN and SNI", "name": "ALPN and SNI", "type": "misc", "desc": "

ALPN (Application-Layer Protocol Negotiation Extension) and\nSNI (Server Name Indication) are TLS handshake extensions:

\n" }, { "textRaw": "Pre-shared keys", "name": "Pre-shared keys", "type": "misc", "desc": "

TLS-PSK support is available as an alternative to normal certificate-based\nauthentication. It uses a pre-shared key instead of certificates to\nauthenticate a TLS connection, providing mutual authentication.\nTLS-PSK and public key infrastructure are not mutually exclusive. Clients and\nservers can accommodate both, choosing either of them during the normal cipher\nnegotiation step.

\n

TLS-PSK is only a good choice where means exist to securely share a\nkey with every connecting machine, so it does not replace PKI\n(Public Key Infrastructure) for the majority of TLS uses.\nThe TLS-PSK implementation in OpenSSL has seen many security flaws in\nrecent years, mostly because it is used only by a minority of applications.\nPlease consider all alternative solutions before switching to PSK ciphers.\nUpon generating PSK it is of critical importance to use sufficient entropy as\ndiscussed in RFC 4086. Deriving a shared secret from a password or other\nlow-entropy sources is not secure.

\n

PSK ciphers are disabled by default, and using TLS-PSK thus requires explicitly\nspecifying a cipher suite with the ciphers option. The list of available\nciphers can be retrieved via openssl ciphers -v 'PSK'. All TLS 1.3\nciphers are eligible for PSK but currently only those that use SHA256 digest are\nsupported they can be retrieved via openssl ciphers -v -s -tls1_3 -psk.

\n

According to the RFC 4279, PSK identities up to 128 bytes in length and\nPSKs up to 64 bytes in length must be supported. As of OpenSSL 1.1.0\nmaximum identity size is 128 bytes, and maximum PSK length is 256 bytes.

\n

The current implementation doesn't support asynchronous PSK callbacks due to the\nlimitations of the underlying OpenSSL API.

" }, { "textRaw": "Client-initiated renegotiation attack mitigation", "name": "Client-initiated renegotiation attack mitigation", "type": "misc", "desc": "

The TLS protocol allows clients to renegotiate certain aspects of the TLS\nsession. Unfortunately, session renegotiation requires a disproportionate amount\nof server-side resources, making it a potential vector for denial-of-service\nattacks.

\n

To mitigate the risk, renegotiation is limited to three times every ten minutes.\nAn 'error' event is emitted on the tls.TLSSocket instance when this\nthreshold is exceeded. The limits are configurable:

\n\n

The default renegotiation limits should not be modified without a full\nunderstanding of the implications and risks.

\n

TLSv1.3 does not support renegotiation.

" } ], "modules": [ { "textRaw": "Session resumption", "name": "session_resumption", "desc": "

Establishing a TLS session can be relatively slow. The process can be sped\nup by saving and later reusing the session state. There are several mechanisms\nto do so, discussed here from oldest to newest (and preferred).

", "modules": [ { "textRaw": "Session identifiers", "name": "session_identifiers", "desc": "

Servers generate a unique ID for new connections and\nsend it to the client. Clients and servers save the session state. When\nreconnecting, clients send the ID of their saved session state and if the server\nalso has the state for that ID, it can agree to use it. Otherwise, the server\nwill create a new session. See RFC 2246 for more information, page 23 and\n30.

\n

Resumption using session identifiers is supported by most web browsers when\nmaking HTTPS requests.

\n

For Node.js, clients wait for the 'session' event to get the session data,\nand provide the data to the session option of a subsequent tls.connect()\nto reuse the session. Servers must\nimplement handlers for the 'newSession' and 'resumeSession' events\nto save and restore the session data using the session ID as the lookup key to\nreuse sessions. To reuse sessions across load balancers or cluster workers,\nservers must use a shared session cache (such as Redis) in their session\nhandlers.

", "type": "module", "displayName": "Session identifiers" }, { "textRaw": "Session tickets", "name": "session_tickets", "desc": "

The servers encrypt the entire session state and send it\nto the client as a \"ticket\". When reconnecting, the state is sent to the server\nin the initial connection. This mechanism avoids the need for server-side\nsession cache. If the server doesn't use the ticket, for any reason (failure\nto decrypt it, it's too old, etc.), it will create a new session and send a new\nticket. See RFC 5077 for more information.

\n

Resumption using session tickets is becoming commonly supported by many web\nbrowsers when making HTTPS requests.

\n

For Node.js, clients use the same APIs for resumption with session identifiers\nas for resumption with session tickets. For debugging, if\ntls.TLSSocket.getTLSTicket() returns a value, the session data contains a\nticket, otherwise it contains client-side session state.

\n

With TLSv1.3, be aware that multiple tickets may be sent by the server,\nresulting in multiple 'session' events, see 'session' for more\ninformation.

\n

Single process servers need no specific implementation to use session tickets.\nTo use session tickets across server restarts or load balancers, servers must\nall have the same ticket keys. There are three 16-byte keys internally, but the\ntls API exposes them as a single 48-byte buffer for convenience.

\n

Its possible to get the ticket keys by calling server.getTicketKeys() on\none server instance and then distribute them, but it is more reasonable to\nsecurely generate 48 bytes of secure random data and set them with the\nticketKeys option of tls.createServer(). The keys should be regularly\nregenerated and server's keys can be reset with\nserver.setTicketKeys().

\n

Session ticket keys are cryptographic keys, and they must be stored\nsecurely. With TLS 1.2 and below, if they are compromised all sessions that\nused tickets encrypted with them can be decrypted. They should not be stored\non disk, and they should be regenerated regularly.

\n

If clients advertise support for tickets, the server will send them. The\nserver can disable tickets by supplying\nrequire('constants').SSL_OP_NO_TICKET in secureOptions.

\n

Both session identifiers and session tickets timeout, causing the server to\ncreate new sessions. The timeout can be configured with the sessionTimeout\noption of tls.createServer().

\n

For all the mechanisms, when resumption fails, servers will create new sessions.\nSince failing to resume the session does not cause TLS/HTTPS connection\nfailures, it is easy to not notice unnecessarily poor TLS performance. The\nOpenSSL CLI can be used to verify that servers are resuming sessions. Use the\n-reconnect option to openssl s_client, for example:

\n
$ openssl s_client -connect localhost:443 -reconnect\n
\n

Read through the debug output. The first connection should say \"New\", for\nexample:

\n
New, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256\n
\n

Subsequent connections should say \"Reused\", for example:

\n
Reused, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256\n
", "type": "module", "displayName": "Session tickets" } ], "type": "module", "displayName": "Session resumption" } ], "type": "module", "displayName": "TLS/SSL concepts" }, { "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. This\ndefault cipher list can be configured when building Node.js to allow\ndistributions to provide their own default list.

\n

The following command can be used to show the default cipher suite:

\n
node -p crypto.constants.defaultCoreCipherList | tr ':' '\\n'\nTLS_AES_256_GCM_SHA384\nTLS_CHACHA20_POLY1305_SHA256\nTLS_AES_128_GCM_SHA256\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\n
\n

This default can be replaced entirely using the --tls-cipher-list command\nline switch (directly, or via the NODE_OPTIONS environment variable). For\ninstance, the following makes ECDHE-RSA-AES128-GCM-SHA256:!RC4 the default TLS\ncipher suite:

\n
node --tls-cipher-list='ECDHE-RSA-AES128-GCM-SHA256:!RC4' server.js\n\nexport NODE_OPTIONS=--tls-cipher-list='ECDHE-RSA-AES128-GCM-SHA256:!RC4'\nnode server.js\n
\n

The default can also be replaced on a per client or server basis using the\nciphers option from tls.createSecureContext(), which is also available\nin tls.createServer(), tls.connect(), and when creating new\ntls.TLSSockets.

\n

The ciphers list can contain a mixture of TLSv1.3 cipher suite names, the ones\nthat start with 'TLS_', and specifications for TLSv1.2 and below cipher\nsuites. The TLSv1.2 ciphers support a legacy specification format, consult\nthe OpenSSL cipher list format documentation for details, but those\nspecifications do not apply to TLSv1.3 ciphers. The TLSv1.3 suites can only\nbe enabled by including their full name in the cipher list. They cannot, for\nexample, be enabled or disabled by using the legacy TLSv1.2 'EECDH' or\n'!EECDH' specification.

\n

Despite the relative order of TLSv1.3 and TLSv1.2 cipher suites, the TLSv1.3\nprotocol is significantly more secure than TLSv1.2, and will always be chosen\nover TLSv1.2 if the handshake indicates it is supported, and if any TLSv1.3\ncipher suites are enabled.

\n

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 and ciphers option should by\nused only if absolutely necessary.

\n

The 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 compatibility.

\n

128 bit AES is preferred over 192 and 256 bit AES in light of specific\nattacks affecting larger AES key sizes.

\n

Old clients that rely on insecure and deprecated RC4 or DES-based ciphers\n(like Internet Explorer 6) cannot complete the handshaking process with\nthe default configuration. If these clients must be supported, the\nTLS recommendations may offer a compatible cipher suite. For more details\non the format, see the OpenSSL cipher list format documentation.

\n

There are only 5 TLSv1.3 cipher suites:

\n\n

The first 3 are enabled by default. The last 2 CCM-based suites are supported\nby TLSv1.3 because they may be more performant on constrained systems, but they\nare not enabled by default since they offer less security.

", "type": "module", "displayName": "Modifying the default TLS cipher suite" }, { "textRaw": "Deprecated APIs", "name": "deprecated_apis", "classes": [ { "textRaw": "Class: `CryptoStream`", "type": "class", "name": "CryptoStream", "meta": { "added": [ "v0.3.4" ], "deprecated": [ "v0.11.3" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Use [`tls.TLSSocket`][] instead.", "desc": "

The tls.CryptoStream class represents a stream of encrypted data. This class\nis deprecated and should no longer be used.

", "properties": [ { "textRaw": "`cryptoStream.bytesWritten`", "name": "bytesWritten", "meta": { "added": [ "v0.3.4" ], "deprecated": [ "v0.11.3" ], "changes": [] }, "desc": "

The cryptoStream.bytesWritten property returns the total number of bytes\nwritten to the underlying socket including the bytes required for the\nimplementation of the TLS protocol.

" } ] }, { "textRaw": "Class: `SecurePair`", "type": "class", "name": "SecurePair", "meta": { "added": [ "v0.3.2" ], "deprecated": [ "v0.11.3" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Use [`tls.TLSSocket`][] instead.", "desc": "

Returned by tls.createSecurePair().

", "events": [ { "textRaw": "Event: `'secure'`", "type": "event", "name": "secure", "meta": { "added": [ "v0.3.2" ], "deprecated": [ "v0.11.3" ], "changes": [] }, "params": [], "desc": "

The 'secure' event is emitted by the SecurePair object once a secure\nconnection has been established.

\n

As with checking for the server\n'secureConnection'\nevent, pair.cleartext.authorized should be inspected to confirm whether the\ncertificate used is properly authorized.

" } ] } ], "methods": [ { "textRaw": "`tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])`", "type": "method", "name": "createSecurePair", "meta": { "added": [ "v0.3.2" ], "deprecated": [ "v0.11.3" ], "changes": [ { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/2564", "description": "ALPN options are supported now." } ] }, "stability": 0, "stabilityText": "Deprecated: Use [`tls.TLSSocket`][] instead.", "signatures": [ { "params": [ { "textRaw": "`context` {Object} A secure context object as returned by `tls.createSecureContext()`", "name": "context", "type": "Object", "desc": "A secure context object as returned by `tls.createSecureContext()`" }, { "textRaw": "`isServer` {boolean} `true` to specify that this TLS connection should be opened as a server.", "name": "isServer", "type": "boolean", "desc": "`true` to specify that this TLS connection should be opened as a server." }, { "textRaw": "`requestCert` {boolean} `true` to specify whether a server should request a certificate from a connecting client. Only applies when `isServer` is `true`.", "name": "requestCert", "type": "boolean", "desc": "`true` to specify whether a server should request a certificate from a connecting client. Only applies when `isServer` is `true`." }, { "textRaw": "`rejectUnauthorized` {boolean} If not `false` a server automatically reject clients with invalid certificates. Only applies when `isServer` is `true`.", "name": "rejectUnauthorized", "type": "boolean", "desc": "If not `false` a server automatically reject clients with invalid certificates. Only applies when `isServer` is `true`." }, { "textRaw": "`options`", "name": "options", "options": [ { "textRaw": "`enableTrace`: See [`tls.createServer()`][]", "name": "enableTrace", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`secureContext`: A TLS context object from [`tls.createSecureContext()`][]", "name": "secureContext", "desc": "A TLS context object from [`tls.createSecureContext()`][]" }, { "textRaw": "`isServer`: If `true` the TLS socket will be instantiated in server-mode. **Default:** `false`.", "name": "isServer", "default": "`false`", "desc": "If `true` the TLS socket will be instantiated in server-mode." }, { "textRaw": "`server` {net.Server} A [`net.Server`][] instance", "name": "server", "type": "net.Server", "desc": "A [`net.Server`][] instance" }, { "textRaw": "`requestCert`: See [`tls.createServer()`][]", "name": "requestCert", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`rejectUnauthorized`: See [`tls.createServer()`][]", "name": "rejectUnauthorized", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`ALPNProtocols`: See [`tls.createServer()`][]", "name": "ALPNProtocols", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`SNICallback`: See [`tls.createServer()`][]", "name": "SNICallback", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`session` {Buffer} A `Buffer` instance containing a TLS session.", "name": "session", "type": "Buffer", "desc": "A `Buffer` instance containing a TLS session." }, { "textRaw": "`requestOCSP` {boolean} If `true`, specifies that the OCSP status request extension will be added to the client hello and an `'OCSPResponse'` event will be emitted on the socket before establishing a secure communication.", "name": "requestOCSP", "type": "boolean", "desc": "If `true`, specifies that the OCSP status request extension will be added to the client hello and an `'OCSPResponse'` event will be emitted on the socket before establishing a secure communication." } ] } ] } ], "desc": "

Creates a new secure pair object with two streams, one of which reads and writes\nthe encrypted data and the other of which reads and writes the cleartext data.\nGenerally, the encrypted stream is piped to/from an incoming encrypted data\nstream and the cleartext one is used as a replacement for the initial encrypted\nstream.

\n

tls.createSecurePair() returns a tls.SecurePair object with cleartext and\nencrypted stream properties.

\n

Using cleartext has the same API as tls.TLSSocket.

\n

The tls.createSecurePair() method is now deprecated in favor of\ntls.TLSSocket(). For example, the code:

\n
pair = tls.createSecurePair(/* ... */);\npair.encrypted.pipe(socket);\nsocket.pipe(pair.encrypted);\n
\n

can be replaced by:

\n
secureSocket = tls.TLSSocket(socket, options);\n
\n

where secureSocket has the same API as pair.cleartext.

" } ], "type": "module", "displayName": "Deprecated APIs" } ], "classes": [ { "textRaw": "Class: `tls.Server`", "type": "class", "name": "tls.Server", "meta": { "added": [ "v0.3.2" ], "changes": [] }, "desc": "\n

Accepts encrypted connections using TLS or SSL.

", "events": [ { "textRaw": "Event: `'keylog'`", "type": "event", "name": "keylog", "meta": { "added": [ "v12.3.0", "v10.20.0" ], "changes": [] }, "params": [ { "textRaw": "`line` {Buffer} Line of ASCII text, in NSS `SSLKEYLOGFILE` format.", "name": "line", "type": "Buffer", "desc": "Line of ASCII text, in NSS `SSLKEYLOGFILE` format." }, { "textRaw": "`tlsSocket` {tls.TLSSocket} The `tls.TLSSocket` instance on which it was generated.", "name": "tlsSocket", "type": "tls.TLSSocket", "desc": "The `tls.TLSSocket` instance on which it was generated." } ], "desc": "

The keylog event is emitted when key material is generated or received by\na connection to this server (typically before handshake has completed, but not\nnecessarily). This keying material can be stored for debugging, as it allows\ncaptured TLS traffic to be decrypted. It may be emitted multiple times for\neach socket.

\n

A typical use case is to append received lines to a common text file, which\nis later used by software (such as Wireshark) to decrypt the traffic:

\n
const logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' });\n// ...\nserver.on('keylog', (line, tlsSocket) => {\n  if (tlsSocket.remoteAddress !== '...')\n    return; // Only log keys for a particular IP\n  logFile.write(line);\n});\n
" }, { "textRaw": "Event: `'newSession'`", "type": "event", "name": "newSession", "meta": { "added": [ "v0.9.2" ], "changes": [ { "version": "v0.11.12", "pr-url": "https://github.com/nodejs/node-v0.x-archive/pull/7118", "description": "The `callback` argument is now supported." } ] }, "params": [], "desc": "

The 'newSession' event is emitted upon creation of a new TLS session. This may\nbe used to store sessions in external storage. The data should be provided to\nthe 'resumeSession' callback.

\n

The listener callback is passed three arguments when called:

\n\n

Listening for this event will have an effect only on connections established\nafter the addition of the event listener.

" }, { "textRaw": "Event: `'OCSPRequest'`", "type": "event", "name": "OCSPRequest", "meta": { "added": [ "v0.11.13" ], "changes": [] }, "params": [], "desc": "

The 'OCSPRequest' event is emitted when the client sends a certificate status\nrequest. The listener callback is passed three arguments when called:

\n\n

The server's current certificate can be parsed to obtain the OCSP URL\nand certificate ID; after obtaining an OCSP response, callback(null, resp) is\nthen invoked, where resp is a Buffer instance containing the OCSP response.\nBoth certificate and issuer are Buffer DER-representations of the\nprimary and issuer's certificates. These can be used to obtain the OCSP\ncertificate ID and OCSP endpoint URL.

\n

Alternatively, callback(null, null) may be called, indicating that there was\nno OCSP response.

\n

Calling callback(err) will result in a socket.destroy(err) call.

\n

The typical flow of an OCSP Request is as follows:

\n
    \n
  1. Client connects to the server and sends an 'OCSPRequest' (via the status\ninfo extension in ClientHello).
  2. \n
  3. Server receives the request and emits the 'OCSPRequest' event, calling the\nlistener if registered.
  4. \n
  5. Server extracts the OCSP URL from either the certificate or issuer and\nperforms an OCSP request to the CA.
  6. \n
  7. Server receives 'OCSPResponse' from the CA and sends it back to the client\nvia the callback argument
  8. \n
  9. Client validates the response and either destroys the socket or performs a\nhandshake.
  10. \n
\n

The issuer can be null if the certificate is either self-signed or the\nissuer is not in the root certificates list. (An issuer may be provided\nvia the ca option when establishing the TLS connection.)

\n

Listening for this event will have an effect only on connections established\nafter the addition of the event listener.

\n

An npm module like asn1.js may be used to parse the certificates.

" }, { "textRaw": "Event: `'resumeSession'`", "type": "event", "name": "resumeSession", "meta": { "added": [ "v0.9.2" ], "changes": [] }, "params": [], "desc": "

The 'resumeSession' event is emitted when the client requests to resume a\nprevious TLS session. The listener callback is passed two arguments when\ncalled:

\n\n

The event listener should perform a lookup in external storage for the\nsessionData saved by the 'newSession' event handler using the given\nsessionId. If found, call callback(null, sessionData) to resume the session.\nIf not found, the session cannot be resumed. callback() must be called\nwithout sessionData so that the handshake can continue and a new session can\nbe created. It is possible to call callback(err) to terminate the incoming\nconnection and destroy the socket.

\n

Listening for this event will have an effect only on connections established\nafter the addition of the event listener.

\n

The following illustrates resuming a TLS session:

\n
const tlsSessionStore = {};\nserver.on('newSession', (id, data, cb) => {\n  tlsSessionStore[id.toString('hex')] = data;\n  cb();\n});\nserver.on('resumeSession', (id, cb) => {\n  cb(null, tlsSessionStore[id.toString('hex')] || null);\n});\n
" }, { "textRaw": "Event: `'secureConnection'`", "type": "event", "name": "secureConnection", "meta": { "added": [ "v0.3.2" ], "changes": [] }, "params": [], "desc": "

The 'secureConnection' event is emitted after the handshaking process for a\nnew connection has successfully completed. The listener callback is passed a\nsingle argument when called:

\n\n

The tlsSocket.authorized property is a boolean indicating whether the\nclient has been verified by one of the supplied Certificate Authorities for the\nserver. If tlsSocket.authorized is false, then socket.authorizationError\nis set to describe how authorization failed. Depending on the settings\nof the TLS server, unauthorized connections may still be accepted.

\n

The tlsSocket.alpnProtocol property is a string that contains the selected\nALPN protocol. When ALPN has no selected protocol, tlsSocket.alpnProtocol\nequals false.

\n

The tlsSocket.servername property is a string containing the server name\nrequested via SNI.

" }, { "textRaw": "Event: `'tlsClientError'`", "type": "event", "name": "tlsClientError", "meta": { "added": [ "v6.0.0" ], "changes": [] }, "params": [], "desc": "

The 'tlsClientError' event is emitted when an error occurs before a secure\nconnection is established. The listener callback is passed two arguments when\ncalled:

\n" } ], "methods": [ { "textRaw": "`server.addContext(hostname, context)`", "type": "method", "name": "addContext", "meta": { "added": [ "v0.5.3" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`hostname` {string} A SNI host name or wildcard (e.g. `'*'`)", "name": "hostname", "type": "string", "desc": "A SNI host name or wildcard (e.g. `'*'`)" }, { "textRaw": "`context` {Object} An object containing any of the possible properties from the [`tls.createSecureContext()`][] `options` arguments (e.g. `key`, `cert`, `ca`, etc).", "name": "context", "type": "Object", "desc": "An object containing any of the possible properties from the [`tls.createSecureContext()`][] `options` arguments (e.g. `key`, `cert`, `ca`, etc)." } ] } ], "desc": "

The server.addContext() method adds a secure context that will be used if\nthe client request's SNI name matches the supplied hostname (or wildcard).

" }, { "textRaw": "`server.address()`", "type": "method", "name": "address", "meta": { "added": [ "v0.6.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object}", "name": "return", "type": "Object" }, "params": [] } ], "desc": "

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.

" }, { "textRaw": "`server.close([callback])`", "type": "method", "name": "close", "meta": { "added": [ "v0.3.2" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {tls.Server}", "name": "return", "type": "tls.Server" }, "params": [ { "textRaw": "`callback` {Function} A listener callback that will be registered to listen for the server instance's `'close'` event.", "name": "callback", "type": "Function", "desc": "A listener callback that will be registered to listen for the server instance's `'close'` event." } ] } ], "desc": "

The server.close() method stops the server from accepting new connections.

\n

This function operates asynchronously. The 'close' event will be emitted\nwhen the server has no more open connections.

" }, { "textRaw": "`server.getTicketKeys()`", "type": "method", "name": "getTicketKeys", "meta": { "added": [ "v3.0.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} A 48-byte buffer containing the session ticket keys.", "name": "return", "type": "Buffer", "desc": "A 48-byte buffer containing the session ticket keys." }, "params": [] } ], "desc": "

Returns the session ticket keys.

\n

See Session Resumption for more information.

" }, { "textRaw": "`server.listen()`", "type": "method", "name": "listen", "signatures": [ { "params": [] } ], "desc": "

Starts the server listening for encrypted connections.\nThis method is identical to server.listen() from net.Server.

" }, { "textRaw": "`server.setSecureContext(options)`", "type": "method", "name": "setSecureContext", "meta": { "added": [ "v11.0.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`options` {Object} An object containing any of the possible properties from the [`tls.createSecureContext()`][] `options` arguments (e.g. `key`, `cert`, `ca`, etc).", "name": "options", "type": "Object", "desc": "An object containing any of the possible properties from the [`tls.createSecureContext()`][] `options` arguments (e.g. `key`, `cert`, `ca`, etc)." } ] } ], "desc": "

The server.setSecureContext() method replaces the secure context of an\nexisting server. Existing connections to the server are not interrupted.

" }, { "textRaw": "`server.setTicketKeys(keys)`", "type": "method", "name": "setTicketKeys", "meta": { "added": [ "v3.0.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`keys` {Buffer} A 48-byte buffer containing the session ticket keys.", "name": "keys", "type": "Buffer", "desc": "A 48-byte buffer containing the session ticket keys." } ] } ], "desc": "

Sets the session ticket keys.

\n

Changes to the ticket keys are effective only for future server connections.\nExisting or currently pending server connections will use the previous keys.

\n

See Session Resumption for more information.

" } ], "properties": [ { "textRaw": "`connections` {number}", "type": "number", "name": "connections", "meta": { "added": [ "v0.3.2" ], "deprecated": [ "v0.9.7" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Use [`server.getConnections()`][] instead.", "desc": "

Returns the current number of concurrent connections on the server.

" } ] }, { "textRaw": "Class: `tls.TLSSocket`", "type": "class", "name": "tls.TLSSocket", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "\n

Performs transparent encryption of written data and all required TLS\nnegotiation.

\n

Instances of tls.TLSSocket implement the duplex Stream interface.

\n

Methods that return TLS connection metadata (e.g.\ntls.TLSSocket.getPeerCertificate() will only return data while the\nconnection is open.

", "events": [ { "textRaw": "Event: `'keylog'`", "type": "event", "name": "keylog", "meta": { "added": [ "v12.3.0", "v10.20.0" ], "changes": [] }, "params": [ { "textRaw": "`line` {Buffer} Line of ASCII text, in NSS `SSLKEYLOGFILE` format.", "name": "line", "type": "Buffer", "desc": "Line of ASCII text, in NSS `SSLKEYLOGFILE` format." } ], "desc": "

The keylog event is emitted on a tls.TLSSocket when key material\nis generated or received by the socket. This keying material can be stored\nfor debugging, as it allows captured TLS traffic to be decrypted. It may\nbe emitted multiple times, before or after the handshake completes.

\n

A typical use case is to append received lines to a common text file, which\nis later used by software (such as Wireshark) to decrypt the traffic:

\n
const logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' });\n// ...\ntlsSocket.on('keylog', (line) => logFile.write(line));\n
" }, { "textRaw": "Event: `'OCSPResponse'`", "type": "event", "name": "OCSPResponse", "meta": { "added": [ "v0.11.13" ], "changes": [] }, "params": [], "desc": "

The 'OCSPResponse' event is emitted if the requestOCSP option was set\nwhen the tls.TLSSocket was created and an OCSP response has been received.\nThe listener callback is passed a single argument when called:

\n\n

Typically, the response is a digitally signed object from the server's CA that\ncontains information about server's certificate revocation status.

" }, { "textRaw": "Event: `'secureConnect'`", "type": "event", "name": "secureConnect", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "params": [], "desc": "

The 'secureConnect' event is emitted after the handshaking process for a new\nconnection has successfully completed. The listener callback will be called\nregardless of whether or not the server's certificate has been authorized. It\nis the client's responsibility to check the tlsSocket.authorized property to\ndetermine if the server certificate was signed by one of the specified CAs. If\ntlsSocket.authorized === false, then the error can be found by examining the\ntlsSocket.authorizationError property. If ALPN was used, the\ntlsSocket.alpnProtocol property can be checked to determine the negotiated\nprotocol.

" }, { "textRaw": "Event: `'session'`", "type": "event", "name": "session", "meta": { "added": [ "v11.10.0" ], "changes": [] }, "params": [ { "textRaw": "`session` {Buffer}", "name": "session", "type": "Buffer" } ], "desc": "

The 'session' event is emitted on a client tls.TLSSocket when a new session\nor TLS ticket is available. This may or may not be before the handshake is\ncomplete, depending on the TLS protocol version that was negotiated. The event\nis not emitted on the server, or if a new session was not created, for example,\nwhen the connection was resumed. For some TLS protocol versions the event may be\nemitted multiple times, in which case all the sessions can be used for\nresumption.

\n

On the client, the session can be provided to the session option of\ntls.connect() to resume the connection.

\n

See Session Resumption for more information.

\n

For TLSv1.2 and below, tls.TLSSocket.getSession() can be called once\nthe handshake is complete. For TLSv1.3, only ticket-based resumption is allowed\nby the protocol, multiple tickets are sent, and the tickets aren't sent until\nafter the handshake completes. So it is necessary to wait for the\n'session' event to get a resumable session. Applications\nshould use the 'session' event instead of getSession() to ensure\nthey will work for all TLS versions. Applications that only expect to\nget or use one session should listen for this event only once:

\n
tlsSocket.once('session', (session) => {\n  // The session can be used immediately or later.\n  tls.connect({\n    session: session,\n    // Other connect options...\n  });\n});\n
" } ], "methods": [ { "textRaw": "`tlsSocket.address()`", "type": "method", "name": "address", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object}", "name": "return", "type": "Object" }, "params": [] } ], "desc": "

Returns the bound address, the address family name, and port of the\nunderlying socket as reported by the operating system:\n{ port: 12346, family: 'IPv4', address: '127.0.0.1' }.

" }, { "textRaw": "`tlsSocket.disableRenegotiation()`", "type": "method", "name": "disableRenegotiation", "meta": { "added": [ "v8.4.0" ], "changes": [] }, "signatures": [ { "params": [] } ], "desc": "

Disables TLS renegotiation for this TLSSocket instance. Once called, attempts\nto renegotiate will trigger an 'error' event on the TLSSocket.

" }, { "textRaw": "`tlsSocket.enableTrace()`", "type": "method", "name": "enableTrace", "meta": { "added": [ "v12.2.0" ], "changes": [] }, "signatures": [ { "params": [] } ], "desc": "

When enabled, TLS packet trace information is written to stderr. This can be\nused to debug TLS connection problems.

\n

Note: The format of the output is identical to the output of openssl s_client -trace or openssl s_server -trace. While it is produced by OpenSSL's\nSSL_trace() function, the format is undocumented, can change without notice,\nand should not be relied on.

" }, { "textRaw": "`tlsSocket.getCertificate()`", "type": "method", "name": "getCertificate", "meta": { "added": [ "v11.2.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object}", "name": "return", "type": "Object" }, "params": [] } ], "desc": "

Returns an object representing the local certificate. The returned object has\nsome properties corresponding to the fields of the certificate.

\n

See tls.TLSSocket.getPeerCertificate() for an example of the certificate\nstructure.

\n

If there is no local certificate, an empty object will be returned. If the\nsocket has been destroyed, null will be returned.

" }, { "textRaw": "`tlsSocket.getCipher()`", "type": "method", "name": "getCipher", "meta": { "added": [ "v0.11.4" ], "changes": [ { "version": [ "v13.4.0", "v12.16.0" ], "pr-url": "https://github.com/nodejs/node/pull/30637", "description": "Return the IETF cipher name as `standardName`." }, { "version": "v12.0.0", "pr-url": "https://github.com/nodejs/node/pull/26625", "description": "Return the minimum cipher version, instead of a fixed string (`'TLSv1/SSLv3'`)." } ] }, "signatures": [ { "return": { "textRaw": "Returns: {Object}", "name": "return", "type": "Object", "options": [ { "textRaw": "`name` {string} OpenSSL name for the cipher suite.", "name": "name", "type": "string", "desc": "OpenSSL name for the cipher suite." }, { "textRaw": "`standardName` {string} IETF name for the cipher suite.", "name": "standardName", "type": "string", "desc": "IETF name for the cipher suite." }, { "textRaw": "`version` {string} The minimum TLS protocol version supported by this cipher suite.", "name": "version", "type": "string", "desc": "The minimum TLS protocol version supported by this cipher suite." } ] }, "params": [] } ], "desc": "

Returns an object containing information on the negotiated cipher suite.

\n

For example:

\n
{\n    \"name\": \"AES128-SHA256\",\n    \"standardName\": \"TLS_RSA_WITH_AES_128_CBC_SHA256\",\n    \"version\": \"TLSv1.2\"\n}\n
\n

See\nSSL_CIPHER_get_name\nfor more information.

" }, { "textRaw": "`tlsSocket.getEphemeralKeyInfo()`", "type": "method", "name": "getEphemeralKeyInfo", "meta": { "added": [ "v5.0.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object}", "name": "return", "type": "Object" }, "params": [] } ], "desc": "

Returns an object representing the type, name, and size of parameter of\nan ephemeral key exchange in perfect forward secrecy on a client\nconnection. It returns an empty object when the key exchange is not\nephemeral. As this is only supported on a client socket; null is returned\nif called on a server socket. The supported types are 'DH' and 'ECDH'. The\nname property is available only when type is 'ECDH'.

\n

For example: { type: 'ECDH', name: 'prime256v1', size: 256 }.

" }, { "textRaw": "`tlsSocket.getFinished()`", "type": "method", "name": "getFinished", "meta": { "added": [ "v9.9.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer|undefined} The latest `Finished` message that has been sent to the socket as part of a SSL/TLS handshake, or `undefined` if no `Finished` message has been sent yet.", "name": "return", "type": "Buffer|undefined", "desc": "The latest `Finished` message that has been sent to the socket as part of a SSL/TLS handshake, or `undefined` if no `Finished` message has been sent yet." }, "params": [] } ], "desc": "

As the Finished messages are message digests of the complete handshake\n(with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can\nbe used for external authentication procedures when the authentication\nprovided by SSL/TLS is not desired or is not enough.

\n

Corresponds to the SSL_get_finished routine in OpenSSL and may be used\nto implement the tls-unique channel binding from RFC 5929.

" }, { "textRaw": "`tlsSocket.getPeerCertificate([detailed])`", "type": "method", "name": "getPeerCertificate", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object} A certificate object.", "name": "return", "type": "Object", "desc": "A certificate object." }, "params": [ { "textRaw": "`detailed` {boolean} Include the full certificate chain if `true`, otherwise include just the peer's certificate.", "name": "detailed", "type": "boolean", "desc": "Include the full certificate chain if `true`, otherwise include just the peer's certificate." } ] } ], "desc": "

Returns an object representing the peer's certificate. If the peer does not\nprovide a certificate, an empty object will be returned. If the socket has been\ndestroyed, null will be returned.

\n

If the full certificate chain was requested, each certificate will include an\nissuerCertificate property containing an object representing its issuer's\ncertificate.

", "modules": [ { "textRaw": "Certificate object", "name": "certificate_object", "meta": { "changes": [ { "version": "v11.4.0", "pr-url": "https://github.com/nodejs/node/pull/24358", "description": "Support Elliptic Curve public key info." } ] }, "desc": "

A certificate object has properties corresponding to the fields of the\ncertificate.

\n\n

The certificate may contain information about the public key, depending on\nthe key type.

\n

For RSA keys, the following properties may be defined:

\n\n

For EC keys, the following properties may be defined:

\n\n

Example certificate:

\n
{ subject:\n   { OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ],\n     CN: '*.nodejs.org' },\n  issuer:\n   { C: 'GB',\n     ST: 'Greater Manchester',\n     L: 'Salford',\n     O: 'COMODO CA Limited',\n     CN: 'COMODO RSA Domain Validation Secure Server CA' },\n  subjectaltname: 'DNS:*.nodejs.org, DNS:nodejs.org',\n  infoAccess:\n   { 'CA Issuers - URI':\n      [ 'http://crt.comodoca.com/COMODORSADomainValidationSecureServerCA.crt' ],\n     'OCSP - URI': [ 'http://ocsp.comodoca.com' ] },\n  modulus: 'B56CE45CB740B09A13F64AC543B712FF9EE8E4C284B542A1708A27E82A8D151CA178153E12E6DDA15BF70FFD96CB8A88618641BDFCCA03527E665B70D779C8A349A6F88FD4EF6557180BD4C98192872BCFE3AF56E863C09DDD8BC1EC58DF9D94F914F0369102B2870BECFA1348A0838C9C49BD1C20124B442477572347047506B1FCD658A80D0C44BCC16BC5C5496CFE6E4A8428EF654CD3D8972BF6E5BFAD59C93006830B5EB1056BBB38B53D1464FA6E02BFDF2FF66CD949486F0775EC43034EC2602AEFBF1703AD221DAA2A88353C3B6A688EFE8387811F645CEED7B3FE46E1F8B9F59FAD028F349B9BC14211D5830994D055EEA3D547911E07A0ADDEB8A82B9188E58720D95CD478EEC9AF1F17BE8141BE80906F1A339445A7EB5B285F68039B0F294598A7D1C0005FC22B5271B0752F58CCDEF8C8FD856FB7AE21C80B8A2CE983AE94046E53EDE4CB89F42502D31B5360771C01C80155918637490550E3F555E2EE75CC8C636DDE3633CFEDD62E91BF0F7688273694EEEBA20C2FC9F14A2A435517BC1D7373922463409AB603295CEB0BB53787A334C9CA3CA8B30005C5A62FC0715083462E00719A8FA3ED0A9828C3871360A73F8B04A4FC1E71302844E9BB9940B77E745C9D91F226D71AFCAD4B113AAF68D92B24DDB4A2136B55A1CD1ADF39605B63CB639038ED0F4C987689866743A68769CC55847E4A06D6E2E3F1',\n  exponent: '0x10001',\n  pubkey: <Buffer ... >,\n  valid_from: 'Aug 14 00:00:00 2017 GMT',\n  valid_to: 'Nov 20 23:59:59 2019 GMT',\n  fingerprint: '01:02:59:D9:C3:D2:0D:08:F7:82:4E:44:A4:B4:53:C5:E2:3A:87:4D',\n  fingerprint256: '69:AE:1A:6A:D4:3D:C6:C1:1B:EA:C6:23:DE:BA:2A:14:62:62:93:5C:7A:EA:06:41:9B:0B:BC:87:CE:48:4E:02',\n  ext_key_usage: [ '1.3.6.1.5.5.7.3.1', '1.3.6.1.5.5.7.3.2' ],\n  serialNumber: '66593D57F20CBC573E433381B5FEC280',\n  raw: <Buffer ... > }\n
", "type": "module", "displayName": "Certificate object" } ] }, { "textRaw": "`tlsSocket.getPeerFinished()`", "type": "method", "name": "getPeerFinished", "meta": { "added": [ "v9.9.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer|undefined} The latest `Finished` message that is expected or has actually been received from the socket as part of a SSL/TLS handshake, or `undefined` if there is no `Finished` message so far.", "name": "return", "type": "Buffer|undefined", "desc": "The latest `Finished` message that is expected or has actually been received from the socket as part of a SSL/TLS handshake, or `undefined` if there is no `Finished` message so far." }, "params": [] } ], "desc": "

As the Finished messages are message digests of the complete handshake\n(with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can\nbe used for external authentication procedures when the authentication\nprovided by SSL/TLS is not desired or is not enough.

\n

Corresponds to the SSL_get_peer_finished routine in OpenSSL and may be used\nto implement the tls-unique channel binding from RFC 5929.

" }, { "textRaw": "`tlsSocket.getProtocol()`", "type": "method", "name": "getProtocol", "meta": { "added": [ "v5.7.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {string|null}", "name": "return", "type": "string|null" }, "params": [] } ], "desc": "

Returns a string containing the negotiated SSL/TLS protocol version of the\ncurrent connection. The value 'unknown' will be returned for connected\nsockets that have not completed the handshaking process. The value null will\nbe returned for server sockets or disconnected client sockets.

\n

Protocol versions are:

\n\n

See the OpenSSL SSL_get_version documentation for more information.

" }, { "textRaw": "`tlsSocket.getSession()`", "type": "method", "name": "getSession", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "{Buffer}", "type": "Buffer" } ] } ], "desc": "

Returns the TLS session data or undefined if no session was\nnegotiated. On the client, the data can be provided to the session option of\ntls.connect() to resume the connection. On the server, it may be useful\nfor debugging.

\n

See Session Resumption for more information.

\n

Note: getSession() works only for TLSv1.2 and below. For TLSv1.3, applications\nmust use the 'session' event (it also works for TLSv1.2 and below).

" }, { "textRaw": "`tlsSocket.getSharedSigalgs()`", "type": "method", "name": "getSharedSigalgs", "meta": { "added": [ "v12.11.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Array} List of signature algorithms shared between the server and the client in the order of decreasing preference.", "name": "return", "type": "Array", "desc": "List of signature algorithms shared between the server and the client in the order of decreasing preference." }, "params": [] } ], "desc": "

See\nSSL_get_shared_sigalgs\nfor more information.

" }, { "textRaw": "`tlsSocket.exportKeyingMaterial(length, label[, context])`", "type": "method", "name": "exportKeyingMaterial", "meta": { "added": [ "v13.10.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Buffer} requested bytes of the keying material", "name": "return", "type": "Buffer", "desc": "requested bytes of the keying material" }, "params": [ { "textRaw": "`length` {number} number of bytes to retrieve from keying material", "name": "length", "type": "number", "desc": "number of bytes to retrieve from keying material" }, { "textRaw": "`label` {string} an application specific label, typically this will be a value from the [IANA Exporter Label Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels).", "name": "label", "type": "string", "desc": "an application specific label, typically this will be a value from the [IANA Exporter Label Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels)." }, { "textRaw": "`context` {Buffer} Optionally provide a context.", "name": "context", "type": "Buffer", "desc": "Optionally provide a context." } ] } ], "desc": "

Keying material is used for validations to prevent different kind of attacks in\nnetwork protocols, for example in the specifications of IEEE 802.1X.

\n

Example

\n
const keyingMaterial = tlsSocket.exportKeyingMaterial(\n  128,\n  'client finished');\n\n/**\n Example return value of keyingMaterial:\n <Buffer 76 26 af 99 c5 56 8e 42 09 91 ef 9f 93 cb ad 6c 7b 65 f8 53 f1 d8 d9\n    12 5a 33 b8 b5 25 df 7b 37 9f e0 e2 4f b8 67 83 a3 2f cd 5d 41 42 4c 91\n    74 ef 2c ... 78 more bytes>\n*/\n
\n

See the OpenSSL SSL_export_keying_material documentation for more\ninformation.

" }, { "textRaw": "`tlsSocket.getTLSTicket()`", "type": "method", "name": "getTLSTicket", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "{Buffer}", "type": "Buffer" } ] } ], "desc": "

For a client, returns the TLS session ticket if one is available, or\nundefined. For a server, always returns undefined.

\n

It may be useful for debugging.

\n

See Session Resumption for more information.

" }, { "textRaw": "`tlsSocket.isSessionReused()`", "type": "method", "name": "isSessionReused", "meta": { "added": [ "v0.5.6" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {boolean} `true` if the session was reused, `false` otherwise.", "name": "return", "type": "boolean", "desc": "`true` if the session was reused, `false` otherwise." }, "params": [] } ], "desc": "

See Session Resumption for more information.

" }, { "textRaw": "`tlsSocket.renegotiate(options, callback)`", "type": "method", "name": "renegotiate", "meta": { "added": [ "v0.11.8" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {boolean} `true` if renegotiation was initiated, `false` otherwise.", "name": "return", "type": "boolean", "desc": "`true` if renegotiation was initiated, `false` otherwise." }, "params": [ { "textRaw": "`options` {Object}", "name": "options", "type": "Object", "options": [ { "textRaw": "`rejectUnauthorized` {boolean} If not `false`, the server certificate is verified against the list of supplied CAs. An `'error'` event is emitted if verification fails; `err.code` contains the OpenSSL error code. **Default:** `true`.", "name": "rejectUnauthorized", "type": "boolean", "default": "`true`", "desc": "If not `false`, the server certificate is verified against the list of supplied CAs. An `'error'` event is emitted if verification fails; `err.code` contains the OpenSSL error code." }, { "textRaw": "`requestCert`", "name": "requestCert" } ] }, { "textRaw": "`callback` {Function} If `renegotiate()` returned `true`, callback is attached once to the `'secure'` event. If `renegotiate()` returned `false`, `callback` will be called in the next tick with an error, unless the `tlsSocket` has been destroyed, in which case `callback` will not be called at all.", "name": "callback", "type": "Function", "desc": "If `renegotiate()` returned `true`, callback is attached once to the `'secure'` event. If `renegotiate()` returned `false`, `callback` will be called in the next tick with an error, unless the `tlsSocket` has been destroyed, in which case `callback` will not be called at all." } ] } ], "desc": "

The tlsSocket.renegotiate() method initiates a TLS renegotiation process.\nUpon completion, the callback function will be passed a single argument\nthat is either an Error (if the request failed) or null.

\n

This method can be used to request a peer's certificate after the secure\nconnection has been established.

\n

When running as the server, the socket will be destroyed with an error after\nhandshakeTimeout timeout.

\n

For TLSv1.3, renegotiation cannot be initiated, it is not supported by the\nprotocol.

" }, { "textRaw": "`tlsSocket.setMaxSendFragment(size)`", "type": "method", "name": "setMaxSendFragment", "meta": { "added": [ "v0.11.11" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {boolean}", "name": "return", "type": "boolean" }, "params": [ { "textRaw": "`size` {number} The maximum TLS fragment size. The maximum value is `16384`. **Default:** `16384`.", "name": "size", "type": "number", "default": "`16384`", "desc": "The maximum TLS fragment size. The maximum value is `16384`." } ] } ], "desc": "

The tlsSocket.setMaxSendFragment() method sets the maximum TLS fragment size.\nReturns true if setting the limit succeeded; false otherwise.

\n

Smaller fragment sizes decrease the buffering latency on the client: larger\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.

" } ], "properties": [ { "textRaw": "`tlsSocket.authorizationError`", "name": "authorizationError", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Returns the reason why the peer's certificate was not been verified. This\nproperty is set only when tlsSocket.authorized === false.

" }, { "textRaw": "`authorized` Returns: {boolean}", "type": "boolean", "name": "return", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Returns true if the peer certificate was signed by one of the CAs specified\nwhen creating the tls.TLSSocket instance, otherwise false.

" }, { "textRaw": "`tlsSocket.encrypted`", "name": "encrypted", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Always returns true. This may be used to distinguish TLS sockets from regular\nnet.Socket instances.

" }, { "textRaw": "`localAddress` {string}", "type": "string", "name": "localAddress", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Returns the string representation of the local IP address.

" }, { "textRaw": "`localPort` {number}", "type": "number", "name": "localPort", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Returns the numeric representation of the local port.

" }, { "textRaw": "`remoteAddress` {string}", "type": "string", "name": "remoteAddress", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Returns the string representation of the remote IP address. For example,\n'74.125.127.100' or '2001:4860:a005::68'.

" }, { "textRaw": "`remoteFamily` {string}", "type": "string", "name": "remoteFamily", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Returns the string representation of the remote IP family. 'IPv4' or 'IPv6'.

" }, { "textRaw": "`remotePort` {number}", "type": "number", "name": "remotePort", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "desc": "

Returns the numeric representation of the remote port. For example, 443.

" } ], "signatures": [ { "params": [ { "textRaw": "`socket` {net.Socket|stream.Duplex} On the server side, any `Duplex` stream. On the client side, any instance of [`net.Socket`][] (for generic `Duplex` stream support on the client side, [`tls.connect()`][] must be used).", "name": "socket", "type": "net.Socket|stream.Duplex", "desc": "On the server side, any `Duplex` stream. On the client side, any instance of [`net.Socket`][] (for generic `Duplex` stream support on the client side, [`tls.connect()`][] must be used)." }, { "textRaw": "`options` {Object}", "name": "options", "type": "Object", "options": [ { "textRaw": "`enableTrace`: See [`tls.createServer()`][]", "name": "enableTrace", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if they are to behave as a server or a client. If `true` the TLS socket will be instantiated as a server. **Default:** `false`.", "name": "isServer", "default": "`false`", "desc": "The SSL/TLS protocol is asymmetrical, TLSSockets must know if they are to behave as a server or a client. If `true` the TLS socket will be instantiated as a server." }, { "textRaw": "`server` {net.Server} A [`net.Server`][] instance.", "name": "server", "type": "net.Server", "desc": "A [`net.Server`][] instance." }, { "textRaw": "`requestCert`: Whether to authenticate the remote peer by requesting a certificate. Clients always request a server certificate. Servers (`isServer` is true) may set `requestCert` to true to request a client certificate.", "name": "requestCert", "desc": "Whether to authenticate the remote peer by requesting a certificate. Clients always request a server certificate. Servers (`isServer` is true) may set `requestCert` to true to request a client certificate." }, { "textRaw": "`rejectUnauthorized`: See [`tls.createServer()`][]", "name": "rejectUnauthorized", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`ALPNProtocols`: See [`tls.createServer()`][]", "name": "ALPNProtocols", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`SNICallback`: See [`tls.createServer()`][]", "name": "SNICallback", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`session` {Buffer} A `Buffer` instance containing a TLS session.", "name": "session", "type": "Buffer", "desc": "A `Buffer` instance containing a TLS session." }, { "textRaw": "`requestOCSP` {boolean} If `true`, specifies that the OCSP status request extension will be added to the client hello and an `'OCSPResponse'` event will be emitted on the socket before establishing a secure communication", "name": "requestOCSP", "type": "boolean", "desc": "If `true`, specifies that the OCSP status request extension will be added to the client hello and an `'OCSPResponse'` event will be emitted on the socket before establishing a secure communication" }, { "textRaw": "`secureContext`: TLS context object created with [`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one will be created by passing the entire `options` object to `tls.createSecureContext()`.", "name": "secureContext", "desc": "TLS context object created with [`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one will be created by passing the entire `options` object to `tls.createSecureContext()`." }, { "textRaw": "...: [`tls.createSecureContext()`][] options that are used if the `secureContext` option is missing. Otherwise, they are ignored.", "name": "...", "desc": "[`tls.createSecureContext()`][] options that are used if the `secureContext` option is missing. Otherwise, they are ignored." } ] } ], "desc": "

Construct a new tls.TLSSocket object from an existing TCP socket.

" } ] } ], "methods": [ { "textRaw": "`tls.checkServerIdentity(hostname, cert)`", "type": "method", "name": "checkServerIdentity", "meta": { "added": [ "v0.8.4" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Error|undefined}", "name": "return", "type": "Error|undefined" }, "params": [ { "textRaw": "`hostname` {string} The host name or IP address to verify the certificate against.", "name": "hostname", "type": "string", "desc": "The host name or IP address to verify the certificate against." }, { "textRaw": "`cert` {Object} A [certificate object][] representing the peer's certificate.", "name": "cert", "type": "Object", "desc": "A [certificate object][] representing the peer's certificate." } ] } ], "desc": "

Verifies the certificate cert is issued to hostname.

\n

Returns <Error> object, populating it with reason, host, and cert on\nfailure. On success, returns <undefined>.

\n

This function can be overwritten by providing alternative function as part of\nthe options.checkServerIdentity option passed to tls.connect(). The\noverwriting function can call tls.checkServerIdentity() of course, to augment\nthe checks done with additional verification.

\n

This function is only called if the certificate passed all other checks, such as\nbeing issued by trusted CA (options.ca).

" }, { "textRaw": "`tls.connect(options[, callback])`", "type": "method", "name": "connect", "meta": { "added": [ "v0.11.3" ], "changes": [ { "version": "v14.1.0", "pr-url": "https://github.com/nodejs/node/pull/32786", "description": "The `highWaterMark` option is accepted now." }, { "version": [ "v13.6.0", "v12.16.0" ], "pr-url": "https://github.com/nodejs/node/pull/23188", "description": "The `pskCallback` option is now supported." }, { "version": "v12.9.0", "pr-url": "https://github.com/nodejs/node/pull/27836", "description": "Support the `allowHalfOpen` option." }, { "version": "v12.4.0", "pr-url": "https://github.com/nodejs/node/pull/27816", "description": "The `hints` option is now supported." }, { "version": "v12.2.0", "pr-url": "https://github.com/nodejs/node/pull/27497", "description": "The `enableTrace` option is now supported." }, { "version": [ "v11.8.0", "v10.16.0" ], "pr-url": "https://github.com/nodejs/node/pull/25517", "description": "The `timeout` option is supported now." }, { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/12839", "description": "The `lookup` option is supported now." }, { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/11984", "description": "The `ALPNProtocols` option can be a `TypedArray` or `DataView` now." }, { "version": "v5.3.0, v4.7.0", "pr-url": "https://github.com/nodejs/node/pull/4246", "description": "The `secureContext` option is supported now." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/2564", "description": "ALPN options are supported now." } ] }, "signatures": [ { "return": { "textRaw": "Returns: {tls.TLSSocket}", "name": "return", "type": "tls.TLSSocket" }, "params": [ { "textRaw": "`options` {Object}", "name": "options", "type": "Object", "options": [ { "textRaw": "`enableTrace`: See [`tls.createServer()`][]", "name": "enableTrace", "desc": "See [`tls.createServer()`][]" }, { "textRaw": "`host` {string} Host the client should connect to. **Default:** `'localhost'`.", "name": "host", "type": "string", "default": "`'localhost'`", "desc": "Host the client should connect to." }, { "textRaw": "`port` {number} Port the client should connect to.", "name": "port", "type": "number", "desc": "Port the client should connect to." }, { "textRaw": "`path` {string} Creates Unix socket connection to path. If this option is specified, `host` and `port` are ignored.", "name": "path", "type": "string", "desc": "Creates Unix socket connection to path. If this option is specified, `host` and `port` are ignored." }, { "textRaw": "`socket` {stream.Duplex} Establish secure connection on a given socket rather than creating a new socket. Typically, this is an instance of [`net.Socket`][], but any `Duplex` stream is allowed. If this option is specified, `path`, `host` and `port` are ignored, except for certificate validation. Usually, a socket is already connected when passed to `tls.connect()`, but it can be connected later. Connection/disconnection/destruction of `socket` is the user's responsibility; calling `tls.connect()` will not cause `net.connect()` to be called.", "name": "socket", "type": "stream.Duplex", "desc": "Establish secure connection on a given socket rather than creating a new socket. Typically, this is an instance of [`net.Socket`][], but any `Duplex` stream is allowed. If this option is specified, `path`, `host` and `port` are ignored, except for certificate validation. Usually, a socket is already connected when passed to `tls.connect()`, but it can be connected later. Connection/disconnection/destruction of `socket` is the user's responsibility; calling `tls.connect()` will not cause `net.connect()` to be called." }, { "textRaw": "`allowHalfOpen` {boolean} If the `socket` option is missing, indicates whether or not to allow the internally created socket to be half-open, otherwise the option is ignored. See the `allowHalfOpen` option of [`net.Socket`][] for details. **Default:** `false`.", "name": "allowHalfOpen", "type": "boolean", "default": "`false`", "desc": "If the `socket` option is missing, indicates whether or not to allow the internally created socket to be half-open, otherwise the option is ignored. See the `allowHalfOpen` option of [`net.Socket`][] for details." }, { "textRaw": "`rejectUnauthorized` {boolean} If not `false`, the server certificate is verified against the list of supplied CAs. An `'error'` event is emitted if verification fails; `err.code` contains the OpenSSL error code. **Default:** `true`.", "name": "rejectUnauthorized", "type": "boolean", "default": "`true`", "desc": "If not `false`, the server certificate is verified against the list of supplied CAs. An `'error'` event is emitted if verification fails; `err.code` contains the OpenSSL error code." }, { "textRaw": "`pskCallback` {Function}", "name": "pskCallback", "type": "Function", "options": [ { "textRaw": "hint: {string} optional message sent from the server to help client decide which identity to use during negotiation. Always `null` if TLS 1.3 is used.", "name": "hint", "type": "string", "desc": "optional message sent from the server to help client decide which identity to use during negotiation. Always `null` if TLS 1.3 is used." }, { "textRaw": "Returns: {Object} in the form `{ psk: , identity: }` or `null` to stop the negotiation process. `psk` must be compatible with the selected cipher's digest. `identity` must use UTF-8 encoding. When negotiating TLS-PSK (pre-shared keys), this function is called with optional identity `hint` provided by the server or `null` in case of TLS 1.3 where `hint` was removed. It will be necessary to provide a custom `tls.checkServerIdentity()` for the connection as the default one will try to check host name/IP of the server against the certificate but that's not applicable for PSK because there won't be a certificate present. More information can be found in the [RFC 4279][].", "name": "return", "type": "Object", "desc": "in the form `{ psk: , identity: }` or `null` to stop the negotiation process. `psk` must be compatible with the selected cipher's digest. `identity` must use UTF-8 encoding. When negotiating TLS-PSK (pre-shared keys), this function is called with optional identity `hint` provided by the server or `null` in case of TLS 1.3 where `hint` was removed. It will be necessary to provide a custom `tls.checkServerIdentity()` for the connection as the default one will try to check host name/IP of the server against the certificate but that's not applicable for PSK because there won't be a certificate present. More information can be found in the [RFC 4279][]." } ] }, { "textRaw": "`ALPNProtocols`: {string[]|Buffer[]|TypedArray[]|DataView[]|Buffer| TypedArray|DataView} An array of strings, `Buffer`s or `TypedArray`s or `DataView`s, or a single `Buffer` or `TypedArray` or `DataView` containing the supported ALPN protocols. `Buffer`s should have the format `[len][name][len][name]...` e.g. `'\\x08http/1.1\\x08http/1.0'`, where the `len` byte is the length of the next protocol name. Passing an array is usually much simpler, e.g. `['http/1.1', 'http/1.0']`. Protocols earlier in the list have higher preference than those later.", "name": "ALPNProtocols", "type": "string[]|Buffer[]|TypedArray[]|DataView[]|Buffer| TypedArray|DataView", "desc": "An array of strings, `Buffer`s or `TypedArray`s or `DataView`s, or a single `Buffer` or `TypedArray` or `DataView` containing the supported ALPN protocols. `Buffer`s should have the format `[len][name][len][name]...` e.g. `'\\x08http/1.1\\x08http/1.0'`, where the `len` byte is the length of the next protocol name. Passing an array is usually much simpler, e.g. `['http/1.1', 'http/1.0']`. Protocols earlier in the list have higher preference than those later." }, { "textRaw": "`servername`: {string} Server name for the SNI (Server Name Indication) TLS extension. It is the name of the host being connected to, and must be a host name, and not an IP address. It can be used by a multi-homed server to choose the correct certificate to present to the client, see the `SNICallback` option to [`tls.createServer()`][].", "name": "servername", "type": "string", "desc": "Server name for the SNI (Server Name Indication) TLS extension. It is the name of the host being connected to, and must be a host name, and not an IP address. It can be used by a multi-homed server to choose the correct certificate to present to the client, see the `SNICallback` option to [`tls.createServer()`][]." }, { "textRaw": "`checkServerIdentity(servername, cert)` {Function} A callback function to be used (instead of the builtin `tls.checkServerIdentity()` function) when checking the server's host name (or the provided `servername` when explicitly set) against the certificate. This should return an {Error} if verification fails. The method should return `undefined` if the `servername` and `cert` are verified.", "name": "checkServerIdentity(servername,", "desc": "cert)` {Function} A callback function to be used (instead of the builtin `tls.checkServerIdentity()` function) when checking the server's host name (or the provided `servername` when explicitly set) against the certificate. This should return an {Error} if verification fails. The method should return `undefined` if the `servername` and `cert` are verified." }, { "textRaw": "`session` {Buffer} A `Buffer` instance, containing TLS session.", "name": "session", "type": "Buffer", "desc": "A `Buffer` instance, containing TLS session." }, { "textRaw": "`minDHSize` {number} Minimum size of the DH parameter in bits to accept a TLS connection. When a server offers a DH parameter with a size less than `minDHSize`, the TLS connection is destroyed and an error is thrown. **Default:** `1024`.", "name": "minDHSize", "type": "number", "default": "`1024`", "desc": "Minimum size of the DH parameter in bits to accept a TLS connection. When a server offers a DH parameter with a size less than `minDHSize`, the TLS connection is destroyed and an error is thrown." }, { "textRaw": "`highWaterMark`: {number} Consistent with the readable stream `highWaterMark` parameter. **Default:** `16 * 1024`.", "name": "highWaterMark", "type": "number", "default": "`16 * 1024`", "desc": "Consistent with the readable stream `highWaterMark` parameter." }, { "textRaw": "`secureContext`: TLS context object created with [`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one will be created by passing the entire `options` object to `tls.createSecureContext()`.", "name": "secureContext", "desc": "TLS context object created with [`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one will be created by passing the entire `options` object to `tls.createSecureContext()`." }, { "textRaw": "...: [`tls.createSecureContext()`][] options that are used if the `secureContext` option is missing, otherwise they are ignored.", "name": "...", "desc": "[`tls.createSecureContext()`][] options that are used if the `secureContext` option is missing, otherwise they are ignored." }, { "textRaw": "...: Any [`socket.connect()`][] option not already listed.", "name": "...", "desc": "Any [`socket.connect()`][] option not already listed." } ] }, { "textRaw": "`callback` {Function}", "name": "callback", "type": "Function" } ] } ], "desc": "

The callback function, if specified, will be added as a listener for the\n'secureConnect' event.

\n

tls.connect() returns a tls.TLSSocket object.

\n

Unlike the https API, tls.connect() does not enable the\nSNI (Server Name Indication) extension by default, which may cause some\nservers to return an incorrect certificate or reject the connection\naltogether. To enable SNI, set the servername option in addition\nto host.

\n

The following illustrates a client for the echo server example from\ntls.createServer():

\n
// Assumes an echo server that is listening on port 8000.\nconst tls = require('tls');\nconst fs = require('fs');\n\nconst options = {\n  // Necessary only if the server requires client certificate authentication.\n  key: fs.readFileSync('client-key.pem'),\n  cert: fs.readFileSync('client-cert.pem'),\n\n  // Necessary only if the server uses a self-signed certificate.\n  ca: [ fs.readFileSync('server-cert.pem') ],\n\n  // Necessary only if the server's cert isn't for \"localhost\".\n  checkServerIdentity: () => { return null; },\n};\n\nconst socket = tls.connect(8000, options, () => {\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', (data) => {\n  console.log(data);\n});\nsocket.on('end', () => {\n  console.log('server ends connection');\n});\n
" }, { "textRaw": "`tls.connect(path[, options][, callback])`", "type": "method", "name": "connect", "meta": { "added": [ "v0.11.3" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {tls.TLSSocket}", "name": "return", "type": "tls.TLSSocket" }, "params": [ { "textRaw": "`path` {string} Default value for `options.path`.", "name": "path", "type": "string", "desc": "Default value for `options.path`." }, { "textRaw": "`options` {Object} See [`tls.connect()`][].", "name": "options", "type": "Object", "desc": "See [`tls.connect()`][]." }, { "textRaw": "`callback` {Function} See [`tls.connect()`][].", "name": "callback", "type": "Function", "desc": "See [`tls.connect()`][]." } ] } ], "desc": "

Same as tls.connect() except that path can be provided\nas an argument instead of an option.

\n

A path option, if specified, will take precedence over the path argument.

" }, { "textRaw": "`tls.connect(port[, host][, options][, callback])`", "type": "method", "name": "connect", "meta": { "added": [ "v0.11.3" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {tls.TLSSocket}", "name": "return", "type": "tls.TLSSocket" }, "params": [ { "textRaw": "`port` {number} Default value for `options.port`.", "name": "port", "type": "number", "desc": "Default value for `options.port`." }, { "textRaw": "`host` {string} Default value for `options.host`.", "name": "host", "type": "string", "desc": "Default value for `options.host`." }, { "textRaw": "`options` {Object} See [`tls.connect()`][].", "name": "options", "type": "Object", "desc": "See [`tls.connect()`][]." }, { "textRaw": "`callback` {Function} See [`tls.connect()`][].", "name": "callback", "type": "Function", "desc": "See [`tls.connect()`][]." } ] } ], "desc": "

Same as tls.connect() except that port and host can be provided\nas arguments instead of options.

\n

A port or host option, if specified, will take precedence over any port or host\nargument.

" }, { "textRaw": "`tls.createSecureContext([options])`", "type": "method", "name": "createSecureContext", "meta": { "added": [ "v0.11.13" ], "changes": [ { "version": "v12.12.0", "pr-url": "https://github.com/nodejs/node/pull/28973", "description": "Added `privateKeyIdentifier` and `privateKeyEngine` options to get private key from an OpenSSL engine." }, { "version": "v12.11.0", "pr-url": "https://github.com/nodejs/node/pull/29598", "description": "Added `sigalgs` option to override supported signature algorithms." }, { "version": "v12.0.0", "pr-url": "https://github.com/nodejs/node/pull/26209", "description": "TLSv1.3 support added." }, { "version": "v11.5.0", "pr-url": "https://github.com/nodejs/node/pull/24733", "description": "The `ca:` option now supports `BEGIN TRUSTED CERTIFICATE`." }, { "version": [ "v11.4.0", "v10.16.0" ], "pr-url": "https://github.com/nodejs/node/pull/24405", "description": "The `minVersion` and `maxVersion` can be used to restrict the allowed TLS protocol versions." }, { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/19794", "description": "The `ecdhCurve` cannot be set to `false` anymore due to a change in OpenSSL." }, { "version": "v9.3.0", "pr-url": "https://github.com/nodejs/node/pull/14903", "description": "The `options` parameter can now include `clientCertEngine`." }, { "version": "v9.0.0", "pr-url": "https://github.com/nodejs/node/pull/15206", "description": "The `ecdhCurve` option can now be multiple `':'` separated curve names or `'auto'`." }, { "version": "v7.3.0", "pr-url": "https://github.com/nodejs/node/pull/10294", "description": "If the `key` option is an array, individual entries do not need a `passphrase` property anymore. `Array` entries can also just be `string`s or `Buffer`s now." }, { "version": "v5.2.0", "pr-url": "https://github.com/nodejs/node/pull/4099", "description": "The `ca` option can now be a single string containing multiple CA certificates." } ] }, "signatures": [ { "params": [ { "textRaw": "`options` {Object}", "name": "options", "type": "Object", "options": [ { "textRaw": "`ca` {string|string[]|Buffer|Buffer[]} Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified using this option. The value can be a string or `Buffer`, or an `Array` of strings and/or `Buffer`s. Any string or `Buffer` can contain multiple PEM CAs concatenated together. The peer's certificate must be chainable to a CA trusted by the server for the connection to be authenticated. When using certificates that are not chainable to a well-known CA, the certificate's CA must be explicitly specified as a trusted or the connection will fail to authenticate. If the peer uses a certificate that doesn't match or chain to one of the default CAs, use the `ca` option to provide a CA certificate that the peer's certificate can match or chain to. For self-signed certificates, the certificate is its own CA, and must be provided. For PEM encoded certificates, supported types are \"TRUSTED CERTIFICATE\", \"X509 CERTIFICATE\", and \"CERTIFICATE\". See also [`tls.rootCertificates`][].", "name": "ca", "type": "string|string[]|Buffer|Buffer[]", "desc": "Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified using this option. The value can be a string or `Buffer`, or an `Array` of strings and/or `Buffer`s. Any string or `Buffer` can contain multiple PEM CAs concatenated together. The peer's certificate must be chainable to a CA trusted by the server for the connection to be authenticated. When using certificates that are not chainable to a well-known CA, the certificate's CA must be explicitly specified as a trusted or the connection will fail to authenticate. If the peer uses a certificate that doesn't match or chain to one of the default CAs, use the `ca` option to provide a CA certificate that the peer's certificate can match or chain to. For self-signed certificates, the certificate is its own CA, and must be provided. For PEM encoded certificates, supported types are \"TRUSTED CERTIFICATE\", \"X509 CERTIFICATE\", and \"CERTIFICATE\". See also [`tls.rootCertificates`][]." }, { "textRaw": "`cert` {string|string[]|Buffer|Buffer[]} Cert chains in PEM format. One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private `key`, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see `ca`). When providing multiple cert chains, they do not have to be in the same order as their private keys in `key`. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail.", "name": "cert", "type": "string|string[]|Buffer|Buffer[]", "desc": "Cert chains in PEM format. One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private `key`, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see `ca`). When providing multiple cert chains, they do not have to be in the same order as their private keys in `key`. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail." }, { "textRaw": "`sigalgs` {string} Colon-separated list of supported signature algorithms. The list can contain digest algorithms (`SHA256`, `MD5` etc.), public key algorithms (`RSA-PSS`, `ECDSA` etc.), combination of both (e.g 'RSA+SHA384') or TLS v1.3 scheme names (e.g. `rsa_pss_pss_sha512`). See [OpenSSL man pages](https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set1_sigalgs_list.html) for more info.", "name": "sigalgs", "type": "string", "desc": "Colon-separated list of supported signature algorithms. The list can contain digest algorithms (`SHA256`, `MD5` etc.), public key algorithms (`RSA-PSS`, `ECDSA` etc.), combination of both (e.g 'RSA+SHA384') or TLS v1.3 scheme names (e.g. `rsa_pss_pss_sha512`). See [OpenSSL man pages](https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set1_sigalgs_list.html) for more info." }, { "textRaw": "`ciphers` {string} Cipher suite specification, replacing the default. For more information, see [modifying the default cipher suite][]. Permitted ciphers can be obtained via [`tls.getCiphers()`][]. Cipher names must be uppercased in order for OpenSSL to accept them.", "name": "ciphers", "type": "string", "desc": "Cipher suite specification, replacing the default. For more information, see [modifying the default cipher suite][]. Permitted ciphers can be obtained via [`tls.getCiphers()`][]. Cipher names must be uppercased in order for OpenSSL to accept them." }, { "textRaw": "`clientCertEngine` {string} Name of an OpenSSL engine which can provide the client certificate.", "name": "clientCertEngine", "type": "string", "desc": "Name of an OpenSSL engine which can provide the client certificate." }, { "textRaw": "`crl` {string|string[]|Buffer|Buffer[]} PEM formatted CRLs (Certificate Revocation Lists).", "name": "crl", "type": "string|string[]|Buffer|Buffer[]", "desc": "PEM formatted CRLs (Certificate Revocation Lists)." }, { "textRaw": "`dhparam` {string|Buffer} Diffie-Hellman parameters, required for [perfect forward secrecy][]. Use `openssl dhparam` to create the parameters. The key length must be greater than or equal to 1024 bits or else an error will be thrown. Although 1024 bits is permissible, use 2048 bits or larger for stronger security. If omitted or invalid, the parameters are silently discarded and DHE ciphers will not be available.", "name": "dhparam", "type": "string|Buffer", "desc": "Diffie-Hellman parameters, required for [perfect forward secrecy][]. Use `openssl dhparam` to create the parameters. The key length must be greater than or equal to 1024 bits or else an error will be thrown. Although 1024 bits is permissible, use 2048 bits or larger for stronger security. If omitted or invalid, the parameters are silently discarded and DHE ciphers will not be available." }, { "textRaw": "`ecdhCurve` {string} A string describing a named curve or a colon separated list of curve NIDs or names, for example `P-521:P-384:P-256`, to use for ECDH key agreement. Set to `auto` to select the curve automatically. Use [`crypto.getCurves()`][] to obtain a list of available curve names. On recent releases, `openssl ecparam -list_curves` will also display the name and description of each available elliptic curve. **Default:** [`tls.DEFAULT_ECDH_CURVE`][].", "name": "ecdhCurve", "type": "string", "default": "[`tls.DEFAULT_ECDH_CURVE`][]", "desc": "A string describing a named curve or a colon separated list of curve NIDs or names, for example `P-521:P-384:P-256`, to use for ECDH key agreement. Set to `auto` to select the curve automatically. Use [`crypto.getCurves()`][] to obtain a list of available curve names. On recent releases, `openssl ecparam -list_curves` will also display the name and description of each available elliptic curve." }, { "textRaw": "`honorCipherOrder` {boolean} Attempt to use the server's cipher suite preferences instead of the client's. When `true`, causes `SSL_OP_CIPHER_SERVER_PREFERENCE` to be set in `secureOptions`, see [OpenSSL Options][] for more information.", "name": "honorCipherOrder", "type": "boolean", "desc": "Attempt to use the server's cipher suite preferences instead of the client's. When `true`, causes `SSL_OP_CIPHER_SERVER_PREFERENCE` to be set in `secureOptions`, see [OpenSSL Options][] for more information." }, { "textRaw": "`key` {string|string[]|Buffer|Buffer[]|Object[]} Private keys in PEM format. PEM allows the option of private keys being encrypted. Encrypted keys will be decrypted with `options.passphrase`. Multiple keys using different algorithms can be provided either as an array of unencrypted key strings or buffers, or an array of objects in the form `{pem: [, passphrase: ]}`. The object form can only occur in an array. `object.passphrase` is optional. Encrypted keys will be decrypted with `object.passphrase` if provided, or `options.passphrase` if it is not.", "name": "key", "type": "string|string[]|Buffer|Buffer[]|Object[]", "desc": "Private keys in PEM format. PEM allows the option of private keys being encrypted. Encrypted keys will be decrypted with `options.passphrase`. Multiple keys using different algorithms can be provided either as an array of unencrypted key strings or buffers, or an array of objects in the form `{pem: [, passphrase: ]}`. The object form can only occur in an array. `object.passphrase` is optional. Encrypted keys will be decrypted with `object.passphrase` if provided, or `options.passphrase` if it is not." }, { "textRaw": "`privateKeyEngine` {string} Name of an OpenSSL engine to get private key from. Should be used together with `privateKeyIdentifier`.", "name": "privateKeyEngine", "type": "string", "desc": "Name of an OpenSSL engine to get private key from. Should be used together with `privateKeyIdentifier`." }, { "textRaw": "`privateKeyIdentifier` {string} Identifier of a private key managed by an OpenSSL engine. Should be used together with `privateKeyEngine`. Should not be set together with `key`, because both options define a private key in different ways.", "name": "privateKeyIdentifier", "type": "string", "desc": "Identifier of a private key managed by an OpenSSL engine. Should be used together with `privateKeyEngine`. Should not be set together with `key`, because both options define a private key in different ways." }, { "textRaw": "`maxVersion` {string} Optionally set the maximum TLS version to allow. One of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the `secureProtocol` option, use one or the other. **Default:** [`tls.DEFAULT_MAX_VERSION`][].", "name": "maxVersion", "type": "string", "default": "[`tls.DEFAULT_MAX_VERSION`][]", "desc": "Optionally set the maximum TLS version to allow. One of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the `secureProtocol` option, use one or the other." }, { "textRaw": "`minVersion` {string} Optionally set the minimum TLS version to allow. One of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the `secureProtocol` option, use one or the other. It is not recommended to use less than TLSv1.2, but it may be required for interoperability. **Default:** [`tls.DEFAULT_MIN_VERSION`][].", "name": "minVersion", "type": "string", "default": "[`tls.DEFAULT_MIN_VERSION`][]", "desc": "Optionally set the minimum TLS version to allow. One of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the `secureProtocol` option, use one or the other. It is not recommended to use less than TLSv1.2, but it may be required for interoperability." }, { "textRaw": "`passphrase` {string} Shared passphrase used for a single private key and/or a PFX.", "name": "passphrase", "type": "string", "desc": "Shared passphrase used for a single private key and/or a PFX." }, { "textRaw": "`pfx` {string|string[]|Buffer|Buffer[]|Object[]} PFX or PKCS12 encoded private key and certificate chain. `pfx` is an alternative to providing `key` and `cert` individually. PFX is usually encrypted, if it is, `passphrase` will be used to decrypt it. Multiple PFX can be provided either as an array of unencrypted PFX buffers, or an array of objects in the form `{buf: [, passphrase: ]}`. The object form can only occur in an array. `object.passphrase` is optional. Encrypted PFX will be decrypted with `object.passphrase` if provided, or `options.passphrase` if it is not.", "name": "pfx", "type": "string|string[]|Buffer|Buffer[]|Object[]", "desc": "PFX or PKCS12 encoded private key and certificate chain. `pfx` is an alternative to providing `key` and `cert` individually. PFX is usually encrypted, if it is, `passphrase` will be used to decrypt it. Multiple PFX can be provided either as an array of unencrypted PFX buffers, or an array of objects in the form `{buf: [, passphrase: ]}`. The object form can only occur in an array. `object.passphrase` is optional. Encrypted PFX will be decrypted with `object.passphrase` if provided, or `options.passphrase` if it is not." }, { "textRaw": "`secureOptions` {number} Optionally affect the OpenSSL protocol behavior, which is not usually necessary. This should be used carefully if at all! Value is a numeric bitmask of the `SSL_OP_*` options from [OpenSSL Options][].", "name": "secureOptions", "type": "number", "desc": "Optionally affect the OpenSSL protocol behavior, which is not usually necessary. This should be used carefully if at all! Value is a numeric bitmask of the `SSL_OP_*` options from [OpenSSL Options][]." }, { "textRaw": "`secureProtocol` {string} Legacy mechanism to select the TLS protocol version to use, it does not support independent control of the minimum and maximum version, and does not support limiting the protocol to TLSv1.3. Use `minVersion` and `maxVersion` instead. The possible values are listed as [SSL_METHODS][], use the function names as strings. For example, use `'TLSv1_1_method'` to force TLS version 1.1, or `'TLS_method'` to allow any TLS protocol version up to TLSv1.3. It is not recommended to use TLS versions less than 1.2, but it may be required for interoperability. **Default:** none, see `minVersion`.", "name": "secureProtocol", "type": "string", "default": "none, see `minVersion`", "desc": "Legacy mechanism to select the TLS protocol version to use, it does not support independent control of the minimum and maximum version, and does not support limiting the protocol to TLSv1.3. Use `minVersion` and `maxVersion` instead. The possible values are listed as [SSL_METHODS][], use the function names as strings. For example, use `'TLSv1_1_method'` to force TLS version 1.1, or `'TLS_method'` to allow any TLS protocol version up to TLSv1.3. It is not recommended to use TLS versions less than 1.2, but it may be required for interoperability." }, { "textRaw": "`sessionIdContext` {string} Opaque identifier used by servers to ensure session state is not shared between applications. Unused by clients.", "name": "sessionIdContext", "type": "string", "desc": "Opaque identifier used by servers to ensure session state is not shared between applications. Unused by clients." }, { "textRaw": "`ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudo-random data. See [Session Resumption][] for more information.", "name": "ticketKeys", "type": "Buffer", "desc": "48-bytes of cryptographically strong pseudo-random data. See [Session Resumption][] for more information." }, { "textRaw": "`sessionTimeout` {number} The number of seconds after which a TLS session created by the server will no longer be resumable. See [Session Resumption][] for more information. **Default:** `300`.", "name": "sessionTimeout", "type": "number", "default": "`300`", "desc": "The number of seconds after which a TLS session created by the server will no longer be resumable. See [Session Resumption][] for more information." } ] } ] } ], "desc": "

tls.createServer() sets the default value of the honorCipherOrder option\nto true, other APIs that create secure contexts leave it unset.

\n

tls.createServer() uses a 128 bit truncated SHA1 hash value generated\nfrom process.argv as the default value of the sessionIdContext option, other\nAPIs that create secure contexts have no default value.

\n

The tls.createSecureContext() method creates a SecureContext object. It is\nusable as an argument to several tls APIs, such as tls.createServer()\nand server.addContext(), but has no public methods.

\n

A key is required for ciphers that make use of certificates. Either key or\npfx can be used to provide it.

\n

If the ca option is not given, then Node.js will default to using\nMozilla's publicly trusted list of CAs.

" }, { "textRaw": "`tls.createServer([options][, secureConnectionListener])`", "type": "method", "name": "createServer", "meta": { "added": [ "v0.3.2" ], "changes": [ { "version": "v12.3.0", "pr-url": "https://github.com/nodejs/node/pull/27665", "description": "The `options` parameter now supports `net.createServer()` options." }, { "version": "v9.3.0", "pr-url": "https://github.com/nodejs/node/pull/14903", "description": "The `options` parameter can now include `clientCertEngine`." }, { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/11984", "description": "The `ALPNProtocols` option can be a `TypedArray` or `DataView` now." }, { "version": "v5.0.0", "pr-url": "https://github.com/nodejs/node/pull/2564", "description": "ALPN options are supported now." } ] }, "signatures": [ { "return": { "textRaw": "Returns: {tls.Server}", "name": "return", "type": "tls.Server" }, "params": [ { "textRaw": "`options` {Object}", "name": "options", "type": "Object", "options": [ { "textRaw": "`ALPNProtocols`: {string[]|Buffer[]|TypedArray[]|DataView[]|Buffer| TypedArray|DataView} An array of strings, `Buffer`s or `TypedArray`s or `DataView`s, or a single `Buffer` or `TypedArray` or `DataView` containing the supported ALPN protocols. `Buffer`s should have the format `[len][name][len][name]...` e.g. `0x05hello0x05world`, where the first byte is the length of the next protocol name. Passing an array is usually much simpler, e.g. `['hello', 'world']`. (Protocols should be ordered by their priority.)", "name": "ALPNProtocols", "type": "string[]|Buffer[]|TypedArray[]|DataView[]|Buffer| TypedArray|DataView", "desc": "An array of strings, `Buffer`s or `TypedArray`s or `DataView`s, or a single `Buffer` or `TypedArray` or `DataView` containing the supported ALPN protocols. `Buffer`s should have the format `[len][name][len][name]...` e.g. `0x05hello0x05world`, where the first byte is the length of the next protocol name. Passing an array is usually much simpler, e.g. `['hello', 'world']`. (Protocols should be ordered by their priority.)" }, { "textRaw": "`clientCertEngine` {string} Name of an OpenSSL engine which can provide the client certificate.", "name": "clientCertEngine", "type": "string", "desc": "Name of an OpenSSL engine which can provide the client certificate." }, { "textRaw": "`enableTrace` {boolean} If `true`, [`tls.TLSSocket.enableTrace()`][] will be called on new connections. Tracing can be enabled after the secure connection is established, but this option must be used to trace the secure connection setup. **Default:** `false`.", "name": "enableTrace", "type": "boolean", "default": "`false`", "desc": "If `true`, [`tls.TLSSocket.enableTrace()`][] will be called on new connections. Tracing can be enabled after the secure connection is established, but this option must be used to trace the secure connection setup." }, { "textRaw": "`handshakeTimeout` {number} Abort the connection if the SSL/TLS handshake does not finish in the specified number of milliseconds. A `'tlsClientError'` is emitted on the `tls.Server` object whenever a handshake times out. **Default:** `120000` (120 seconds).", "name": "handshakeTimeout", "type": "number", "default": "`120000` (120 seconds)", "desc": "Abort the connection if the SSL/TLS handshake does not finish in the specified number of milliseconds. A `'tlsClientError'` is emitted on the `tls.Server` object whenever a handshake times out." }, { "textRaw": "`rejectUnauthorized` {boolean} If not `false` the server will reject any connection which is not authorized with the list of supplied CAs. This option only has an effect if `requestCert` is `true`. **Default:** `true`.", "name": "rejectUnauthorized", "type": "boolean", "default": "`true`", "desc": "If not `false` the server will reject any connection which is not authorized with the list of supplied CAs. This option only has an effect if `requestCert` is `true`." }, { "textRaw": "`requestCert` {boolean} If `true` the server will request a certificate from clients that connect and attempt to verify that certificate. **Default:** `false`.", "name": "requestCert", "type": "boolean", "default": "`false`", "desc": "If `true` the server will request a certificate from clients that connect and attempt to verify that certificate." }, { "textRaw": "`sessionTimeout` {number} The number of seconds after which a TLS session created by the server will no longer be resumable. See [Session Resumption][] for more information. **Default:** `300`.", "name": "sessionTimeout", "type": "number", "default": "`300`", "desc": "The number of seconds after which a TLS session created by the server will no longer be resumable. See [Session Resumption][] for more information." }, { "textRaw": "`SNICallback(servername, callback)` {Function} A function that will be called if the client supports SNI TLS extension. Two arguments will be passed when called: `servername` and `callback`. `callback` is an error-first callback that takes two optional arguments: `error` and `ctx`. `ctx`, if provided, is a `SecureContext` instance. [`tls.createSecureContext()`][] can be used to get a proper `SecureContext`. If `callback` is called with a falsy `ctx` argument, the default secure context of the server will be used. If `SNICallback` wasn't provided the default callback with high-level API will be used (see below).", "name": "SNICallback(servername,", "desc": "callback)` {Function} A function that will be called if the client supports SNI TLS extension. Two arguments will be passed when called: `servername` and `callback`. `callback` is an error-first callback that takes two optional arguments: `error` and `ctx`. `ctx`, if provided, is a `SecureContext` instance. [`tls.createSecureContext()`][] can be used to get a proper `SecureContext`. If `callback` is called with a falsy `ctx` argument, the default secure context of the server will be used. If `SNICallback` wasn't provided the default callback with high-level API will be used (see below)." }, { "textRaw": "`ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudo-random data. See [Session Resumption][] for more information.", "name": "ticketKeys", "type": "Buffer", "desc": "48-bytes of cryptographically strong pseudo-random data. See [Session Resumption][] for more information." }, { "textRaw": "`pskCallback` {Function}", "name": "pskCallback", "type": "Function", "options": [ { "textRaw": "socket: {tls.TLSSocket} the server [`tls.TLSSocket`][] instance for this connection.", "name": "socket", "type": "tls.TLSSocket", "desc": "the server [`tls.TLSSocket`][] instance for this connection." }, { "textRaw": "identity: {string} identity parameter sent from the client.", "name": "identity", "type": "string", "desc": "identity parameter sent from the client." }, { "textRaw": "Returns: {Buffer|TypedArray|DataView} pre-shared key that must either be a buffer or `null` to stop the negotiation process. Returned PSK must be compatible with the selected cipher's digest. When negotiating TLS-PSK (pre-shared keys), this function is called with the identity provided by the client. If the return value is `null` the negotiation process will stop and an \"unknown_psk_identity\" alert message will be sent to the other party. If the server wishes to hide the fact that the PSK identity was not known, the callback must provide some random data as `psk` to make the connection fail with \"decrypt_error\" before negotiation is finished. PSK ciphers are disabled by default, and using TLS-PSK thus requires explicitly specifying a cipher suite with the `ciphers` option. More information can be found in the [RFC 4279][].", "name": "return", "type": "Buffer|TypedArray|DataView", "desc": "pre-shared key that must either be a buffer or `null` to stop the negotiation process. Returned PSK must be compatible with the selected cipher's digest. When negotiating TLS-PSK (pre-shared keys), this function is called with the identity provided by the client. If the return value is `null` the negotiation process will stop and an \"unknown_psk_identity\" alert message will be sent to the other party. If the server wishes to hide the fact that the PSK identity was not known, the callback must provide some random data as `psk` to make the connection fail with \"decrypt_error\" before negotiation is finished. PSK ciphers are disabled by default, and using TLS-PSK thus requires explicitly specifying a cipher suite with the `ciphers` option. More information can be found in the [RFC 4279][]." } ] }, { "textRaw": "`pskIdentityHint` {string} optional hint to send to a client to help with selecting the identity during TLS-PSK negotiation. Will be ignored in TLS 1.3. Upon failing to set pskIdentityHint `'tlsClientError'` will be emitted with `'ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED'` code.", "name": "pskIdentityHint", "type": "string", "desc": "optional hint to send to a client to help with selecting the identity during TLS-PSK negotiation. Will be ignored in TLS 1.3. Upon failing to set pskIdentityHint `'tlsClientError'` will be emitted with `'ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED'` code." }, { "textRaw": "...: Any [`tls.createSecureContext()`][] option can be provided. For servers, the identity options (`pfx`, `key`/`cert` or `pskCallback`) are usually required.", "name": "...", "desc": "Any [`tls.createSecureContext()`][] option can be provided. For servers, the identity options (`pfx`, `key`/`cert` or `pskCallback`) are usually required." }, { "textRaw": "...: Any [`net.createServer()`][] option can be provided.", "name": "...", "desc": "Any [`net.createServer()`][] option can be provided." } ] }, { "textRaw": "`secureConnectionListener` {Function}", "name": "secureConnectionListener", "type": "Function" } ] } ], "desc": "

Creates a new tls.Server. The secureConnectionListener, if provided, is\nautomatically set as a listener for the 'secureConnection' event.

\n

The ticketKeys options is automatically shared between cluster module\nworkers.

\n

The following illustrates a simple echo server:

\n
const tls = require('tls');\nconst fs = require('fs');\n\nconst options = {\n  key: fs.readFileSync('server-key.pem'),\n  cert: fs.readFileSync('server-cert.pem'),\n\n  // This is necessary only if using client certificate authentication.\n  requestCert: true,\n\n  // This is necessary only if the client uses a self-signed certificate.\n  ca: [ fs.readFileSync('client-cert.pem') ]\n};\n\nconst server = tls.createServer(options, (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, () => {\n  console.log('server bound');\n});\n
\n

The server can be tested by connecting to it using the example client from\ntls.connect().

" }, { "textRaw": "`tls.getCiphers()`", "type": "method", "name": "getCiphers", "meta": { "added": [ "v0.10.2" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {string[]}", "name": "return", "type": "string[]" }, "params": [] } ], "desc": "

Returns an array with the names of the supported TLS ciphers. The names are\nlower-case for historical reasons, but must be uppercased to be used in\nthe ciphers option of tls.createSecureContext().

\n

Cipher names that start with 'tls_' are for TLSv1.3, all the others are for\nTLSv1.2 and below.

\n
console.log(tls.getCiphers()); // ['aes128-gcm-sha256', 'aes128-sha', ...]\n
" } ], "properties": [ { "textRaw": "`rootCertificates` {string[]}", "type": "string[]", "name": "rootCertificates", "meta": { "added": [ "v12.3.0" ], "changes": [] }, "desc": "

An immutable array of strings representing the root certificates (in PEM format)\nfrom the bundled Mozilla CA store as supplied by current Node.js version.

\n

The bundled CA store, as supplied by Node.js, is a snapshot of Mozilla CA store\nthat is fixed at release time. It is identical on all supported platforms.

" }, { "textRaw": "`tls.DEFAULT_ECDH_CURVE`", "name": "DEFAULT_ECDH_CURVE", "meta": { "added": [ "v0.11.13" ], "changes": [ { "version": "v10.0.0", "pr-url": "https://github.com/nodejs/node/pull/16853", "description": "Default value changed to `'auto'`." } ] }, "desc": "

The default curve name to use for ECDH key agreement in a tls server. The\ndefault value is 'auto'. See tls.createSecureContext() for further\ninformation.

" }, { "textRaw": "`DEFAULT_MAX_VERSION` {string} The default value of the `maxVersion` option of [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. **Default:** `'TLSv1.3'`, unless changed using CLI options. Using `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used.", "type": "string", "name": "DEFAULT_MAX_VERSION", "meta": { "added": [ "v11.4.0" ], "changes": [] }, "default": "`'TLSv1.3'`, unless changed using CLI options. Using `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used", "desc": "The default value of the `maxVersion` option of [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`." }, { "textRaw": "`DEFAULT_MIN_VERSION` {string} The default value of the `minVersion` option of [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. **Default:** `'TLSv1.2'`, unless changed using CLI options. Using `--tls-min-v1.0` sets the default to `'TLSv1'`. Using `--tls-min-v1.1` sets the default to `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to `'TLSv1.3'`. If multiple of the options are provided, the lowest minimum is used.", "type": "string", "name": "DEFAULT_MIN_VERSION", "meta": { "added": [ "v11.4.0" ], "changes": [] }, "default": "`'TLSv1.2'`, unless changed using CLI options. Using `--tls-min-v1.0` sets the default to `'TLSv1'`. Using `--tls-min-v1.1` sets the default to `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to `'TLSv1.3'`. If multiple of the options are provided, the lowest minimum is used", "desc": "The default value of the `minVersion` option of [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`." } ], "type": "module", "displayName": "TLS (SSL)" } ] }