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

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 of\nkey-agreement (i.e., key-exchange) methods. That is, the server and client keys\nare used to negotiate new temporary keys that are used specifically and only for\nthe current communication session. Practically, this means that even if the\nserver's private key is compromised, communication can only be decrypted by\neavesdroppers 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.

" }, { "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": "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.

" } ], "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).

\n

Session Identifiers 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 must call tls.TLSSocket.getSession() after the\n'secureConnect' event to get the session data, and provide the data to the\nsession option of tls.connect() to 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.

\n

Session Tickets 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

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 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.\nCurrently, the default cipher suite is:

\n
ECDHE-RSA-AES128-GCM-SHA256:\nECDHE-ECDSA-AES128-GCM-SHA256:\nECDHE-RSA-AES256-GCM-SHA384:\nECDHE-ECDSA-AES256-GCM-SHA384:\nDHE-RSA-AES128-GCM-SHA256:\nECDHE-RSA-AES128-SHA256:\nDHE-RSA-AES128-SHA256:\nECDHE-RSA-AES256-SHA384:\nDHE-RSA-AES256-SHA384:\nECDHE-RSA-AES256-SHA256:\nDHE-RSA-AES256-SHA256:\nHIGH:\n!aNULL:\n!eNULL:\n!EXPORT:\n!DES:\n!RC4:\n!MD5:\n!PSK:\n!SRP:\n!CAMELLIA\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

Consult OpenSSL cipher list format documentation for details on the format.

\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.

", "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()`", "optional": true }, { "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.", "optional": true }, { "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`.", "optional": 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`.", "optional": true }, { "textRaw": "`options`", "name": "options", "options": [ { "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." } ], "optional": true } ] } ], "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": "

The tls.Server class is a subclass of net.Server that accepts encrypted\nconnections using TLS or SSL.

", "events": [ { "textRaw": "Event: 'keylog'", "type": "event", "name": "keylog", "meta": { "added": [ "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": [] }, "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. Note that 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 hostname or wildcard (e.g. `'*'`)", "name": "hostname", "type": "string", "desc": "A SNI hostname 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.", "optional": true } ] } ], "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.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": "

The tls.TLSSocket is a subclass of net.Socket that performs transparent\nencryption of written data and all required TLS negotiation.

\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": [ "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 client 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.

" } ], "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.getCipher()", "type": "method", "name": "getCipher", "meta": { "added": [ "v0.11.4" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object}", "name": "return", "type": "Object" }, "params": [] } ], "desc": "

Returns an object representing the cipher name. The version key is a legacy\nfield which always contains the value 'TLSv1/SSLv3'.

\n

For example: { name: 'AES256-SHA', version: 'TLSv1/SSLv3' }.

\n

See SSL_CIPHER_get_name() in\nhttps://www.openssl.org/docs/man1.1.0/ssl/SSL_CIPHER_get_name.html for more\ninformation.

" }, { "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}", "name": "return", "type": "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.", "optional": true } ] } ], "desc": "

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

\n

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

\n
{ subject:\n   { C: 'UK',\n     ST: 'Acknack Ltd',\n     L: 'Rhys Jones',\n     O: 'node.js',\n     OU: 'Test TLS Certificate',\n     CN: 'localhost' },\n  issuer:\n   { C: 'UK',\n     ST: 'Acknack Ltd',\n     L: 'Rhys Jones',\n     O: 'node.js',\n     OU: 'Test TLS Certificate',\n     CN: 'localhost' },\n  issuerCertificate:\n   { ... another certificate, possibly with an .issuerCertificate ... },\n  raw: < RAW DER buffer >,\n  pubkey: < RAW DER buffer >,\n  valid_from: 'Nov 11 09:52:22 2009 GMT',\n  valid_to: 'Nov 6 09:52:22 2029 GMT',\n  fingerprint: '2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF',\n  fingerprint256: '2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF:00:11:22:33:44:55:66:77:88:99:AA:BB',\n  serialNumber: 'B9B0D332A1AA5635' }\n
\n

If the peer does not provide a certificate, an empty object will be returned.

" }, { "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 https://www.openssl.org/docs/man1.1.0/ssl/SSL_get_version.html for more\ninformation.

" }, { "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.

" }, { "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": [ { "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} A function that will be called when the renegotiation request has been completed.", "name": "callback", "type": "Function", "desc": "A function that will be called when the renegotiation request has been completed." } ] } ], "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.

" }, { "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": "`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." } ], "optional": true } ], "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} An object representing the peer's certificate. The returned object has some properties corresponding to the fields of the certificate.", "name": "cert", "type": "Object", "desc": "An object representing the peer's certificate. The returned object has some properties corresponding to the fields of the 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).

\n

The cert object contains the parsed certificate and will have a structure\nsimilar to:

\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
" }, { "textRaw": "tls.connect(options[, callback])", "type": "method", "name": "connect", "meta": { "added": [ "v0.11.3" ], "changes": [ { "version": "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 `Uint8Array` 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": "`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. Note that 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. Note that connection/disconnection/destruction of `socket` is the user's responsibility, calling `tls.connect()` will not cause `net.connect()` to be called." }, { "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": "`ALPNProtocols`: {string[]|Buffer[]|Uint8Array[]|Buffer|Uint8Array} An array of strings, `Buffer`s or `Uint8Array`s, or a single `Buffer` or `Uint8Array` 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[]|Uint8Array[]|Buffer|Uint8Array", "desc": "An array of strings, `Buffer`s or `Uint8Array`s, or a single `Buffer` or `Uint8Array` 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 hostname (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 hostname (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": "`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": "`lookup`: {Function} Custom lookup function. **Default:** [`dns.lookup()`][].", "name": "lookup", "type": "Function", "default": "[`dns.lookup()`][]", "desc": "Custom lookup function." }, { "textRaw": "`timeout`: {number} If set and if a socket is created internally, will call [`socket.setTimeout(timeout)`][] after the socket is created, but before it starts the connection.", "name": "timeout", "type": "number", "desc": "If set and if a socket is created internally, will call [`socket.setTimeout(timeout)`][] after the socket is created, but before it starts the connection." }, { "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": "`callback` {Function}", "name": "callback", "type": "Function", "optional": true } ] } ], "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

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()`][].", "optional": true }, { "textRaw": "`callback` {Function} See [`tls.connect()`][].", "name": "callback", "type": "Function", "desc": "See [`tls.connect()`][].", "optional": true } ] } ], "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`.", "optional": true }, { "textRaw": "`options` {Object} See [`tls.connect()`][].", "name": "options", "type": "Object", "desc": "See [`tls.connect()`][].", "optional": true }, { "textRaw": "`callback` {Function} See [`tls.connect()`][].", "name": "callback", "type": "Function", "desc": "See [`tls.connect()`][].", "optional": true } ] } ], "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": "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 \"X509 CERTIFICATE\", and \"CERTIFICATE\".", "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 \"X509 CERTIFICATE\", and \"CERTIFICATE\"." }, { "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": "`ciphers` {string} Cipher suite specification, replacing the default. For more information, see [modifying the default cipher suite][].", "name": "ciphers", "type": "string", "desc": "Cipher suite specification, replacing the default. For more information, see [modifying the default cipher suite][]." }, { "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, otherwise an error will be thrown. It is strongly recommended to 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, otherwise an error will be thrown. It is strongly recommended to 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": "`maxVersion` {string} Optionally set the maximum TLS version to allow. One of `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.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.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.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} The TLS protocol version to use. 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. 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": "The TLS protocol version to use. 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. 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." } ], "optional": true } ] } ], "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 credentials object.

\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 use the default\npublicly trusted list of CAs as given in\nhttps://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt.

" }, { "textRaw": "tls.createServer([options][, secureConnectionListener])", "type": "method", "name": "createServer", "meta": { "added": [ "v0.3.2" ], "changes": [ { "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 `Uint8Array` 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[]|Uint8Array[]|Buffer|Uint8Array} An array of strings, `Buffer`s or `Uint8Array`s, or a single `Buffer` or `Uint8Array` 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[]|Uint8Array[]|Buffer|Uint8Array", "desc": "An array of strings, `Buffer`s or `Uint8Array`s, or a single `Buffer` or `Uint8Array` 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": "`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, cb)` {Function} A function that will be called if the client supports SNI TLS extension. Two arguments will be passed when called: `servername` and `cb`. `SNICallback` should invoke `cb(null, ctx)`, where `ctx` is a `SecureContext` instance. (`tls.createSecureContext(...)` can be used to get a proper `SecureContext`.) If `SNICallback` wasn't provided the default callback with high-level API will be used (see below).", "name": "SNICallback(servername,", "desc": "cb)` {Function} A function that will be called if the client supports SNI TLS extension. Two arguments will be passed when called: `servername` and `cb`. `SNICallback` should invoke `cb(null, ctx)`, where `ctx` is a `SecureContext` instance. (`tls.createSecureContext(...)` can be used to get a proper `SecureContext`.) 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": "...: Any [`tls.createSecureContext()`][] option can be provided. For servers, the identity options (`pfx` or `key`/`cert`) are usually required.", "name": "...", "desc": "Any [`tls.createSecureContext()`][] option can be provided. For servers, the identity options (`pfx` or `key`/`cert`) are usually required." } ], "optional": true }, { "textRaw": "`secureConnectionListener` {Function}", "name": "secureConnectionListener", "type": "Function", "optional": true } ] } ], "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 SSL ciphers.

\n
console.log(tls.getCiphers()); // ['AES128-SHA', 'AES256-SHA', ...]\n
" } ], "properties": [ { "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.2'`, `'TLSv1.1'`, or `'TLSv1'`. **Default:** `'TLSv1.2'`.", "type": "string", "name": "DEFAULT_MAX_VERSION", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "default": "`'TLSv1.2'`", "desc": "The default value of the `maxVersion` option of [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS protocol versions, `'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.2'`, `'TLSv1.1'`, or `'TLSv1'`. **Default:** `'TLSv1'`, 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.2` sets the default to `'TLSv1.2'`. If multiple of the options are provided, the lowest minimum is used.", "type": "string", "name": "DEFAULT_MIN_VERSION", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "default": "`'TLSv1'`, 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.2` sets the default to `'TLSv1.2'`. 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.2'`, `'TLSv1.1'`, or `'TLSv1'`." } ], "type": "module", "displayName": "TLS (SSL)" } ] }