{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"tls","path":"/tls","type":"module","module":"tls","title":"TLS (SSL)","introducedIn":"v0.10.0","sourceLink":{"path":"lib/tls.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/tls.js"},"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `node: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\n```mjs\nimport tls from 'node:tls';\n```\n\n```cjs\nconst tls = require('node:tls');\n```","summary":"The `node:tls` module provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL) protocols that is built on top of OpenSSL. The module can be accessed using:","examples":[{"language":"mjs","displayName":null,"code":"import tls from 'node:tls';"},{"language":"cjs","displayName":null,"code":"const tls = require('node:tls');"}],"children":[{"kind":"section","id":"determining-if-crypto-support-is-unavailable","name":"Determining if crypto support is unavailable","title":"Determining if crypto support is unavailable","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"It is possible for Node.js to be built without including support for the\n`node:crypto` module. In such cases, attempting to `import` from `tls` or\ncalling `require('node:tls')` will result in an error being thrown.\n\nWhen using CommonJS, the error thrown can be caught using try/catch:\n\n```cjs\nlet tls;\ntry {\n  tls = require('node:tls');\n} catch (err) {\n  console.error('tls support is disabled!');\n}\n```\n\nWhen using the lexical ESM `import` keyword, the error can only be\ncaught if a handler for `process.on('uncaughtException')` is registered\n*before* any attempt to load the module is made (using, for instance,\na preload module).\n\nWhen using ESM, if there is a chance that the code may be run on a build\nof Node.js where crypto support is not enabled, consider using the\n[`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) function instead of the lexical `import` keyword:\n\n```mjs\nlet tls;\ntry {\n  tls = await import('node:tls');\n} catch (err) {\n  console.error('tls support is disabled!');\n}\n```","summary":"It is possible for Node.js to be built without including support for the `node:crypto` module. In such cases, attempting to `import` from `tls` or calling `require('node:tls')` will result in an error being thrown.","examples":[{"language":"cjs","displayName":null,"code":"let tls;\ntry {\n  tls = require('node:tls');\n} catch (err) {\n  console.error('tls support is disabled!');\n}"},{"language":"mjs","displayName":null,"code":"let tls;\ntry {\n  tls = await import('node:tls');\n} catch (err) {\n  console.error('tls support is disabled!');\n}"}],"children":[]},{"kind":"section","id":"tlsssl-concepts","name":"TLS/SSL concepts","title":"TLS/SSL concepts","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"TLS/SSL is a set of protocols that rely on a public key infrastructure (PKI) to\nenable secure communication between a client and a server. For most common\ncases, each server must have a private key.\n\nPrivate 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\n```bash\nopenssl genrsa -out ryans-key.pem 2048\n```\n\nWith 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\nThe OpenSSL command-line interface can be used to generate a CSR for a private\nkey:\n\n```bash\nopenssl req -new -sha256 -key ryans-key.pem -out ryans-csr.pem\n```\n\nOnce 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\nCreating a self-signed certificate using the OpenSSL command-line interface\nis illustrated in the example below:\n\n```bash\nopenssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem\n```\n\nOnce the certificate is generated, it can be used to generate a `.pfx` or\n`.p12` file:\n\n```bash\nopenssl pkcs12 -export -in ryans-cert.pem -inkey ryans-key.pem \\\n      -certfile ca-cert.pem -out ryans.pfx\n```\n\nWhere:\n\n* `in`: is the signed certificate\n* `inkey`: is the associated private key\n* `certfile`: is a concatenation of all Certificate Authority (CA) certs into\n  a single file, e.g. `cat ca1-cert.pem ca2-cert.pem > ca-cert.pem`","summary":"TLS/SSL is a set of protocols that rely on a public key infrastructure (PKI) to enable secure communication between a client and a server. For most common cases, each server must have a private key.","examples":[{"language":"bash","displayName":null,"code":"openssl genrsa -out ryans-key.pem 2048"},{"language":"bash","displayName":null,"code":"openssl req -new -sha256 -key ryans-key.pem -out ryans-csr.pem"},{"language":"bash","displayName":null,"code":"openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem"},{"language":"bash","displayName":null,"code":"openssl pkcs12 -export -in ryans-cert.pem -inkey ryans-key.pem \\\n      -certfile ca-cert.pem -out ryans.pfx"}],"children":[{"kind":"section","id":"perfect-forward-secrecy","name":"Perfect forward secrecy","title":"Perfect forward secrecy","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The term *[forward secrecy](https://en.wikipedia.org/wiki/Perfect_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\nPerfect 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\nCurrently two methods are commonly used to achieve perfect forward secrecy (note\nthe character \"E\" appended to the traditional abbreviations):\n\n* [ECDHE](https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman): An ephemeral version of the Elliptic Curve Diffie-Hellman\n  key-agreement protocol.\n* [DHE](https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange): An ephemeral version of the Diffie-Hellman key-agreement protocol.\n\nPerfect forward secrecy using ECDHE is enabled by default. The `ecdhCurve`\noption can be used when creating a TLS server to customize the list of supported\nECDH curves for TLSv1.2 and below, and the list of supported TLS groups for\nTLSv1.3. See [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener) for more info.\n\nDHE is disabled by default but can be enabled alongside ECDHE by setting the\n`dhparam` option to `'auto'`. Custom DHE parameters are also supported but\ndiscouraged in favor of automatically selected, well-known parameters.\n\nPerfect forward secrecy was optional up to TLSv1.2. As of TLSv1.3, (EC)DHE is\nalways used (with the exception of PSK-only connections).","summary":"The term _forward secrecy_ or _perfect forward secrecy_ describes a feature of key-agreement (i.e., key-exchange) methods. That is, the server and client keys are used to negotiate new temporary keys that are used specifically and only for the current communication session. Practically, this means that even if the server's private key is compromised, communication can only be decrypted by eavesdroppers if the attacker manages to obtain the key-pair specifically generated for the session.","examples":[],"children":[]},{"kind":"section","id":"alpn-and-sni","name":"ALPN and SNI","title":"ALPN and SNI","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"ALPN (Application-Layer Protocol Negotiation Extension) and\nSNI (Server Name Indication) are TLS handshake extensions:\n\n* ALPN: Allows the use of one TLS server for multiple protocols (HTTP, HTTP/2)\n* SNI: Allows the use of one TLS server for multiple hostnames with different\n  certificates.","summary":"ALPN (Application-Layer Protocol Negotiation Extension) and SNI (Server Name Indication) are TLS handshake extensions:","examples":[],"children":[]},{"kind":"section","id":"pre-shared-keys","name":"Pre-shared keys","title":"Pre-shared keys","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"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\nTLS-PSK is only a good choice where means exist to securely share a\nkey with every connecting machine, so it does not replace the public key\ninfrastructure (PKI) 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](https://tools.ietf.org/html/rfc4086). Deriving a shared secret from a password or other\nlow-entropy sources is not secure.\n\nPSK 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 and can be retrieved via\n`openssl ciphers -v -s -tls1_3 -psk`.\nOn the client connection, a custom `checkServerIdentity` should be passed\nbecause the default one will fail in the absence of a certificate.\n\nAccording to the [RFC 4279](https://tools.ietf.org/html/rfc4279), 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\nThe current implementation doesn't support asynchronous PSK callbacks due to the\nlimitations of the underlying OpenSSL API.\n\nTo use TLS-PSK, client and server must specify the `pskCallback` option,\na function that returns the PSK to use (which must be compatible with\nthe selected cipher's digest).\n\nIt will be called first on the client:\n\n* `hint` {string} optional message sent from the server to help the client\n  decide which identity to use during negotiation.\n  Always `null` if TLS 1.3 is used.\n* Returns: {Object} in the form\n  `{ psk: <Buffer|TypedArray|DataView>, identity: <string> }` or `null`.\n\nThen on the server:\n\n* `socket` {tls.TLSSocket} the server socket instance, equivalent to `this`.\n* `identity` {string} identity parameter sent from the client.\n* Returns: {Buffer | TypedArray | DataView} the PSK (or `null`).\n\nA return value of `null` stops the negotiation process and sends an\n`unknown_psk_identity` alert message to the other party.\nIf the server wishes to hide the fact that the PSK identity was not known,\nthe callback must provide some random data as `psk` to make the connection\nfail with `decrypt_error` before negotiation is finished.","summary":"TLS-PSK support is available as an alternative to normal certificate-based authentication. It uses a pre-shared key instead of certificates to authenticate a TLS connection, providing mutual authentication. TLS-PSK and public key infrastructure are not mutually exclusive. Clients and servers can accommodate both, choosing either of them during the normal cipher negotiation step.","examples":[],"children":[]},{"kind":"section","id":"client-initiated-renegotiation-attack-mitigation","name":"Client-initiated renegotiation attack mitigation","title":"Client-initiated renegotiation attack mitigation","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"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\nTo mitigate the risk, renegotiation is limited to three times every ten minutes.\nAn `'error'` event is emitted on the [`tls.TLSSocket`](#class-tlstlssocket) instance when this\nthreshold is exceeded. The limits are configurable:\n\n* `tls.CLIENT_RENEG_LIMIT` {number} Specifies the number of renegotiation\n  requests. **Default:** `3`.\n* `tls.CLIENT_RENEG_WINDOW` {number} Specifies the time renegotiation window\n  in seconds. **Default:** `600` (10 minutes).\n\nThe default renegotiation limits should not be modified without a full\nunderstanding of the implications and risks.\n\nTLSv1.3 does not support renegotiation.","summary":"The TLS protocol allows clients to renegotiate certain aspects of the TLS session. Unfortunately, session renegotiation requires a disproportionate amount of server-side resources, making it a potential vector for denial-of-service attacks.","examples":[],"children":[]},{"kind":"section","id":"session-resumption","name":"Session resumption","title":"Session resumption","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"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).","summary":"Establishing a TLS session can be relatively slow. The process can be sped up by saving and later reusing the session state. There are several mechanisms to do so, discussed here from oldest to newest (and preferred).","examples":[],"children":[{"kind":"section","id":"session-identifiers","name":"Session identifiers","title":"Session identifiers","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"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](https://www.ietf.org/rfc/rfc2246.txt) for more information, page 23 and\n30\\.\n\nResumption using session identifiers is supported by most web browsers when\nmaking HTTPS requests.\n\nFor Node.js, clients wait for the [`'session'`](#event-session) event to get the session data,\nand provide the data to the `session` option of a subsequent [`tls.connect()`](#tlsconnectoptions-callback)\nto reuse the session. Servers must\nimplement handlers for the [`'newSession'`](#event-newsession) and [`'resumeSession'`](#event-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.","summary":"Servers generate a unique ID for new connections and send it to the client. Clients and servers save the session state. When reconnecting, clients send the ID of their saved session state and if the server also has the state for that ID, it can agree to use it. Otherwise, the server will create a new session. See RFC 2246 for more information, page 23 and 30.","examples":[],"children":[]},{"kind":"section","id":"session-tickets","name":"Session tickets","title":"Session tickets","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"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 a 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](https://tools.ietf.org/html/rfc5077) for more information.\n\nResumption using session tickets is becoming commonly supported by many web\nbrowsers when making HTTPS requests.\n\nFor Node.js, clients use the same APIs for resumption with session identifiers\nas for resumption with session tickets. For debugging, if\n[`tls.TLSSocket.getTLSTicket()`](#tlssocketgettlsticket) returns a value, the session data contains a\nticket, otherwise it contains client-side session state.\n\nWith TLSv1.3, be aware that multiple tickets may be sent by the server,\nresulting in multiple `'session'` events, see [`'session'`](#event-session) for more\ninformation.\n\nSingle 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\nIt's possible to get the ticket keys by calling [`server.getTicketKeys()`](#servergetticketkeys) 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\n`ticketKeys` option of [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener). The keys should be regularly\nregenerated and server's keys can be reset with\n[`server.setTicketKeys()`](#serversetticketkeyskeys).\n\nSession 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\nIf clients advertise support for tickets, the server will send them. The\nserver can disable tickets by supplying\n`require('node:constants').SSL_OP_NO_TICKET` in `secureOptions`.\n\nBoth 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()`](#tlscreateserveroptions-secureconnectionlistener).\n\nFor 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\n```bash\nopenssl s_client -connect localhost:443 -reconnect\n```\n\nRead through the debug output. The first connection should say \"New\", for\nexample:\n\n```text\nNew, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256\n```\n\nSubsequent connections should say \"Reused\", for example:\n\n```text\nReused, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256\n```","summary":"The servers encrypt the entire session state and send it to the client as a \"ticket\". When reconnecting, the state is sent to the server in the initial connection. This mechanism avoids the need for a server-side session cache. If the server doesn't use the ticket, for any reason (failure to decrypt it, it's too old, etc.), it will create a new session and send a new ticket. See RFC 5077 for more information.","examples":[{"language":"bash","displayName":null,"code":"openssl s_client -connect localhost:443 -reconnect"},{"language":"text","displayName":null,"code":"New, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256"},{"language":"text","displayName":null,"code":"Reused, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256"}],"children":[]}]}]},{"kind":"section","id":"modifying-the-default-tls-cipher-suite","name":"Modifying the default TLS cipher suite","title":"Modifying the default TLS cipher suite","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"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\nThe following command can be used to show the default cipher suite:\n\n```console\nnode -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\nThis default can be replaced entirely using the [`--tls-cipher-list`](cli.html#--tls-cipher-listlist)\ncommand-line switch (directly, or via the [`NODE_OPTIONS`](cli.html#node_optionsoptions) environment\nvariable). For instance, the following makes `ECDHE-RSA-AES128-GCM-SHA256:!RC4`\nthe default TLS cipher suite:\n\n```bash\nnode --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\nTo verify, use the following command to show the set cipher list, note the\ndifference between `defaultCoreCipherList` and `defaultCipherList`:\n\n```bash\nnode --tls-cipher-list='ECDHE-RSA-AES128-GCM-SHA256:!RC4' -p crypto.constants.defaultCipherList | tr ':' '\\n'\nECDHE-RSA-AES128-GCM-SHA256\n!RC4\n```\n\ni.e. the `defaultCoreCipherList` list is set at compilation time and the\n`defaultCipherList` is set at runtime.\n\nTo modify the default cipher suites from within the runtime, modify the\n`tls.DEFAULT_CIPHERS` variable, this must be performed before listening on any\nsockets, it will not affect sockets already opened. For example:\n\n```js\n// Remove Obsolete CBC Ciphers and RSA Key Exchange based Ciphers as they don't provide Forward Secrecy\ntls.DEFAULT_CIPHERS +=\n  ':!ECDHE-RSA-AES128-SHA:!ECDHE-RSA-AES128-SHA256:!ECDHE-RSA-AES256-SHA:!ECDHE-RSA-AES256-SHA384' +\n  ':!ECDHE-ECDSA-AES128-SHA:!ECDHE-ECDSA-AES128-SHA256:!ECDHE-ECDSA-AES256-SHA:!ECDHE-ECDSA-AES256-SHA384' +\n  ':!kRSA';\n```\n\nThe default can also be replaced on a per client or server basis using the\n`ciphers` option from [`tls.createSecureContext()`](#tlscreatesecurecontextoptions), which is also available\nin [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener), [`tls.connect()`](#tlsconnectoptions-callback), and when creating new\n[`tls.TLSSocket`](#class-tlstlssocket)s.\n\nThe 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](https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#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\nDespite 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\nThe 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\nThe default cipher suite prefers GCM ciphers for [Chrome's 'modern\ncryptography' setting](https://www.chromium.org/Home/chromium-security/education/tls#TOC-Cipher-Suites) and also prefers ECDHE and DHE ciphers for perfect\nforward secrecy, while offering *some* backward compatibility.\n\nOld 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\n[TLS recommendations](https://wiki.mozilla.org/Security/Server_Side_TLS) may offer a compatible cipher suite. For more details\non the format, see the OpenSSL [cipher list format](https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT) documentation.\n\nThere are only five TLSv1.3 cipher suites:\n\n* `'TLS_AES_256_GCM_SHA384'`\n* `'TLS_CHACHA20_POLY1305_SHA256'`\n* `'TLS_AES_128_GCM_SHA256'`\n* `'TLS_AES_128_CCM_SHA256'`\n* `'TLS_AES_128_CCM_8_SHA256'`\n\nThe first three are enabled by default. The two `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.","summary":"Node.js is built with a default suite of enabled and disabled TLS ciphers. This default cipher list can be configured when building Node.js to allow distributions to provide their own default list.","examples":[{"language":"console","displayName":null,"code":"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"},{"language":"bash","displayName":null,"code":"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"},{"language":"bash","displayName":null,"code":"node --tls-cipher-list='ECDHE-RSA-AES128-GCM-SHA256:!RC4' -p crypto.constants.defaultCipherList | tr ':' '\\n'\nECDHE-RSA-AES128-GCM-SHA256\n!RC4"},{"language":"js","displayName":null,"code":"// Remove Obsolete CBC Ciphers and RSA Key Exchange based Ciphers as they don't provide Forward Secrecy\ntls.DEFAULT_CIPHERS +=\n  ':!ECDHE-RSA-AES128-SHA:!ECDHE-RSA-AES128-SHA256:!ECDHE-RSA-AES256-SHA:!ECDHE-RSA-AES256-SHA384' +\n  ':!ECDHE-ECDSA-AES128-SHA:!ECDHE-ECDSA-AES128-SHA256:!ECDHE-ECDSA-AES256-SHA:!ECDHE-ECDSA-AES256-SHA384' +\n  ':!kRSA';"}],"children":[]},{"kind":"section","id":"openssl-security-level","name":"OpenSSL security level","title":"OpenSSL security level","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The OpenSSL library enforces security levels to control the minimum acceptable\nlevel of security for cryptographic operations. OpenSSL's security levels range\nfrom 0 to 5, with each level imposing stricter security requirements. The default\nsecurity level is 2, which is generally suitable for most modern applications.\nHowever, some legacy features and protocols, such as TLSv1, require a lower\nsecurity level (`SECLEVEL=0`) to function properly. For more detailed information,\nplease refer to the [OpenSSL documentation on security levels](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_security_level.html#DEFAULT-CALLBACK-BEHAVIOUR).","summary":"The OpenSSL library enforces security levels to control the minimum acceptable level of security for cryptographic operations. OpenSSL's security levels range from 0 to 5, with each level imposing stricter security requirements. The default security level is 2, which is generally suitable for most modern applications. However, some legacy features and protocols, such as TLSv1, require a lower security level (`SECLEVEL=0`) to function properly. For more detailed information, please refer to the OpenSSL documentation on security levels.","examples":[],"children":[{"kind":"section","id":"setting-security-levels","name":"Setting security levels","title":"Setting security levels","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"To adjust the security level in your Node.js application, you can include `@SECLEVEL=X`\nwithin a cipher string, where `X` is the desired security level. For example,\nto set the security level to 0 while using the default OpenSSL cipher list, you could use:\n\n```mjs\nimport { createServer, connect } from 'node:tls';\nimport { readFileSync } from 'node:fs';\nconst port = 8000;\n\ncreateServer({\n  key: readFileSync('server-key.pem'),\n  cert: readFileSync('server-cert.pem'),\n  ciphers: 'DEFAULT@SECLEVEL=0',\n  minVersion: 'TLSv1',\n}, function(socket) {\n  console.log('Client connected with protocol:', socket.getProtocol());\n  socket.end();\n  this.close();\n})\n.listen(port, () => {\n  connect(port, {\n    ciphers: 'DEFAULT@SECLEVEL=0',\n    minVersion: 'TLSv1',\n    maxVersion: 'TLSv1',\n    ca: [ readFileSync('server-cert.pem') ],\n  });\n});\n```\n\n```cjs\nconst { createServer, connect } = require('node:tls');\nconst { readFileSync } = require('node:fs');\nconst port = 8000;\n\ncreateServer({\n  key: readFileSync('server-key.pem'),\n  cert: readFileSync('server-cert.pem'),\n  ciphers: 'DEFAULT@SECLEVEL=0',\n  minVersion: 'TLSv1',\n}, function(socket) {\n  console.log('Client connected with protocol:', socket.getProtocol());\n  socket.end();\n  this.close();\n})\n.listen(port, () => {\n  connect(port, {\n    ciphers: 'DEFAULT@SECLEVEL=0',\n    minVersion: 'TLSv1',\n    maxVersion: 'TLSv1',\n    ca: [ readFileSync('server-cert.pem') ],\n  });\n});\n```\n\nThis approach sets the security level to 0, allowing the use of legacy features while still\nleveraging the default OpenSSL ciphers.\n\nTo generate the certificate and key for this example, run:\n\n```bash\nopenssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n  -keyout server-key.pem -out server-cert.pem\n```","summary":"To adjust the security level in your Node.js application, you can include `@SECLEVEL=X` within a cipher string, where `X` is the desired security level. For example, to set the security level to 0 while using the default OpenSSL cipher list, you could use:","examples":[{"language":"mjs","displayName":null,"code":"import { createServer, connect } from 'node:tls';\nimport { readFileSync } from 'node:fs';\nconst port = 8000;\n\ncreateServer({\n  key: readFileSync('server-key.pem'),\n  cert: readFileSync('server-cert.pem'),\n  ciphers: 'DEFAULT@SECLEVEL=0',\n  minVersion: 'TLSv1',\n}, function(socket) {\n  console.log('Client connected with protocol:', socket.getProtocol());\n  socket.end();\n  this.close();\n})\n.listen(port, () => {\n  connect(port, {\n    ciphers: 'DEFAULT@SECLEVEL=0',\n    minVersion: 'TLSv1',\n    maxVersion: 'TLSv1',\n    ca: [ readFileSync('server-cert.pem') ],\n  });\n});"},{"language":"cjs","displayName":null,"code":"const { createServer, connect } = require('node:tls');\nconst { readFileSync } = require('node:fs');\nconst port = 8000;\n\ncreateServer({\n  key: readFileSync('server-key.pem'),\n  cert: readFileSync('server-cert.pem'),\n  ciphers: 'DEFAULT@SECLEVEL=0',\n  minVersion: 'TLSv1',\n}, function(socket) {\n  console.log('Client connected with protocol:', socket.getProtocol());\n  socket.end();\n  this.close();\n})\n.listen(port, () => {\n  connect(port, {\n    ciphers: 'DEFAULT@SECLEVEL=0',\n    minVersion: 'TLSv1',\n    maxVersion: 'TLSv1',\n    ca: [ readFileSync('server-cert.pem') ],\n  });\n});"},{"language":"bash","displayName":null,"code":"openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n  -keyout server-key.pem -out server-cert.pem"}],"children":[]},{"kind":"section","id":"-tls-cipher-list","name":"Using --tls-cipher-list","title":"Using `--tls-cipher-list`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"You can also set the security level and ciphers from the command line using the\n`--tls-cipher-list=DEFAULT@SECLEVEL=X` as described in [Modifying the default TLS cipher suite](#modifying-the-default-tls-cipher-suite).\nHowever, it is generally discouraged to use the command line option for setting ciphers and it is\npreferable to configure the ciphers for individual contexts within your application code,\nas this approach provides finer control and reduces the risk of globally downgrading the security level.","summary":"You can also set the security level and ciphers from the command line using the `--tls-cipher-list=DEFAULT@SECLEVEL=X` as described in Modifying the default TLS cipher suite. However, it is generally discouraged to use the command line option for setting ciphers and it is preferable to configure the ciphers for individual contexts within your application code, as this approach provides finer control and reduces the risk of globally downgrading the security level.","examples":[],"children":[]}]},{"kind":"section","id":"x509-certificate-error-codes","name":"X509 certificate error codes","title":"X509 certificate error codes","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Multiple functions can fail due to certificate errors that are reported by\nOpenSSL. In such a case, the function provides an {Error} via its callback that\nhas the property `code` which can take one of the following values:\n\n<!--\nvalues are taken from src/crypto/crypto_common.cc\ndescription are taken from deps/openssl/openssl/crypto/x509/x509_txt.c\n-->\n\n* `'UNABLE_TO_GET_ISSUER_CERT'`: Unable to get issuer certificate.\n* `'UNABLE_TO_GET_CRL'`: Unable to get certificate CRL.\n* `'UNABLE_TO_DECRYPT_CERT_SIGNATURE'`: Unable to decrypt certificate's\n  signature.\n* `'UNABLE_TO_DECRYPT_CRL_SIGNATURE'`: Unable to decrypt CRL's signature.\n* `'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY'`: Unable to decode issuer public key.\n* `'CERT_SIGNATURE_FAILURE'`: Certificate signature failure.\n* `'CRL_SIGNATURE_FAILURE'`: CRL signature failure.\n* `'CERT_NOT_YET_VALID'`: Certificate is not yet valid.\n* `'CERT_HAS_EXPIRED'`: Certificate has expired.\n* `'CRL_NOT_YET_VALID'`: CRL is not yet valid.\n* `'CRL_HAS_EXPIRED'`: CRL has expired.\n* `'ERROR_IN_CERT_NOT_BEFORE_FIELD'`: Format error in certificate's notBefore\n  field.\n* `'ERROR_IN_CERT_NOT_AFTER_FIELD'`: Format error in certificate's notAfter\n  field.\n* `'ERROR_IN_CRL_LAST_UPDATE_FIELD'`: Format error in CRL's lastUpdate field.\n* `'ERROR_IN_CRL_NEXT_UPDATE_FIELD'`: Format error in CRL's nextUpdate field.\n* `'OUT_OF_MEM'`: Out of memory.\n* `'DEPTH_ZERO_SELF_SIGNED_CERT'`: Self signed certificate.\n* `'SELF_SIGNED_CERT_IN_CHAIN'`: Self signed certificate in certificate chain.\n* `'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'`: Unable to get local issuer certificate.\n* `'UNABLE_TO_VERIFY_LEAF_SIGNATURE'`: Unable to verify the first certificate.\n* `'CERT_CHAIN_TOO_LONG'`: Certificate chain too long.\n* `'CERT_REVOKED'`: Certificate revoked.\n* `'INVALID_CA'`: Invalid CA certificate.\n* `'PATH_LENGTH_EXCEEDED'`: Path length constraint exceeded.\n* `'INVALID_PURPOSE'`: Unsupported certificate purpose.\n* `'CERT_UNTRUSTED'`: Certificate not trusted.\n* `'CERT_REJECTED'`: Certificate rejected.\n* `'HOSTNAME_MISMATCH'`: Hostname mismatch.\n\nWhen certificate errors like `UNABLE_TO_VERIFY_LEAF_SIGNATURE`,\n`DEPTH_ZERO_SELF_SIGNED_CERT`, or `UNABLE_TO_GET_ISSUER_CERT` occur, Node.js\nappends a hint suggesting that if the root CA is installed locally,\ntry running with the `--use-system-ca` flag to direct developers towards a\nsecure solution, to prevent unsafe workarounds.","summary":"Multiple functions can fail due to certificate errors that are reported by OpenSSL. In such a case, the function provides an {Error} via its callback that has the property `code` which can take one of the following values:","examples":[],"children":[]},{"kind":"class","id":"class-tlsserver","name":"Server","title":"Class: `tls.Server`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":"Accepts encrypted connections using TLS or SSL.","summary":"Accepts encrypted connections using TLS or SSL.","examples":[],"children":[{"kind":"event","id":"event-connection","name":"connection","title":"Event: `'connection'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"This event is emitted when a new TCP stream is established, before the TLS\nhandshake begins. `socket` is typically an object of type [`net.Socket`](net.html#class-netsocket) but\nwill not receive events unlike the socket created from the [`net.Server`](net.html#class-netserver)\n`'connection'` event. Usually users will not want to access this event.\n\nThis event can also be explicitly emitted by users to inject connections\ninto the TLS server. In that case, any [`Duplex`](stream.html#class-streamduplex) stream can be passed.","summary":"This event is emitted when a new TCP stream is established, before the TLS handshake begins. `socket` is typically an object of type `net.Socket` but will not receive events unlike the socket created from the `net.Server` `'connection'` event. Usually users will not want to access this event.","examples":[],"children":[]},{"kind":"event","id":"event-keylog","name":"keylog","title":"Event: `'keylog'`","scope":"module","overloadOf":null,"stability":null,"added":["v12.3.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"line","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"Line of ASCII text, in NSS `SSLKEYLOGFILE` format.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"tlsSocket","type":{"text":"tls.TLSSocket","links":[{"name":"tls.TLSSocket","href":"tls.html#tlstlssocket","start":0,"end":13}]},"description":"The `tls.TLSSocket` instance on which it was\ngenerated.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"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\nA 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\n```js\nconst 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```","summary":"The `keylog` event is emitted when key material is generated or received by a connection to this server (typically before handshake has completed, but not necessarily). This keying material can be stored for debugging, as it allows captured TLS traffic to be decrypted. It may be emitted multiple times for each socket.","examples":[{"language":"js","displayName":null,"code":"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});"}],"children":[]},{"kind":"event","id":"event-newsession","name":"newSession","title":"Event: `'newSession'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v0.11.12"],"prUrl":"https://github.com/nodejs/node-v0.x-archive/pull/7118","commit":null,"description":"The `callback` argument is now supported."}],"parameters":[{"name":"sessionId","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The TLS session identifier","default":null,"optional":false,"rest":false,"properties":[]},{"name":"sessionData","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The TLS session data","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A callback function taking no arguments that must be\ninvoked in order for data to be sent or received over the secure connection.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"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'`](#event-resumesession) callback.\n\nThe listener callback is passed three arguments when called:\n\nListening for this event will have an effect only on connections established\nafter the addition of the event listener.","summary":"The `'newSession'` event is emitted upon creation of a new TLS session. This may be used to store sessions in external storage. The data should be provided to the `'resumeSession'` callback.","examples":[],"children":[]},{"kind":"event","id":"event-ocsprequest","name":"OCSPRequest","title":"Event: `'OCSPRequest'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.13"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"certificate","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The server certificate","default":null,"optional":false,"rest":false,"properties":[]},{"name":"issuer","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The issuer's certificate","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A callback function that must be invoked to provide\nthe results of the OCSP request.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"The `'OCSPRequest'` event is emitted when the client sends a certificate status\nrequest. The listener callback is passed three arguments when called:\n\nThe 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\nAlternatively, `callback(null, null)` may be called, indicating that there was\nno OCSP response.\n\nCalling `callback(err)` will result in a `socket.destroy(err)` call.\n\nThe typical flow of an OCSP request is as follows:\n\n1. Client connects to the server and sends an `'OCSPRequest'` (via the status\n   info extension in ClientHello).\n2. Server receives the request and emits the `'OCSPRequest'` event, calling the\n   listener if registered.\n3. Server extracts the OCSP URL from either the `certificate` or `issuer` and\n   performs an [OCSP request](https://en.wikipedia.org/wiki/OCSP_stapling) to the CA.\n4. Server receives `'OCSPResponse'` from the CA and sends it back to the client\n   via the `callback` argument\n5. Client validates the response and either destroys the socket or performs a\n   handshake.\n\nThe `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\nListening for this event will have an effect only on connections established\nafter the addition of the event listener.\n\nAn npm module like [asn1.js](https://www.npmjs.com/package/asn1.js) may be used to parse the certificates.","summary":"The `'OCSPRequest'` event is emitted when the client sends a certificate status request. The listener callback is passed three arguments when called:","examples":[],"children":[]},{"kind":"event","id":"event-resumesession","name":"resumeSession","title":"Event: `'resumeSession'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"sessionId","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The TLS session identifier","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A callback function to be called when the prior session\nhas been recovered: `callback([err[, sessionData]])`","default":null,"optional":false,"rest":false,"properties":[{"name":"err","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"sessionData","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"description":"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\nThe event listener should perform a lookup in external storage for the\n`sessionData` saved by the [`'newSession'`](#event-newsession) event handler using the given\n`sessionId`. 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\nListening for this event will have an effect only on connections established\nafter the addition of the event listener.\n\nThe following illustrates resuming a TLS session:\n\n```js\nconst 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```","summary":"The `'resumeSession'` event is emitted when the client requests to resume a previous TLS session. The listener callback is passed two arguments when called:","examples":[{"language":"js","displayName":null,"code":"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});"}],"children":[]},{"kind":"event","id":"event-secureconnection","name":"secureConnection","title":"Event: `'secureConnection'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"tlsSocket","type":{"text":"tls.TLSSocket","links":[{"name":"tls.TLSSocket","href":"tls.html#tlstlssocket","start":0,"end":13}]},"description":"The established TLS socket.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"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\nThe `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\nThe [`tls.TLSSocket.servername`](#tlssocketservername) and [`tls.TLSSocket.alpnProtocol`](#tlssocketalpnprotocol)\nproperties can be used to check which server name was requested, and which\nprotocol was negotiated.","summary":"The `'secureConnection'` event is emitted after the handshaking process for a new connection has successfully completed. The listener callback is passed a single argument when called:","examples":[],"children":[]},{"kind":"event","id":"event-tlsclienterror","name":"tlsClientError","title":"Event: `'tlsClientError'`","scope":"module","overloadOf":null,"stability":null,"added":["v6.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"exception","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"The `Error` object describing the error","default":null,"optional":false,"rest":false,"properties":[]},{"name":"tlsSocket","type":{"text":"tls.TLSSocket","links":[{"name":"tls.TLSSocket","href":"tls.html#tlstlssocket","start":0,"end":13}]},"description":"The `tls.TLSSocket` instance from which the\nerror originated.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"The `'tlsClientError'` event is emitted when an error occurs before a secure\nconnection is established. The listener callback is passed two arguments when\ncalled:","summary":"The `'tlsClientError'` event is emitted when an error occurs before a secure connection is established. The listener callback is passed two arguments when called:","examples":[],"children":[]},{"kind":"method","id":"serveraddcontexthostname-context","name":"addContext","title":"`server.addContext(hostname, context)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"hostname","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A SNI host name or wildcard (e.g. `'*'`)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"context","type":{"text":"Object | tls.SecureContext","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"tls.SecureContext","href":"tls.html#class-tlssecurecontext","start":9,"end":26}]},"description":"An object containing any of the possible\nproperties from the [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) `options` arguments\n(e.g. `key`, `cert`, `ca`, etc), or a TLS context object created with\n[`tls.createSecureContext()`](#tlscreatesecurecontextoptions) itself.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"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).\n\nWhen there are multiple matching contexts, the most recently added one is\nused.","summary":"The `server.addContext()` method adds a secure context that will be used if the client request's SNI name matches the supplied `hostname` (or wildcard).","examples":[],"children":[]},{"kind":"method","id":"serveraddress","name":"address","title":"`server.address()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns the bound address, the address family name, and port of the\nserver as reported by the operating system. See [`net.Server.address()`](net.html#serveraddress) for\nmore information.","summary":"Returns the bound address, the address family name, and port of the server as reported by the operating system. See `net.Server.address()` for more information.","examples":[],"children":[]},{"kind":"method","id":"serverclosecallback","name":"close","title":"`server.close([callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A listener callback that will be registered to listen\nfor the server instance's `'close'` event.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"tls.Server","links":[{"name":"tls.Server","href":"tls.html#class-tlsserver","start":0,"end":10}]},"description":""}},"description":"The `server.close()` method stops the server from accepting new connections.\n\nThis function operates asynchronously. The `'close'` event will be emitted\nwhen the server has no more open connections.","summary":"The `server.close()` method stops the server from accepting new connections.","examples":[],"children":[]},{"kind":"method","id":"servergetticketkeys","name":"getTicketKeys","title":"`server.getTicketKeys()`","scope":"module","overloadOf":null,"stability":null,"added":["v3.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"A 48-byte buffer containing the session ticket keys."}},"description":"Returns the session ticket keys.\n\nSee [Session Resumption](#session-resumption) for more information.","summary":"Returns the session ticket keys.","examples":[],"children":[]},{"kind":"method","id":"serverlisten","name":"listen","title":"`server.listen()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Starts the server listening for encrypted connections.\nThis method is identical to [`server.listen()`](net.html#serverlisten) from [`net.Server`](net.html#class-netserver).","summary":"Starts the server listening for encrypted connections. This method is identical to `server.listen()` from `net.Server`.","examples":[],"children":[]},{"kind":"method","id":"serversetsecurecontextoptions","name":"setSecureContext","title":"`server.setSecureContext(options)`","scope":"module","overloadOf":null,"stability":null,"added":["v11.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"An object containing any of the possible properties from\nthe [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) `options` arguments (e.g. `key`, `cert`,\n`ca`, etc).","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `server.setSecureContext()` method replaces the secure context of an\nexisting server. Existing connections to the server are not interrupted.","summary":"The `server.setSecureContext()` method replaces the secure context of an existing server. Existing connections to the server are not interrupted.","examples":[],"children":[]},{"kind":"method","id":"serversetticketkeyskeys","name":"setTicketKeys","title":"`server.setTicketKeys(keys)`","scope":"module","overloadOf":null,"stability":null,"added":["v3.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"keys","type":{"text":"Buffer | TypedArray | DataView","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6},{"name":"TypedArray","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray","start":9,"end":19},{"name":"DataView","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/DataView","start":22,"end":30}]},"description":"A 48-byte buffer containing the session\nticket keys.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Sets the session ticket keys.\n\nChanges to the ticket keys are effective only for future server connections.\nExisting or currently pending server connections will use the previous keys.\n\nSee [Session Resumption](#session-resumption) for more information.","summary":"Sets the session ticket keys.","examples":[],"children":[]}]},{"kind":"class","id":"class-tlstlssocket","name":"TLSSocket","title":"Class: `tls.TLSSocket`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"Performs transparent encryption of written data and all required TLS\nnegotiation.\n\nInstances of `tls.TLSSocket` implement the duplex [Stream](stream.html#stream) interface.\n\nMethods that return TLS connection metadata (e.g.\n[`tls.TLSSocket.getPeerCertificate()`](#tlssocketgetpeercertificatedetailed)) will only return data while the\nconnection is open.","summary":"Performs transparent encryption of written data and all required TLS negotiation.","examples":[],"children":[{"kind":"constructor","id":"new-tlstlssocketsocket-options","name":"TLSSocket","title":"`new tls.TLSSocket(socket[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v12.2.0"],"prUrl":"https://github.com/nodejs/node/pull/27497","commit":null,"description":"The `enableTrace` option is now supported."},{"versions":["v5.0.0"],"prUrl":"https://github.com/nodejs/node/pull/2564","commit":null,"description":"ALPN options are supported now."}],"signature":{"parameters":[{"name":"socket","type":{"text":"net.Socket | stream.Duplex","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10},{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":13,"end":26}]},"description":"On the server side, any `Duplex` stream. On the client side, any\ninstance of [`net.Socket`](net.html#class-netsocket) (for generic `Duplex` stream support\non the client side, [`tls.connect()`](#tlsconnectoptions-callback) must be used).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"enableTrace","type":null,"description":"See [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"isServer","type":null,"description":"The SSL/TLS protocol is asymmetrical, TLSSockets must know if\nthey are to behave as a server or a client. If `true` the TLS socket will be\ninstantiated as a server.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"server","type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":"A [`net.Server`](net.html#class-netserver) instance.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"requestCert","type":null,"description":"Whether to authenticate the remote peer by requesting a\ncertificate. Clients always request a server certificate. Servers\n(`isServer` is true) may set `requestCert` to true to request a client\ncertificate.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"rejectUnauthorized","type":null,"description":"See [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ALPNProtocols","type":null,"description":"See [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"SNICallback","type":null,"description":"See [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ALPNCallback","type":null,"description":"See [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"session","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"A `Buffer` instance containing a TLS session.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"requestOCSP","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, specifies that the OCSP status request\nextension will be added to the client hello and an `'OCSPResponse'` event\nwill be emitted on the socket before establishing a secure communication","default":null,"optional":false,"rest":false,"properties":[]},{"name":"secureContext","type":null,"description":"TLS context object created with\n[`tls.createSecureContext()`](#tlscreatesecurecontextoptions). If a `secureContext` is *not* provided, one\nwill be created by passing the entire `options` object to\n`tls.createSecureContext()`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"","type":null,"description":"...: [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) options that are used if the\n`secureContext` option is missing. Otherwise, they are ignored.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"Construct a new `tls.TLSSocket` object from an existing TCP socket.","summary":"Construct a new `tls.TLSSocket` object from an existing TCP socket.","examples":[],"children":[]},{"kind":"event","id":"event-keylog-1","name":"keylog","title":"Event: `'keylog'`","scope":"module","overloadOf":null,"stability":null,"added":["v12.3.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"line","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"Line of ASCII text, in NSS `SSLKEYLOGFILE` format.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"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\nA 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\n```js\nconst logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' });\n// ...\ntlsSocket.on('keylog', (line) => logFile.write(line));\n```","summary":"The `keylog` event is emitted on a `tls.TLSSocket` when key material is generated or received by the socket. This keying material can be stored for debugging, as it allows captured TLS traffic to be decrypted. It may be emitted multiple times, before or after the handshake completes.","examples":[{"language":"js","displayName":null,"code":"const logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' });\n// ...\ntlsSocket.on('keylog', (line) => logFile.write(line));"}],"children":[]},{"kind":"event","id":"event-ocspresponse","name":"OCSPResponse","title":"Event: `'OCSPResponse'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.13"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"response","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The server's OCSP response","default":null,"optional":false,"rest":false,"properties":[]}],"description":"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\nTypically, the `response` is a digitally signed object from the server's CA that\ncontains information about server's certificate revocation status.","summary":"The `'OCSPResponse'` event is emitted if the `requestOCSP` option was set when the `tls.TLSSocket` was created and an OCSP response has been received. The listener callback is passed a single argument when called:","examples":[],"children":[]},{"kind":"event","id":"event-secure","name":"secure","title":"Event: `'secure'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'secure'` event is emitted after the TLS handshake has successfully\ncompleted and a secure connection has been established.\n\nThis event is emitted on both client and server {tls.TLSSocket} instances,\nincluding sockets created using the `new tls.TLSSocket()` constructor.","summary":"The `'secure'` event is emitted after the TLS handshake has successfully completed and a secure connection has been established.","examples":[],"children":[]},{"kind":"event","id":"event-secureconnect","name":"secureConnect","title":"Event: `'secureConnect'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"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\n`tlsSocket.authorized === false`, then the error can be found by examining the\n`tlsSocket.authorizationError` property. If ALPN was used, the\n`tlsSocket.alpnProtocol` property can be checked to determine the negotiated\nprotocol.\n\nThe `'secureConnect'` event is not emitted when a {tls.TLSSocket} is created\nusing the `new tls.TLSSocket()` constructor.","summary":"The `'secureConnect'` event is emitted after the handshaking process for a new connection has successfully completed. The listener callback will be called regardless of whether or not the server's certificate has been authorized. It is the client's responsibility to check the `tlsSocket.authorized` property to determine if the server certificate was signed by one of the specified CAs. If `tlsSocket.authorized === false`, then the error can be found by examining the `tlsSocket.authorizationError` property. If ALPN was used, the `tlsSocket.alpnProtocol` property can be checked to determine the negotiated protocol.","examples":[],"children":[]},{"kind":"event","id":"event-session","name":"session","title":"Event: `'session'`","scope":"module","overloadOf":null,"stability":null,"added":["v11.10.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"session","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"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\nOn the client, the `session` can be provided to the `session` option of\n[`tls.connect()`](#tlsconnectoptions-callback) to resume the connection.\n\nSee [Session Resumption](#session-resumption) for more information.\n\nFor TLSv1.2 and below, [`tls.TLSSocket.getSession()`](#tlssocketgetsession) 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\n```js\ntlsSocket.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```","summary":"The `'session'` event is emitted on a client `tls.TLSSocket` when a new session or TLS ticket is available. This may or may not be before the handshake is complete, depending on the TLS protocol version that was negotiated. The event is not emitted on the server, or if a new session was not created, for example, when the connection was resumed. For some TLS protocol versions the event may be emitted multiple times, in which case all the sessions can be used for resumption.","examples":[{"language":"js","displayName":null,"code":"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});"}],"children":[]},{"kind":"method","id":"tlssocketaddress","name":"address","title":"`tlsSocket.address()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.4.0"],"prUrl":"https://github.com/nodejs/node/pull/43054","commit":null,"description":"The `family` property now returns a string instead of a number."},{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41431","commit":null,"description":"The `family` property now returns a number instead of a string."}],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"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' }`.","summary":"Returns the bound `address`, the address `family` name, and `port` of the underlying socket as reported by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.","examples":[],"children":[]},{"kind":"property","id":"tlssocketalpnprotocol","name":"alpnProtocol","title":"`tlsSocket.alpnProtocol`","scope":"module","overloadOf":null,"stability":null,"added":["v6.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string | boolean | null","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":9,"end":16},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":19,"end":23}]},"default":null,"description":"The negotiated ALPN protocol. This is `null` before the handshake completes.\nOnce the handshake completes, it settles as either the negotiated protocol\nname, or `false` if the peers did not negotiate an ALPN protocol.","summary":"The negotiated ALPN protocol. This is `null` before the handshake completes. Once the handshake completes, it settles as either the negotiated protocol name, or `false` if the peers did not negotiate an ALPN protocol.","examples":[],"children":[]},{"kind":"property","id":"tlssocketauthorizationerror","name":"authorizationError","title":"`tlsSocket.authorizationError`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"Returns the reason why the peer's certificate was not been verified. This\nproperty is set only when `tlsSocket.authorized === false`.","summary":"Returns the reason why the peer's certificate was not been verified. This property is set only when `tlsSocket.authorized === false`.","examples":[],"children":[]},{"kind":"property","id":"tlssocketauthorized","name":"authorized","title":"`tlsSocket.authorized`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"This property is `true` if the peer certificate was signed by one of the CAs\nspecified when creating the `tls.TLSSocket` instance, otherwise `false`.\n\nThe peer certificate is only verified during a full TLS handshake. When a\nconnection is established by resuming a previous session (see\n[Session Resumption](#session-resumption)), verification is not repeated. If the client\npresented a certificate in the original handshake, `authorized` and\n`authorizationError` carry the result stored with the session, including\nany verification error. On TLS 1.3, a client that sent no certificate at\nall can resume a session and report `authorized` as `true`, while\n[`tls.TLSSocket.getPeerCertificate()`](#tlssocketgetpeercertificatedetailed) returns an empty object. Servers\nthat authorize clients manually with `rejectUnauthorized: false` should\ntherefore also check [`tls.TLSSocket.isSessionReused()`](#tlssocketissessionreused) and that a peer\ncertificate is present.","summary":"This property is `true` if the peer certificate was signed by one of the CAs specified when creating the `tls.TLSSocket` instance, otherwise `false`.","examples":[],"children":[]},{"kind":"method","id":"tlssocketdisablerenegotiation","name":"disableRenegotiation","title":"`tlsSocket.disableRenegotiation()`","scope":"module","overloadOf":null,"stability":null,"added":["v8.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Disables TLS renegotiation for this `TLSSocket` instance. Once called, attempts\nto renegotiate will trigger an `'error'` event on the `TLSSocket`.","summary":"Disables TLS renegotiation for this `TLSSocket` instance. Once called, attempts to renegotiate will trigger an `'error'` event on the `TLSSocket`.","examples":[],"children":[]},{"kind":"method","id":"tlssocketenabletrace","name":"enableTrace","title":"`tlsSocket.enableTrace()`","scope":"module","overloadOf":null,"stability":null,"added":["v12.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"When enabled, TLS packet trace information is written to `stderr`. This can be\nused to debug TLS connection problems.\n\nThe format of the output is identical to the output of\n`openssl s_client -trace` or `openssl s_server -trace`. While it is produced by\nOpenSSL's `SSL_trace()` function, the format is undocumented, can change\nwithout notice, and should not be relied on.","summary":"When enabled, TLS packet trace information is written to `stderr`. This can be used to debug TLS connection problems.","examples":[],"children":[]},{"kind":"property","id":"tlssocketencrypted","name":"encrypted","title":"`tlsSocket.encrypted`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"Always returns `true`. This may be used to distinguish TLS sockets from regular\n`net.Socket` instances.","summary":"Always returns `true`. This may be used to distinguish TLS sockets from regular `net.Socket` instances.","examples":[],"children":[]},{"kind":"method","id":"tlssocketexportkeyingmateriallength-label-context","name":"exportKeyingMaterial","title":"`tlsSocket.exportKeyingMaterial(length, label[, context])`","scope":"module","overloadOf":null,"stability":null,"added":["v13.10.0","v12.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"length","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"number of bytes to retrieve from keying material","default":null,"optional":false,"rest":false,"properties":[]},{"name":"label","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"an application specific label, typically this will be a\nvalue from the\n[IANA Exporter Label Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"context","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"Optionally provide a context.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"requested bytes of the keying material"}},"description":"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\nExample\n\n```js\nconst 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\nSee the OpenSSL [`SSL_export_keying_material`](https://www.openssl.org/docs/man1.1.1/man3/SSL_export_keying_material.html) documentation for more\ninformation.","summary":"Keying material is used for validations to prevent different kind of attacks in network protocols, for example in the specifications of IEEE 802.1X.","examples":[{"language":"js","displayName":null,"code":"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*/"}],"children":[]},{"kind":"method","id":"tlssocketgetcertificate","name":"getCertificate","title":"`tlsSocket.getCertificate()`","scope":"module","overloadOf":null,"stability":null,"added":["v11.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns an object representing the local certificate. The returned object has\nsome properties corresponding to the fields of the certificate.\n\nSee [`tls.TLSSocket.getPeerCertificate()`](#tlssocketgetpeercertificatedetailed) for an example of the certificate\nstructure.\n\nIf there is no local certificate, an empty object will be returned. If the\nsocket has been destroyed, `null` will be returned.","summary":"Returns an object representing the local certificate. The returned object has some properties corresponding to the fields of the certificate.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetcipher","name":"getCipher","title":"`tlsSocket.getCipher()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v13.4.0","v12.16.0"],"prUrl":"https://github.com/nodejs/node/pull/30637","commit":null,"description":"Return the IETF cipher name as `standardName`."},{"versions":["v12.0.0"],"prUrl":"https://github.com/nodejs/node/pull/26625","commit":null,"description":"Return the minimum cipher version, instead of a fixed string (`'TLSv1/SSLv3'`)."}],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns an object containing information on the negotiated cipher suite.\n\nFor example, a TLSv1.2 protocol with AES256-SHA cipher:\n\n```json\n{\n    \"name\": \"AES256-SHA\",\n    \"standardName\": \"TLS_RSA_WITH_AES_256_CBC_SHA\",\n    \"version\": \"SSLv3\"\n}\n```\n\nSee\n[SSL\\_CIPHER\\_get\\_name](https://www.openssl.org/docs/man1.1.1/man3/SSL_CIPHER_get_name.html)\nfor more information.","summary":"Returns an object containing information on the negotiated cipher suite.","examples":[{"language":"json","displayName":null,"code":"{\n    \"name\": \"AES256-SHA\",\n    \"standardName\": \"TLS_RSA_WITH_AES_256_CBC_SHA\",\n    \"version\": \"SSLv3\"\n}"}],"children":[]},{"kind":"method","id":"tlssocketgetephemeralkeyinfo","name":"getEphemeralKeyInfo","title":"`tlsSocket.getEphemeralKeyInfo()`","scope":"module","overloadOf":null,"stability":null,"added":["v5.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns an object describing ephemeral key agreement in [perfect forward\nsecrecy](#perfect-forward-secrecy) on a client connection. It returns an empty object when the key\nagreement is not ephemeral. As this is only supported on a client socket;\n`null` is returned if called on a server socket. The supported types are `'DH'`,\n`'ECDH'`, and `'TLSGroup'`. For `'DH'` and `'ECDH'`, the object describes peer\ntemporary key parameters. For `'TLSGroup'`, the object identifies the negotiated\nTLS Supported Group used for key agreement when a peer temporary key object is\nnot available.\n\nThe `name` property is available only when type is `'ECDH'` or `'TLSGroup'`. The\n`size` property is not available when type is `'TLSGroup'`. For `'TLSGroup'`,\n`name` is the negotiated TLS Supported Group name. Standardized TLS group names\nand code points are listed in the [IANA TLS Supported Groups registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8).\n\nFor example: `{ type: 'ECDH', name: 'prime256v1', size: 256 }`.","summary":"Returns an object describing ephemeral key agreement in perfect forward secrecy on a client connection. It returns an empty object when the key agreement is not ephemeral. As this is only supported on a client socket; `null` is returned if called on a server socket. The supported types are `'DH'`, `'ECDH'`, and `'TLSGroup'`. For `'DH'` and `'ECDH'`, the object describes peer temporary key parameters. For `'TLSGroup'`, the object identifies the negotiated TLS Supported Group used for key agreement when a peer temporary key object is not available.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetfinished","name":"getFinished","title":"`tlsSocket.getFinished()`","scope":"module","overloadOf":null,"stability":null,"added":["v9.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Buffer | undefined","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"The latest `Finished` message that has been\nsent to the socket as part of an SSL/TLS handshake, or `undefined` if\nno `Finished` message has been sent yet."}},"description":"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\nCorresponds to the `SSL_get_finished` routine in OpenSSL and may be used\nto implement the `tls-unique` channel binding from [RFC 5929](https://tools.ietf.org/html/rfc5929).","summary":"As the `Finished` messages are message digests of the complete handshake (with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can be used for external authentication procedures when the authentication provided by SSL/TLS is not desired or is not enough.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetpeercertificatedetailed","name":"getPeerCertificate","title":"`tlsSocket.getPeerCertificate([detailed])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"detailed","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Include the full certificate chain if `true`, otherwise\ninclude just the peer's certificate.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"A certificate object."}},"description":"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\nIf the full certificate chain was requested, each certificate will include an\n`issuerCertificate` property containing an object representing its issuer's\ncertificate.","summary":"Returns an object representing the peer's certificate. If the peer does not provide a certificate, an empty object will be returned. If the socket has been destroyed, `null` will be returned.","examples":[],"children":[{"kind":"section","id":"certificate-object","name":"Certificate object","title":"Certificate object","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.1.0","v18.13.0"],"prUrl":"https://github.com/nodejs/node/pull/44935","commit":null,"description":"Add \"ca\" property."},{"versions":["v17.2.0","v16.14.0"],"prUrl":"https://github.com/nodejs/node/pull/39809","commit":null,"description":"Add fingerprint512."},{"versions":["v11.4.0"],"prUrl":"https://github.com/nodejs/node/pull/24358","commit":null,"description":"Support Elliptic Curve public key info."}],"description":"A certificate object has properties corresponding to the fields of the\ncertificate.\n\n* `ca` {boolean} `true` if a Certificate Authority (CA), `false` otherwise.\n* `raw` {Buffer} The DER encoded X.509 certificate data.\n* `subject` {Object} The certificate subject, described in terms of\n  Country (`C`), StateOrProvince (`ST`), Locality (`L`), Organization (`O`),\n  OrganizationalUnit (`OU`), and CommonName (`CN`). The CommonName is typically\n  a DNS name with TLS certificates. Example:\n  `{C: 'UK', ST: 'BC', L: 'Metro', O: 'Node Fans', OU: 'Docs', CN: 'example.com'}`.\n* `issuer` {Object} The certificate issuer, described in the same terms as the\n  `subject`.\n* `valid_from` {string} The date-time the certificate is valid from.\n* `valid_to` {string} The date-time the certificate is valid to.\n* `serialNumber` {string} The certificate serial number, as a hex string.\n  Example: `'B9B0D332A1AA5635'`.\n* `fingerprint` {string} The SHA-1 digest of the DER encoded certificate. It is\n  returned as a `:` separated hexadecimal string. Example: `'2A:7A:C2:DD:...'`.\n* `fingerprint256` {string} The SHA-256 digest of the DER encoded certificate.\n  It is returned as a `:` separated hexadecimal string. Example:\n  `'2A:7A:C2:DD:...'`.\n* `fingerprint512` {string} The SHA-512 digest of the DER encoded certificate.\n  It is returned as a `:` separated hexadecimal string. Example:\n  `'2A:7A:C2:DD:...'`.\n* `ext_key_usage` {Array} (Optional) The extended key usage, a set of OIDs.\n* `subjectaltname` {string} (Optional) A string containing concatenated names\n  for the subject, an alternative to the `subject` names.\n* `infoAccess` {Array} (Optional) An array describing the AuthorityInfoAccess,\n  used with OCSP.\n* `issuerCertificate` {Object} (Optional) The issuer certificate object. For\n  self-signed certificates, this may be a circular reference.\n\nThe certificate may contain information about the public key, depending on\nthe key type.\n\nFor RSA keys, the following properties may be defined:\n\n* `bits` {number} The RSA bit size. Example: `1024`.\n* `exponent` {string} The RSA exponent, as a string in hexadecimal number\n  notation. Example: `'0x010001'`.\n* `modulus` {string} The RSA modulus, as a hexadecimal string. Example:\n  `'B56CE45CB7...'`.\n* `pubkey` {Buffer} The public key.\n\nFor EC keys, the following properties may be defined:\n\n* `pubkey` {Buffer} The public key.\n* `bits` {number} The key size in bits. Example: `256`.\n* `asn1Curve` {string} (Optional) The ASN.1 name of the OID of the elliptic\n  curve. Well-known curves are identified by an OID. While it is unusual, it is\n  possible that the curve is identified by its mathematical properties, in which\n  case it will not have an OID. Example: `'prime256v1'`.\n* `nistCurve` {string} (Optional) The NIST name for the elliptic curve, if it\n  has one (not all well-known curves have been assigned names by NIST). Example:\n  `'P-256'`.\n\nExample certificate:\n\n```js\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  fingerprint512: '19:2B:3E:C3:B3:5B:32:E8:AE:BB:78:97:27:E4:BA:6C:39:C9:92:79:4F:31:46:39:E2:70:E5:5F:89:42:17:C9:E8:64:CA:FF:BB:72:56:73:6E:28:8A:92:7E:A3:2A:15:8B:C2:E0:45:CA:C3:BC:EA:40:52:EC:CA:A2:68:CB:32',\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```","summary":"A certificate object has properties corresponding to the fields of the certificate.","examples":[{"language":"js","displayName":null,"code":"{ 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  fingerprint512: '19:2B:3E:C3:B3:5B:32:E8:AE:BB:78:97:27:E4:BA:6C:39:C9:92:79:4F:31:46:39:E2:70:E5:5F:89:42:17:C9:E8:64:CA:FF:BB:72:56:73:6E:28:8A:92:7E:A3:2A:15:8B:C2:E0:45:CA:C3:BC:EA:40:52:EC:CA:A2:68:CB:32',\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 ... > }"}],"children":[]}]},{"kind":"method","id":"tlssocketgetpeerfinished","name":"getPeerFinished","title":"`tlsSocket.getPeerFinished()`","scope":"module","overloadOf":null,"stability":null,"added":["v9.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Buffer | undefined","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"The latest `Finished` message that is expected\nor has actually been received from the socket as part of an SSL/TLS handshake,\nor `undefined` if there is no `Finished` message so far."}},"description":"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\nCorresponds to the `SSL_get_peer_finished` routine in OpenSSL and may be used\nto implement the `tls-unique` channel binding from [RFC 5929](https://tools.ietf.org/html/rfc5929).","summary":"As the `Finished` messages are message digests of the complete handshake (with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can be used for external authentication procedures when the authentication provided by SSL/TLS is not desired or is not enough.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetpeerx509certificate","name":"getPeerX509Certificate","title":"`tlsSocket.getPeerX509Certificate()`","scope":"module","overloadOf":null,"stability":null,"added":["v15.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"X509Certificate","links":[{"name":"X509Certificate","href":"crypto.html#class-x509certificate","start":0,"end":15}]},"description":""}},"description":"Returns the peer certificate as an {X509Certificate} object.\n\nIf there is no peer certificate, or the socket has been destroyed,\n`undefined` will be returned.","summary":"Returns the peer certificate as an {X509Certificate} object.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetprotocol","name":"getProtocol","title":"`tlsSocket.getProtocol()`","scope":"module","overloadOf":null,"stability":null,"added":["v5.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string | null","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":9,"end":13}]},"description":""}},"description":"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\nProtocol versions are:\n\n* `'SSLv3'`\n* `'TLSv1'`\n* `'TLSv1.1'`\n* `'TLSv1.2'`\n* `'TLSv1.3'`\n\nSee the OpenSSL [`SSL_get_version`](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_version.html) documentation for more information.","summary":"Returns a string containing the negotiated SSL/TLS protocol version of the current connection. The value `'unknown'` will be returned for connected sockets that have not completed the handshaking process. The value `null` will be returned for server sockets or disconnected client sockets.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetsession","name":"getSession","title":"`tlsSocket.getSession()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"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\n[`tls.connect()`](#tlsconnectoptions-callback) to resume the connection. On the server, it may be useful\nfor debugging.\n\nSee [Session Resumption](#session-resumption) for more information.\n\nNote: `getSession()` works only for TLSv1.2 and below. For TLSv1.3, applications\nmust use the [`'session'`](#event-session) event (it also works for TLSv1.2 and below).","summary":"Returns the TLS session data or `undefined` if no session was negotiated. On the client, the data can be provided to the `session` option of `tls.connect()` to resume the connection. On the server, it may be useful for debugging.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetsharedsigalgs","name":"getSharedSigalgs","title":"`tlsSocket.getSharedSigalgs()`","scope":"module","overloadOf":null,"stability":null,"added":["v12.11.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Array","links":[{"name":"Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array","start":0,"end":5}]},"description":"List of signature algorithms shared between the server and\nthe client in the order of decreasing preference."}},"description":"See\n[SSL\\_get\\_shared\\_sigalgs](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html)\nfor more information.","summary":"See SSL_get_shared_sigalgs for more information.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgettlsticket","name":"getTLSTicket","title":"`tlsSocket.getTLSTicket()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"For a client, returns the TLS session ticket if one is available, or\n`undefined`. For a server, always returns `undefined`.\n\nIt may be useful for debugging.\n\nSee [Session Resumption](#session-resumption) for more information.","summary":"For a client, returns the TLS session ticket if one is available, or `undefined`. For a server, always returns `undefined`.","examples":[],"children":[]},{"kind":"method","id":"tlssocketgetx509certificate","name":"getX509Certificate","title":"`tlsSocket.getX509Certificate()`","scope":"module","overloadOf":null,"stability":null,"added":["v15.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"X509Certificate","links":[{"name":"X509Certificate","href":"crypto.html#class-x509certificate","start":0,"end":15}]},"description":""}},"description":"Returns the local certificate as an {X509Certificate} object.\n\nIf there is no local certificate, or the socket has been destroyed,\n`undefined` will be returned.","summary":"Returns the local certificate as an {X509Certificate} object.","examples":[],"children":[]},{"kind":"method","id":"tlssocketissessionreused","name":"isSessionReused","title":"`tlsSocket.isSessionReused()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the session was reused, `false` otherwise."}},"description":"See [Session Resumption](#session-resumption) for more information.","summary":"See Session Resumption for more information.","examples":[],"children":[]},{"kind":"property","id":"tlssocketlocaladdress","name":"localAddress","title":"`tlsSocket.localAddress`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Returns the string representation of the local IP address.","summary":"Returns the string representation of the local IP address.","examples":[],"children":[]},{"kind":"property","id":"tlssocketlocalport","name":"localPort","title":"`tlsSocket.localPort`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"Returns the numeric representation of the local port.","summary":"Returns the numeric representation of the local port.","examples":[],"children":[]},{"kind":"property","id":"tlssocketremoteaddress","name":"remoteAddress","title":"`tlsSocket.remoteAddress`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Returns the string representation of the remote IP address. For example,\n`'74.125.127.100'` or `'2001:4860:a005::68'`.","summary":"Returns the string representation of the remote IP address. For example, `'74.125.127.100'` or `'2001:4860:a005::68'`.","examples":[],"children":[]},{"kind":"property","id":"tlssocketremotefamily","name":"remoteFamily","title":"`tlsSocket.remoteFamily`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Returns the string representation of the remote IP family. `'IPv4'` or `'IPv6'`.","summary":"Returns the string representation of the remote IP family. `'IPv4'` or `'IPv6'`.","examples":[],"children":[]},{"kind":"property","id":"tlssocketremoteport","name":"remotePort","title":"`tlsSocket.remotePort`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"Returns the numeric representation of the remote port. For example, `443`.","summary":"Returns the numeric representation of the remote port. For example, `443`.","examples":[],"children":[]},{"kind":"method","id":"tlssocketrenegotiateoptions-callback","name":"renegotiate","title":"`tlsSocket.renegotiate(options, callback)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.8"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[{"name":"rejectUnauthorized","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If not `false`, the server certificate is\nverified against the list of supplied CAs. An `'error'` event is emitted if\nverification fails; `err.code` contains the OpenSSL error code.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"requestCert","type":null,"description":"","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"If `renegotiate()` returned `true`, callback is\nattached once to the [`'secure'`](#event-secure) event. If `renegotiate()` returned `false`,\n`callback` will be called in the next tick with an error, unless the\n`tlsSocket` has been destroyed, in which case `callback` will not be called\nat all.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if renegotiation was initiated, `false` otherwise."}},"description":"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\nThis method can be used to request a peer's certificate after the secure\nconnection has been established.\n\nWhen running as the server, the socket will be destroyed with an error after\n`handshakeTimeout` timeout.\n\nFor TLSv1.3, renegotiation cannot be initiated, it is not supported by the\nprotocol.","summary":"The `tlsSocket.renegotiate()` method initiates a TLS renegotiation process. Upon completion, the `callback` function will be passed a single argument that is either an `Error` (if the request failed) or `null`.","examples":[],"children":[]},{"kind":"property","id":"tlssocketservername","name":"servername","title":"`tlsSocket.servername`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string | boolean | null","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":9,"end":16},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":19,"end":23}]},"default":null,"description":"The SNI (Server Name Indication) host name associated with the socket. This is\n`null` before the handshake completes. Once the handshake completes it settles\nas either the host name string, or `false` if SNI was not used.","summary":"The SNI (Server Name Indication) host name associated with the socket. This is `null` before the handshake completes. Once the handshake completes it settles as either the host name string, or `false` if SNI was not used.","examples":[],"children":[]},{"kind":"method","id":"tlssocketsetkeycertcontext","name":"setKeyCert","title":"`tlsSocket.setKeyCert(context)`","scope":"module","overloadOf":null,"stability":null,"added":["v22.5.0","v20.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"context","type":{"text":"Object | tls.SecureContext","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"tls.SecureContext","href":"tls.html#class-tlssecurecontext","start":9,"end":26}]},"description":"An object containing at least `key` and\n`cert` properties from the [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) `options`, or a\nTLS context object created with [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) itself.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `tlsSocket.setKeyCert()` method sets the private key and certificate to use\nfor the socket. This is mainly useful if you wish to select a server certificate\nfrom a TLS server's `ALPNCallback`.","summary":"The `tlsSocket.setKeyCert()` method sets the private key and certificate to use for the socket. This is mainly useful if you wish to select a server certificate from a TLS server's `ALPNCallback`.","examples":[],"children":[]},{"kind":"method","id":"tlssocketsetmaxsendfragmentsize","name":"setMaxSendFragment","title":"`tlsSocket.setMaxSendFragment(size)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.11"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"size","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The maximum TLS fragment size. The maximum value is `16384`.","default":"16384","optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"The `tlsSocket.setMaxSendFragment()` method sets the maximum TLS fragment size.\nReturns `true` if setting the limit succeeded; `false` otherwise.\n\nSmaller 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.","summary":"The `tlsSocket.setMaxSendFragment()` method sets the maximum TLS fragment size. Returns `true` if setting the limit succeeded; `false` otherwise.","examples":[],"children":[]}]},{"kind":"method","id":"tlscheckserveridentityhostname-cert","name":"checkServerIdentity","title":"`tls.checkServerIdentity(hostname, cert)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.8.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v17.3.1","v16.13.2","v14.18.3","v12.22.9"],"prUrl":"https://github.com/nodejs-private/node-private/pull/300","commit":null,"description":"Support for `uniformResourceIdentifier` subject alternative names has been disabled in response to CVE-2021-44531."}],"signature":{"parameters":[{"name":"hostname","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The host name or IP address to verify the certificate\nagainst.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"cert","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"A [certificate object](#certificate-object) representing the peer's certificate.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Error | undefined","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":8,"end":17}]},"description":""}},"description":"Verifies the certificate `cert` is issued to `hostname`.\n\nReturns {Error} object, populating it with `reason`, `host`, and `cert` on\nfailure. On success, returns {undefined}.\n\nThis function is intended to be used in combination with the\n`checkServerIdentity` option that can be passed to [`tls.connect()`](#tlsconnectoptions-callback) and as\nsuch operates on a [certificate object](#certificate-object). For other purposes, consider using\n[`x509.checkHost()`](crypto.html#x509checkhostname-options) instead.\n\nThis function can be overwritten by providing an alternative function as the\n`options.checkServerIdentity` option that is passed to `tls.connect()`. The\noverwriting function can call `tls.checkServerIdentity()` of course, to augment\nthe checks done with additional verification.\n\nThis function is only called if the certificate passed all other checks, such as\nbeing issued by trusted CA (`options.ca`).\n\nEarlier versions of Node.js incorrectly accepted certificates for a given\n`hostname` if a matching `uniformResourceIdentifier` subject alternative name\nwas present (see [CVE-2021-44531](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44531)). Applications that wish to accept\n`uniformResourceIdentifier` subject alternative names can use a custom\n`options.checkServerIdentity` function that implements the desired behavior.","summary":"Verifies the certificate `cert` is issued to `hostname`.","examples":[],"children":[]},{"kind":"method","id":"tlsconnectoptions-callback","name":"connect","title":"`tls.connect(options[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.1.0","v14.18.0"],"prUrl":"https://github.com/nodejs/node/pull/35753","commit":null,"description":"Added `onread` option."},{"versions":["v14.1.0","v13.14.0"],"prUrl":"https://github.com/nodejs/node/pull/32786","commit":null,"description":"The `highWaterMark` option is accepted now."},{"versions":["v13.6.0","v12.16.0"],"prUrl":"https://github.com/nodejs/node/pull/23188","commit":null,"description":"The `pskCallback` option is now supported."},{"versions":["v12.9.0"],"prUrl":"https://github.com/nodejs/node/pull/27836","commit":null,"description":"Support the `allowHalfOpen` option."},{"versions":["v12.4.0"],"prUrl":"https://github.com/nodejs/node/pull/27816","commit":null,"description":"The `hints` option is now supported."},{"versions":["v12.2.0"],"prUrl":"https://github.com/nodejs/node/pull/27497","commit":null,"description":"The `enableTrace` option is now supported."},{"versions":["v11.8.0","v10.16.0"],"prUrl":"https://github.com/nodejs/node/pull/25517","commit":null,"description":"The `timeout` option is supported now."},{"versions":["v8.0.0"],"prUrl":"https://github.com/nodejs/node/pull/12839","commit":null,"description":"The `lookup` option is supported now."},{"versions":["v8.0.0"],"prUrl":"https://github.com/nodejs/node/pull/11984","commit":null,"description":"The `ALPNProtocols` option can be a `TypedArray` or `DataView` now."},{"versions":["v5.3.0","v4.7.0"],"prUrl":"https://github.com/nodejs/node/pull/4246","commit":null,"description":"The `secureContext` option is supported now."},{"versions":["v5.0.0"],"prUrl":"https://github.com/nodejs/node/pull/2564","commit":null,"description":"ALPN options are supported now."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[{"name":"enableTrace","type":null,"description":"See [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Host the client should connect to.","default":"'localhost'","optional":true,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Port the client should connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Creates Unix socket connection to path. If this option is\nspecified, `host` and `port` are ignored.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"Establish secure connection on a given socket\nrather than creating a new socket. Typically, this is an instance of\n[`net.Socket`](net.html#class-netsocket), but any `Duplex` stream is allowed.\nIf this option is specified, `path`, `host`, and `port` are ignored,\nexcept for certificate validation. Usually, a socket is already connected\nwhen passed to `tls.connect()`, but it can be connected later.\nConnection/disconnection/destruction of `socket` is the user's\nresponsibility; calling `tls.connect()` will not cause `net.connect()` to be\ncalled.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"allowHalfOpen","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `false`, then the socket will\nautomatically end the writable side when the readable side ends. If the\n`socket` option is set, this option has no effect. See the `allowHalfOpen`\noption of [`net.Socket`](net.html#class-netsocket) for details.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"rejectUnauthorized","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If not `false`, the server certificate is\nverified against the list of supplied CAs. An `'error'` event is emitted if\nverification fails; `err.code` contains the OpenSSL error code.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"pskCallback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"For TLS-PSK negotiation, see [Pre-shared keys](#pre-shared-keys).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ALPNProtocols","type":{"text":"string[] | Buffer | TypedArray | DataView","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":11,"end":17},{"name":"TypedArray","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray","start":20,"end":30},{"name":"DataView","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/DataView","start":33,"end":41}]},"description":"An array of strings,\nor a single `Buffer`, `TypedArray`, or `DataView` containing the supported\nALPN protocols. Buffers should have the format `[len][name][len][name]...`\ne.g. `'\\x08http/1.1\\x08http/1.0'`, where the `len` byte is the length of the\nnext protocol name. Passing an array is usually much simpler, e.g.\n`['http/1.1', 'http/1.0']`. Protocols earlier in the list have higher\npreference than those later.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"servername","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Server name for the SNI (Server Name Indication) TLS\nextension. It is the name of the host being connected to, and must be a host\nname, and not an IP address. It can be used by a multi-homed server to\nchoose the correct certificate to present to the client, see the\n`SNICallback` option to [`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"checkServerIdentity(servername, cert)","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A callback function\nto be used (instead of the builtin `tls.checkServerIdentity()` function)\nwhen checking the server's host name (or the provided `servername` when\nexplicitly set) against the certificate. This should return an {Error} if\nverification fails. The method should return `undefined` if the `servername`\nand `cert` are verified.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"session","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"A `Buffer` instance, containing TLS session.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"requestOCSP","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, specifies that the OCSP status request\nextension will be added to the client hello and an `'OCSPResponse'` event\nwill be emitted on the socket before establishing a secure communication.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"minDHSize","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Minimum size of the DH parameter in bits to accept a\nTLS connection. When a server offers a DH parameter with a size less\nthan `minDHSize`, the TLS connection is destroyed and an error is thrown.","default":"1024","optional":true,"rest":false,"properties":[]},{"name":"highWaterMark","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Consistent with the readable stream `highWaterMark` parameter.","default":"16 * 1024","optional":true,"rest":false,"properties":[]},{"name":"timeout","type":null,"description":"{number} If set and if a socket is created internally, will call\n[`socket.setTimeout(timeout)`](net.html#socketsettimeouttimeout-callback) after the socket is created, but before it\nstarts the connection.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"secureContext","type":null,"description":"TLS context object created with\n[`tls.createSecureContext()`](#tlscreatesecurecontextoptions). If a `secureContext` is *not* provided, one\nwill be created by passing the entire `options` object to\n`tls.createSecureContext()`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"onread","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"If the `socket` option is missing, incoming data is\nstored in a single `buffer` and passed to the supplied `callback` when\ndata arrives on the socket, otherwise the option is ignored. See the\n`onread` option of [`net.Socket`](net.html#class-netsocket) for details.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"","type":null,"description":"...: [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) options that are used if the\n`secureContext` option is missing, otherwise they are ignored.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"","type":null,"description":"...: Any [`socket.connect()`](net.html#socketconnectoptions-connectlistener) option not already listed.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"tls.TLSSocket","links":[{"name":"tls.TLSSocket","href":"tls.html#tlstlssocket","start":0,"end":13}]},"description":""}},"description":"The `callback` function, if specified, will be added as a listener for the\n[`'secureConnect'`](#event-secureconnect) event.\n\n`tls.connect()` returns a [`tls.TLSSocket`](#class-tlstlssocket) object.\n\nUnlike 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\nThe following illustrates a client for the echo server example from\n[`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener):\n\n```mjs\n// Assumes an echo server that is listening on port 8000.\nimport { connect } from 'node:tls';\nimport { readFileSync } from 'node:fs';\nimport { stdin } from 'node:process';\n\nconst options = {\n  // Necessary only if the server requires client certificate authentication.\n  key: readFileSync('client-key.pem'),\n  cert: readFileSync('client-cert.pem'),\n\n  // Necessary only if the server uses a self-signed certificate.\n  ca: [ 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 = connect(8000, options, () => {\n  console.log('client connected',\n              socket.authorized ? 'authorized' : 'unauthorized');\n  stdin.pipe(socket);\n  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```\n\n```cjs\n// Assumes an echo server that is listening on port 8000.\nconst { connect } = require('node:tls');\nconst { readFileSync } = require('node:fs');\n\nconst options = {\n  // Necessary only if the server requires client certificate authentication.\n  key: readFileSync('client-key.pem'),\n  cert: readFileSync('client-cert.pem'),\n\n  // Necessary only if the server uses a self-signed certificate.\n  ca: [ 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 = 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```\n\nTo generate the certificate and key for this example, run:\n\n```bash\nopenssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n  -keyout client-key.pem -out client-cert.pem\n```\n\nThen, to generate the `server-cert.pem` certificate for this example, run:\n\n```bash\nopenssl pkcs12 -certpbe AES-256-CBC -export -out server-cert.pem \\\n  -inkey client-key.pem -in client-cert.pem\n```","summary":"The `callback` function, if specified, will be added as a listener for the `'secureConnect'` event.","examples":[{"language":"mjs","displayName":null,"code":"// Assumes an echo server that is listening on port 8000.\nimport { connect } from 'node:tls';\nimport { readFileSync } from 'node:fs';\nimport { stdin } from 'node:process';\n\nconst options = {\n  // Necessary only if the server requires client certificate authentication.\n  key: readFileSync('client-key.pem'),\n  cert: readFileSync('client-cert.pem'),\n\n  // Necessary only if the server uses a self-signed certificate.\n  ca: [ 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 = connect(8000, options, () => {\n  console.log('client connected',\n              socket.authorized ? 'authorized' : 'unauthorized');\n  stdin.pipe(socket);\n  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});"},{"language":"cjs","displayName":null,"code":"// Assumes an echo server that is listening on port 8000.\nconst { connect } = require('node:tls');\nconst { readFileSync } = require('node:fs');\n\nconst options = {\n  // Necessary only if the server requires client certificate authentication.\n  key: readFileSync('client-key.pem'),\n  cert: readFileSync('client-cert.pem'),\n\n  // Necessary only if the server uses a self-signed certificate.\n  ca: [ 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 = 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});"},{"language":"bash","displayName":null,"code":"openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n  -keyout client-key.pem -out client-cert.pem"},{"language":"bash","displayName":null,"code":"openssl pkcs12 -certpbe AES-256-CBC -export -out server-cert.pem \\\n  -inkey client-key.pem -in client-cert.pem"}],"children":[]},{"kind":"method","id":"tlsconnectpath-options-callback","name":"connect","title":"`tls.connect(path[, options][, callback])`","scope":"module","overloadOf":"tlsconnectoptions-callback","stability":null,"added":["v0.11.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Default value for `options.path`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"See [`tls.connect()`](#tlsconnectoptions-callback).","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"See [`tls.connect()`](#tlsconnectoptions-callback).","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"tls.TLSSocket","links":[{"name":"tls.TLSSocket","href":"tls.html#tlstlssocket","start":0,"end":13}]},"description":""}},"description":"Same as [`tls.connect()`](#tlsconnectoptions-callback) except that `path` can be provided\nas an argument instead of an option.\n\nA path option, if specified, will take precedence over the path argument.","summary":"Same as `tls.connect()` except that `path` can be provided as an argument instead of an option.","examples":[],"children":[]},{"kind":"method","id":"tlsconnectport-host-options-callback","name":"connect","title":"`tls.connect(port[, host][, options][, callback])`","scope":"module","overloadOf":"tlsconnectoptions-callback","stability":null,"added":["v0.11.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Default value for `options.port`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Default value for `options.host`.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"See [`tls.connect()`](#tlsconnectoptions-callback).","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"See [`tls.connect()`](#tlsconnectoptions-callback).","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"tls.TLSSocket","links":[{"name":"tls.TLSSocket","href":"tls.html#tlstlssocket","start":0,"end":13}]},"description":""}},"description":"Same as [`tls.connect()`](#tlsconnectoptions-callback) except that `port` and `host` can be provided\nas arguments instead of options.\n\nA port or host option, if specified, will take precedence over any port or host\nargument.","summary":"Same as `tls.connect()` except that `port` and `host` can be provided as arguments instead of options.","examples":[],"children":[]},{"kind":"method","id":"tlscreatesecurecontextoptions","name":"createSecureContext","title":"`tls.createSecureContext([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.13"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.4.0"],"prUrl":"https://github.com/nodejs/node/pull/62217","commit":null,"description":"The `certificateCompression` option has been added."},{"versions":["v22.9.0","v20.18.0"],"prUrl":"https://github.com/nodejs/node/pull/54790","commit":null,"description":"The `allowPartialTrustChain` option has been added."},{"versions":["v22.4.0","v20.16.0"],"prUrl":"https://github.com/nodejs/node/pull/53329","commit":null,"description":"The `clientCertEngine`, `privateKeyEngine` and `privateKeyIdentifier` options depend on custom engine support in OpenSSL which is deprecated in OpenSSL 3."},{"versions":["v19.8.0","v18.16.0"],"prUrl":"https://github.com/nodejs/node/pull/46978","commit":null,"description":"The `dhparam` option can now be set to `'auto'` to enable DHE with appropriate well-known parameters."},{"versions":["v12.12.0"],"prUrl":"https://github.com/nodejs/node/pull/28973","commit":null,"description":"Added `privateKeyIdentifier` and `privateKeyEngine` options to get private key from an OpenSSL engine."},{"versions":["v12.11.0"],"prUrl":"https://github.com/nodejs/node/pull/29598","commit":null,"description":"Added `sigalgs` option to override supported signature algorithms."},{"versions":["v12.0.0"],"prUrl":"https://github.com/nodejs/node/pull/26209","commit":null,"description":"TLSv1.3 support added."},{"versions":["v11.5.0"],"prUrl":"https://github.com/nodejs/node/pull/24733","commit":null,"description":"The `ca:` option now supports `BEGIN TRUSTED CERTIFICATE`."},{"versions":["v11.4.0","v10.16.0"],"prUrl":"https://github.com/nodejs/node/pull/24405","commit":null,"description":"The `minVersion` and `maxVersion` can be used to restrict the allowed TLS protocol versions."},{"versions":["v10.0.0"],"prUrl":"https://github.com/nodejs/node/pull/19794","commit":null,"description":"The `ecdhCurve` cannot be set to `false` anymore due to a change in OpenSSL."},{"versions":["v9.3.0"],"prUrl":"https://github.com/nodejs/node/pull/14903","commit":null,"description":"The `options` parameter can now include `clientCertEngine`."},{"versions":["v9.0.0"],"prUrl":"https://github.com/nodejs/node/pull/15206","commit":null,"description":"The `ecdhCurve` option can now be multiple `':'` separated curve names or `'auto'`."},{"versions":["v7.3.0"],"prUrl":"https://github.com/nodejs/node/pull/10294","commit":null,"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."},{"versions":["v5.2.0"],"prUrl":"https://github.com/nodejs/node/pull/4099","commit":null,"description":"The `ca` option can now be a single string containing multiple CA certificates."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"allowPartialTrustChain","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Treat intermediate (non-self-signed)\ncertificates in the trust CA certificate list as trusted.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ca","type":{"text":"string | string[] | Buffer | Buffer[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"Buffer","href":"buffer.html#class-buffer","start":20,"end":26},{"name":"Buffer","href":"buffer.html#class-buffer","start":29,"end":35}]},"description":"Optionally override the trusted CA\ncertificates. If not specified, the CA certificates trusted by default are\nthe same as the ones returned by [`tls.getCACertificates()`](#tlsgetcacertificatestype) using the\n`default` type.  If specified, the default list would be completely replaced\n(instead of being concatenated) by the certificates in the `ca` option.\nUsers need to concatenate manually if they wish to add additional certificates\ninstead of completely overriding the default.\nThe value can be a string or `Buffer`, or an `Array` of\nstrings and/or `Buffer`s. Any string or `Buffer` can contain multiple PEM\nCAs concatenated together. The peer's certificate must be chainable to a CA\ntrusted by the server for the connection to be authenticated. When using\ncertificates that are not chainable to a well-known CA, the certificate's CA\nmust be explicitly specified as a trusted or the connection will fail to\nauthenticate.\nIf the peer uses a certificate that doesn't match or chain to one of the\ndefault CAs, use the `ca` option to provide a CA certificate that the peer's\ncertificate can match or chain to.\nFor self-signed certificates, the certificate is its own CA, and must be\nprovided.\nFor PEM encoded certificates, supported types are \"TRUSTED CERTIFICATE\",\n\"X509 CERTIFICATE\", and \"CERTIFICATE\".","default":null,"optional":false,"rest":false,"properties":[]},{"name":"cert","type":{"text":"string | string[] | Buffer | Buffer[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"Buffer","href":"buffer.html#class-buffer","start":20,"end":26},{"name":"Buffer","href":"buffer.html#class-buffer","start":29,"end":35}]},"description":"Cert chains in PEM format. One\ncert chain should be provided per private key. Each cert chain should\nconsist of the PEM formatted certificate for a provided private `key`,\nfollowed by the PEM formatted intermediate certificates (if any), in order,\nand not including the root CA (the root CA must be pre-known to the peer,\nsee `ca`). When providing multiple cert chains, they do not have to be in\nthe same order as their private keys in `key`. If the intermediate\ncertificates are not provided, the peer will not be able to validate the\ncertificate, and the handshake will fail.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"certificateCompression","type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An array of supported certificate\ncompression algorithm names, in preference order. Supported values are\n`'zlib'`, `'brotli'`, and `'zstd'`. When set, enables TLS certificate\ncompression ([RFC 8879](https://tools.ietf.org/html/rfc8879)) which compresses certificates during the TLS\nhandshake, reducing handshake size. Only effective with TLSv1.3.","default":"`[]` (disabled)","optional":true,"rest":false,"properties":[]},{"name":"sigalgs","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Colon-separated list of supported signature algorithms.\nThe list can contain digest algorithms (`SHA256`, `MD5` etc.), public key\nalgorithms (`RSA-PSS`, `ECDSA` etc.), combination of both (e.g\n'RSA+SHA384') or TLS v1.3 scheme names (e.g. `rsa_pss_pss_sha512`).\nSee [OpenSSL man pages](https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set1_sigalgs_list.html)\nfor more info.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ciphers","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Cipher suite specification, replacing the default. For\nmore information, see [Modifying the default TLS cipher suite](#modifying-the-default-tls-cipher-suite). Permitted\nciphers can be obtained via [`tls.getCiphers()`](#tlsgetciphers). Cipher names must be\nuppercased in order for OpenSSL to accept them.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"clientCertEngine","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Name of an OpenSSL engine which can provide the\nclient certificate. **Deprecated.**","default":null,"optional":false,"rest":false,"properties":[]},{"name":"crl","type":{"text":"string | string[] | Buffer | Buffer[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"Buffer","href":"buffer.html#class-buffer","start":20,"end":26},{"name":"Buffer","href":"buffer.html#class-buffer","start":29,"end":35}]},"description":"PEM formatted CRLs (Certificate\nRevocation Lists).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"dhparam","type":{"text":"string | Buffer","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15}]},"description":"`'auto'` or custom Diffie-Hellman parameters,\nrequired for non-ECDHE [perfect forward secrecy](#perfect-forward-secrecy). If omitted or invalid,\nthe parameters are silently discarded and DHE ciphers will not be available.\n[ECDHE](https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman)-based [perfect forward secrecy](#perfect-forward-secrecy) will still be available.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ecdhCurve","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A string describing a named curve, TLS group, or\ncolon-separated list of named curves or TLS groups to use for key agreement,\nfor example `P-521:P-384:P-256`, `X25519`, or `X25519MLKEM768`. The\nhistorical name of this option refers to ECDH key agreement in TLSv1.2 and\nbelow. In TLSv1.3, this option configures the TLS Supported Groups and\nkey share groups offered or accepted by the TLS stack. Set to `auto` to\nselect the group automatically. Use [`crypto.getCurves()`](crypto.html#cryptogetcurves) to obtain a\nlist of available elliptic curve names. For TLS group names, use\n`openssl list -tls-groups` or consult the [IANA TLS Supported Groups\nregistry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8).","default":"tls.DEFAULT_ECDH_CURVE","optional":true,"rest":false,"properties":[]},{"name":"honorCipherOrder","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Attempt to use the server's cipher suite\npreferences instead of the client's. When `true`, causes\n`SSL_OP_CIPHER_SERVER_PREFERENCE` to be set in `secureOptions`, see\n[OpenSSL Options](crypto.html#openssl-options) for more information.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"key","type":{"text":"string | string[] | Buffer | Buffer[] | Object[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"Buffer","href":"buffer.html#class-buffer","start":20,"end":26},{"name":"Buffer","href":"buffer.html#class-buffer","start":29,"end":35},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":40,"end":46}]},"description":"Private keys in PEM\nformat. PEM allows the option of private keys being encrypted. Encrypted\nkeys will be decrypted with `options.passphrase`. Multiple keys using\ndifferent algorithms can be provided either as an array of unencrypted key\nstrings or buffers, or an array of objects in the form\n`{pem: <string|buffer>[, passphrase: <string>]}`. The object form can only\noccur in an array. `object.passphrase` is optional. Encrypted keys will be\ndecrypted with `object.passphrase` if provided, or `options.passphrase` if\nit is not.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"privateKeyEngine","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Name of an OpenSSL engine to get private key\nfrom. Should be used together with `privateKeyIdentifier`. **Deprecated.**","default":null,"optional":false,"rest":false,"properties":[]},{"name":"privateKeyIdentifier","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Identifier of a private key managed by\nan OpenSSL engine. Should be used together with `privateKeyEngine`.\nShould not be set together with `key`, because both options define a\nprivate key in different ways. **Deprecated.**","default":null,"optional":false,"rest":false,"properties":[]},{"name":"maxVersion","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Optionally set the maximum TLS version to allow. One\nof `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified\nalong with the `secureProtocol` option; use one or the other.","default":"tls.DEFAULT_MAX_VERSION","optional":true,"rest":false,"properties":[]},{"name":"minVersion","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Optionally set the minimum TLS version to allow. One\nof `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified\nalong with the `secureProtocol` option; use one or the other. Avoid\nsetting to less than TLSv1.2, but it may be required for\ninteroperability. Versions before TLSv1.2 may require downgrading the [OpenSSL Security Level](#openssl-security-level).","default":"tls.DEFAULT_MIN_VERSION","optional":true,"rest":false,"properties":[]},{"name":"passphrase","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Shared passphrase used for a single private key and/or\na PFX.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"pfx","type":{"text":"string | string[] | Buffer | Buffer[] | Object[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"Buffer","href":"buffer.html#class-buffer","start":20,"end":26},{"name":"Buffer","href":"buffer.html#class-buffer","start":29,"end":35},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":40,"end":46}]},"description":"PFX or PKCS12 encoded\nprivate key and certificate chain. `pfx` is an alternative to providing\n`key` and `cert` individually. PFX is usually encrypted, if it is,\n`passphrase` will be used to decrypt it. Multiple PFX can be provided either\nas an array of unencrypted PFX buffers, or an array of objects in the form\n`{buf: <string|buffer>[, passphrase: <string>]}`. The object form can only\noccur in an array. `object.passphrase` is optional. Encrypted PFX will be\ndecrypted with `object.passphrase` if provided, or `options.passphrase` if\nit is not.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"secureOptions","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Optionally affect the OpenSSL protocol behavior,\nwhich is not usually necessary. This should be used carefully if at all!\nValue is a numeric bitmask of the `SSL_OP_*` options from\n[OpenSSL Options](crypto.html#openssl-options).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"secureProtocol","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Legacy mechanism to select the TLS protocol\nversion to use, it does not support independent control of the minimum and\nmaximum version, and does not support limiting the protocol to TLSv1.3. Use\n`minVersion` and `maxVersion` instead. The possible values are listed as\n[SSL\\_METHODS](https://www.openssl.org/docs/man1.1.1/man7/ssl.html#Dealing-with-Protocol-Methods), use the function names as strings. For example,\nuse `'TLSv1_1_method'` to force TLS version 1.1, or `'TLS_method'` to allow\nany TLS protocol version up to TLSv1.3. It is not recommended to use TLS\nversions less than 1.2, but it may be required for interoperability.","default":"none, see `minVersion`","optional":true,"rest":false,"properties":[]},{"name":"sessionIdContext","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Opaque identifier used by servers to ensure\nsession state is not shared between applications. Unused by clients.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ticketKeys","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"48-bytes of cryptographically strong pseudorandom\ndata. See [Session Resumption](#session-resumption) for more information.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"sessionTimeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of seconds after which a TLS session\ncreated by the server will no longer be resumable. See\n[Session Resumption](#session-resumption) for more information.","default":"300","optional":true,"rest":false,"properties":[]}]}],"returns":null},"description":"[`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener) sets the default value of the `honorCipherOrder` option\nto `true`, other APIs that create secure contexts leave it unset.\n\n[`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener) 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\nThe `tls.createSecureContext()` method creates a `SecureContext` object. It is\nusable as an argument to several `tls` APIs, such as [`server.addContext()`](#serveraddcontexthostname-context),\nbut has no public methods. The [`tls.Server`](#class-tlsserver) constructor and the\n[`tls.createServer()`](#tlscreateserveroptions-secureconnectionlistener) method do not support the `secureContext` option.\n\nA key is *required* for ciphers that use certificates. Either `key` or\n`pfx` can be used to provide it.\n\nIf the `ca` option is not given, then Node.js will default to using\n[Mozilla's publicly trusted list of CAs](https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt).\n\nCustom DHE parameters are discouraged in favor of the new `dhparam: 'auto'`\noption. When set to `'auto'`, well-known DHE parameters of sufficient strength\nwill be selected automatically. Otherwise, if necessary, `openssl dhparam` can\nbe used to create custom parameters. The key length must be greater than or\nequal to 1024 bits or else an error will be thrown. Although 1024 bits is\npermissible, use 2048 bits or larger for stronger security.","summary":"`tls.createServer()` sets the default value of the `honorCipherOrder` option to `true`, other APIs that create secure contexts leave it unset.","examples":[],"children":[]},{"kind":"method","id":"tlscreateserveroptions-secureconnectionlistener","name":"createServer","title":"`tls.createServer([options][, secureConnectionListener])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v22.4.0","v20.16.0"],"prUrl":"https://github.com/nodejs/node/pull/53329","commit":null,"description":"The `clientCertEngine` option depends on custom engine support in OpenSSL which is deprecated in OpenSSL 3."},{"versions":["v20.4.0","v18.19.0"],"prUrl":"https://github.com/nodejs/node/pull/45190","commit":null,"description":"The `options` parameter can now include `ALPNCallback`."},{"versions":["v19.0.0"],"prUrl":"https://github.com/nodejs/node/pull/44031","commit":null,"description":"If `ALPNProtocols` is set, incoming connections that send an ALPN extension with no supported protocols are terminated with a fatal `no_application_protocol` alert."},{"versions":["v12.3.0"],"prUrl":"https://github.com/nodejs/node/pull/27665","commit":null,"description":"The `options` parameter now supports `net.createServer()` options."},{"versions":["v9.3.0"],"prUrl":"https://github.com/nodejs/node/pull/14903","commit":null,"description":"The `options` parameter can now include `clientCertEngine`."},{"versions":["v8.0.0"],"prUrl":"https://github.com/nodejs/node/pull/11984","commit":null,"description":"The `ALPNProtocols` option can be a `TypedArray` or `DataView` now."},{"versions":["v5.0.0"],"prUrl":"https://github.com/nodejs/node/pull/2564","commit":null,"description":"ALPN options are supported now."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"ALPNProtocols","type":{"text":"string[] | Buffer | TypedArray | DataView","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":11,"end":17},{"name":"TypedArray","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray","start":20,"end":30},{"name":"DataView","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/DataView","start":33,"end":41}]},"description":"An array of strings,\nor a single `Buffer`, `TypedArray`, or `DataView` containing the supported\nALPN protocols. Buffers should have the format `[len][name][len][name]...`\ne.g. `0x05hello0x05world`, where the first byte is the length of the next\nprotocol name. Passing an array is usually much simpler, e.g.\n`['hello', 'world']`. (Protocols should be ordered by their priority.)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ALPNCallback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"If set, this will be called when a\nclient opens a connection using the ALPN extension. One argument will\nbe passed to the callback: an object containing `servername` and\n`protocols` fields, respectively containing the server name from\nthe SNI extension (if any) and an array of ALPN protocol name strings. The\ncallback must return either one of the strings listed in\n`protocols`, which will be returned to the client as the selected\nALPN protocol, or `undefined`, to reject the connection with a fatal alert.\nIf a string is returned that does not match one of the client's ALPN\nprotocols, an error will be thrown. This option cannot be used with the\n`ALPNProtocols` option, and setting both options will throw an error.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"clientCertEngine","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Name of an OpenSSL engine which can provide the\nclient certificate. **Deprecated.**","default":null,"optional":false,"rest":false,"properties":[]},{"name":"enableTrace","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, [`tls.TLSSocket.enableTrace()`](#tlssocketenabletrace) will be\ncalled on new connections. Tracing can be enabled after the secure\nconnection is established, but this option must be used to trace the secure\nconnection setup.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"handshakeTimeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Abort the connection if the SSL/TLS handshake\ndoes not finish in the specified number of milliseconds.\nA `'tlsClientError'` is emitted on the `tls.Server` object whenever\na handshake times out.","default":"`120000` (120 seconds)","optional":true,"rest":false,"properties":[]},{"name":"rejectUnauthorized","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If not `false` the server will reject any\nconnection which is not authorized with the list of supplied CAs. This\noption only has an effect if `requestCert` is `true`.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"requestCert","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true` the server will request a certificate from\nclients that connect and attempt to verify that certificate.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"sessionTimeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of seconds after which a TLS session\ncreated by the server will no longer be resumable. See\n[Session Resumption](#session-resumption) for more information.","default":"300","optional":true,"rest":false,"properties":[]},{"name":"SNICallback(servername, callback)","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A function that will be\ncalled if the client supports SNI TLS extension. Two arguments will be\npassed when called: `servername` and `callback`. `callback` is an\nerror-first callback that takes two optional arguments: `error` and `ctx`.\n`ctx`, if provided, is a `SecureContext` instance.\n[`tls.createSecureContext()`](#tlscreatesecurecontextoptions) can be used to get a proper `SecureContext`.\nIf `callback` is called with a falsy `ctx` argument, the default secure\ncontext of the server will be used. If `SNICallback` wasn't provided the\ndefault callback with high-level API will be used (see below).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ticketKeys","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"48-bytes of cryptographically strong pseudorandom\ndata. See [Session Resumption](#session-resumption) for more information.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"pskCallback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"For TLS-PSK negotiation, see [Pre-shared keys](#pre-shared-keys).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"pskIdentityHint","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"optional hint to send to a client to help\nwith selecting the identity during TLS-PSK negotiation. Will be ignored\nin TLS 1.3. Upon failing to set pskIdentityHint `'tlsClientError'` will be\nemitted with `'ERR_TLS_PSK_SET_IDENTITY_HINT_FAILED'` code.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"","type":null,"description":"...: Any [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) option can be provided. For\nservers, the identity options (`pfx`, `key`/`cert`, or `pskCallback`)\nare usually required.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"","type":null,"description":"...: Any [`net.createServer()`](net.html#netcreateserveroptions-connectionlistener) option can be provided.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"secureConnectionListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"tls.Server","links":[{"name":"tls.Server","href":"tls.html#class-tlsserver","start":0,"end":10}]},"description":""}},"description":"Creates a new [`tls.Server`](#class-tlsserver). The `secureConnectionListener`, if provided, is\nautomatically set as a listener for the [`'secureConnection'`](#event-secureconnection) event.\n\nThe `ticketKeys` option is automatically shared between `node:cluster` module\nworkers.\n\nThe following illustrates a simple echo server:\n\n```mjs\nimport { createServer } from 'node:tls';\nimport { readFileSync } from 'node:fs';\n\nconst options = {\n  key: readFileSync('server-key.pem'),\n  cert: 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: [ readFileSync('client-cert.pem') ],\n};\n\nconst server = 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\n```cjs\nconst { createServer } = require('node:tls');\nconst { readFileSync } = require('node:fs');\n\nconst options = {\n  key: readFileSync('server-key.pem'),\n  cert: 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: [ readFileSync('client-cert.pem') ],\n};\n\nconst server = 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\nTo generate the certificate and key for this example, run:\n\n```bash\nopenssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n  -keyout server-key.pem -out server-cert.pem\n```\n\nThen, to generate the `client-cert.pem` certificate for this example, run:\n\n```bash\nopenssl pkcs12 -certpbe AES-256-CBC -export -out client-cert.pem \\\n  -inkey server-key.pem -in server-cert.pem\n```\n\nThe server can be tested by connecting to it using the example client from\n[`tls.connect()`](#tlsconnectoptions-callback).","summary":"Creates a new `tls.Server`. The `secureConnectionListener`, if provided, is automatically set as a listener for the `'secureConnection'` event.","examples":[{"language":"mjs","displayName":null,"code":"import { createServer } from 'node:tls';\nimport { readFileSync } from 'node:fs';\n\nconst options = {\n  key: readFileSync('server-key.pem'),\n  cert: 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: [ readFileSync('client-cert.pem') ],\n};\n\nconst server = 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});"},{"language":"cjs","displayName":null,"code":"const { createServer } = require('node:tls');\nconst { readFileSync } = require('node:fs');\n\nconst options = {\n  key: readFileSync('server-key.pem'),\n  cert: 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: [ readFileSync('client-cert.pem') ],\n};\n\nconst server = 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});"},{"language":"bash","displayName":null,"code":"openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n  -keyout server-key.pem -out server-cert.pem"},{"language":"bash","displayName":null,"code":"openssl pkcs12 -certpbe AES-256-CBC -export -out client-cert.pem \\\n  -inkey server-key.pem -in server-cert.pem"}],"children":[]},{"kind":"method","id":"tlssetdefaultcacertificatescerts","name":"setDefaultCACertificates","title":"`tls.setDefaultCACertificates(certs)`","scope":"module","overloadOf":null,"stability":null,"added":["v24.5.0","v22.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"certs","type":{"text":"string[] | ArrayBufferView[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"ArrayBufferView","href":"https://developer.mozilla.org/docs/Web/API/ArrayBufferView","start":11,"end":26}]},"description":"An array of CA certificates in PEM format.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Sets the default CA certificates used by Node.js TLS clients. If the provided\ncertificates are parsed successfully, they will become the default CA\ncertificate list returned by [`tls.getCACertificates()`](#tlsgetcacertificatestype) and used\nby subsequent TLS connections that don't specify their own CA certificates.\nThe certificates will be deduplicated before being set as the default.\n\nThis function only affects the current Node.js thread. Previous\nsessions cached by the HTTPS agent won't be affected by this change, so\nthis method should be called before any unwanted cacheable TLS connections are\nmade.\n\nTo use system CA certificates as the default:\n\n```cjs\nconst tls = require('node:tls');\ntls.setDefaultCACertificates(tls.getCACertificates('system'));\n```\n\n```mjs\nimport tls from 'node:tls';\ntls.setDefaultCACertificates(tls.getCACertificates('system'));\n```\n\nThis function completely replaces the default CA certificate list. To add additional\ncertificates to the existing defaults, get the current certificates and append to them:\n\n```cjs\nconst tls = require('node:tls');\nconst currentCerts = tls.getCACertificates('default');\nconst additionalCerts = ['-----BEGIN CERTIFICATE-----\\n...'];\ntls.setDefaultCACertificates([...currentCerts, ...additionalCerts]);\n```\n\n```mjs\nimport tls from 'node:tls';\nconst currentCerts = tls.getCACertificates('default');\nconst additionalCerts = ['-----BEGIN CERTIFICATE-----\\n...'];\ntls.setDefaultCACertificates([...currentCerts, ...additionalCerts]);\n```","summary":"Sets the default CA certificates used by Node.js TLS clients. If the provided certificates are parsed successfully, they will become the default CA certificate list returned by `tls.getCACertificates()` and used by subsequent TLS connections that don't specify their own CA certificates. The certificates will be deduplicated before being set as the default.","examples":[{"language":"cjs","displayName":null,"code":"const tls = require('node:tls');\ntls.setDefaultCACertificates(tls.getCACertificates('system'));"},{"language":"mjs","displayName":null,"code":"import tls from 'node:tls';\ntls.setDefaultCACertificates(tls.getCACertificates('system'));"},{"language":"cjs","displayName":null,"code":"const tls = require('node:tls');\nconst currentCerts = tls.getCACertificates('default');\nconst additionalCerts = ['-----BEGIN CERTIFICATE-----\\n...'];\ntls.setDefaultCACertificates([...currentCerts, ...additionalCerts]);"},{"language":"mjs","displayName":null,"code":"import tls from 'node:tls';\nconst currentCerts = tls.getCACertificates('default');\nconst additionalCerts = ['-----BEGIN CERTIFICATE-----\\n...'];\ntls.setDefaultCACertificates([...currentCerts, ...additionalCerts]);"}],"children":[]},{"kind":"method","id":"tlsgetcacertificatestype","name":"getCACertificates","title":"`tls.getCACertificates([type])`","scope":"module","overloadOf":null,"stability":null,"added":["v23.10.0","v22.15.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"The type of CA certificates that will be returned. Valid values\nare `\"default\"`, `\"system\"`, `\"bundled\"` and `\"extra\"`.","default":"\"default\"","optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An array of PEM-encoded certificates. The array may contain duplicates\nif the same certificate is repeatedly stored in multiple sources."}},"description":"Returns an array containing the CA certificates from various sources, depending on `type`:\n\n* `\"default\"`: return the CA certificates that will be used by the Node.js TLS clients by default.\n  * When [`--use-bundled-ca`](cli.html#--use-bundled-ca---use-openssl-ca) is enabled (default), or [`--use-openssl-ca`](cli.html#--use-bundled-ca---use-openssl-ca) is not enabled,\n    this would include CA certificates from the bundled Mozilla CA store.\n  * When [`--use-system-ca`](cli.html#--use-system-ca) is enabled, this would also include certificates from the system's\n    trusted store.\n  * When [`NODE_EXTRA_CA_CERTS`](cli.html#node_extra_ca_certsfile) is used, this would also include certificates loaded from the specified\n    file.\n* `\"system\"`: return the CA certificates that are loaded from the system's trusted store, according\n  to rules set by [`--use-system-ca`](cli.html#--use-system-ca). This can be used to get the certificates from the system\n  when [`--use-system-ca`](cli.html#--use-system-ca) is not enabled.\n* `\"bundled\"`: return the CA certificates from the bundled Mozilla CA store. This would be the same\n  as [`tls.rootCertificates`](#tlsrootcertificates).\n* `\"extra\"`: return the CA certificates loaded from [`NODE_EXTRA_CA_CERTS`](cli.html#node_extra_ca_certsfile). It's an empty array if\n  [`NODE_EXTRA_CA_CERTS`](cli.html#node_extra_ca_certsfile) is not set.","summary":"Returns an array containing the CA certificates from various sources, depending on `type`:","examples":[],"children":[]},{"kind":"method","id":"tlsgetciphers","name":"getCiphers","title":"`tls.getCiphers()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.10.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"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()`](#tlscreatesecurecontextoptions).\n\nNot all supported ciphers are enabled by default. See\n[Modifying the default TLS cipher suite](#modifying-the-default-tls-cipher-suite).\n\nCipher names that start with `'tls_'` are for TLSv1.3, all the others are for\nTLSv1.2 and below.\n\n```js\nconsole.log(tls.getCiphers()); // ['aes128-gcm-sha256', 'aes128-sha', ...]\n```","summary":"Returns an array with the names of the supported TLS ciphers. The names are lower-case for historical reasons, but must be uppercased to be used in the `ciphers` option of `tls.createSecureContext()`.","examples":[{"language":"js","displayName":null,"code":"console.log(tls.getCiphers()); // ['aes128-gcm-sha256', 'aes128-sha', ...]"}],"children":[]},{"kind":"method","id":"tlsgetcertificatecompressionalgorithms","name":"getCertificateCompressionAlgorithms","title":"`tls.getCertificateCompressionAlgorithms()`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns an array with the names of the RFC 8879 certificate compression\nalgorithms supported by the current OpenSSL build, suitable for use in the\n`certificateCompression` option of [`tls.createSecureContext()`](#tlscreatesecurecontextoptions). Possible\nvalues include `'zlib'`, `'brotli'`, and `'zstd'`.\n\nThe array is empty when certificate compression is unavailable.\n\n```js\nconsole.log(tls.getCertificateCompressionAlgorithms()); // ['zlib', 'brotli', 'zstd']\n```","summary":"Returns an array with the names of the RFC 8879 certificate compression algorithms supported by the current OpenSSL build, suitable for use in the `certificateCompression` option of `tls.createSecureContext()`. Possible values include `'zlib'`, `'brotli'`, and `'zstd'`.","examples":[{"language":"js","displayName":null,"code":"console.log(tls.getCertificateCompressionAlgorithms()); // ['zlib', 'brotli', 'zstd']"}],"children":[]},{"kind":"property","id":"tlsrootcertificates","name":"rootCertificates","title":"`tls.rootCertificates`","scope":"module","overloadOf":null,"stability":null,"added":["v12.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"An immutable array of strings representing the root certificates (in PEM format)\nfrom the bundled Mozilla CA store as supplied by the current Node.js version.\n\nThe 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.\n\nTo get the actual CA certificates used by the current Node.js instance, which\nmay include certificates loaded from the system store (if `--use-system-ca` is used)\nor loaded from a file indicated by `NODE_EXTRA_CA_CERTS`, use\n[`tls.getCACertificates()`](#tlsgetcacertificatestype).","summary":"An immutable array of strings representing the root certificates (in PEM format) from the bundled Mozilla CA store as supplied by the current Node.js version.","examples":[],"children":[]},{"kind":"property","id":"tlsdefault_ecdh_curve","name":"DEFAULT_ECDH_CURVE","title":"`tls.DEFAULT_ECDH_CURVE`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.13"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v10.0.0"],"prUrl":"https://github.com/nodejs/node/pull/16853","commit":null,"description":"Default value changed to `'auto'`."}],"type":null,"default":null,"description":"The default named curve or TLS group list to use for key agreement in a TLS\nserver. The default value is `'auto'`. See [`tls.createSecureContext()`](#tlscreatesecurecontextoptions) for\nfurther information.","summary":"The default named curve or TLS group list to use for key agreement in a TLS server. The default value is `'auto'`. See `tls.createSecureContext()` for further information.","examples":[],"children":[]},{"kind":"property","id":"tlsdefault_max_version","name":"DEFAULT_MAX_VERSION","title":"`tls.DEFAULT_MAX_VERSION`","scope":"module","overloadOf":null,"stability":null,"added":["v11.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"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","description":"The default value of the `maxVersion` option of\n[`tls.createSecureContext()`](#tlscreatesecurecontextoptions). It can be assigned any of the supported TLS\nprotocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`.","summary":"","examples":[],"children":[]},{"kind":"property","id":"tlsdefault_min_version","name":"DEFAULT_MIN_VERSION","title":"`tls.DEFAULT_MIN_VERSION`","scope":"module","overloadOf":null,"stability":null,"added":["v11.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"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","description":"The default value of the `minVersion` option of\n[`tls.createSecureContext()`](#tlscreatesecurecontextoptions). It can be assigned any of the supported TLS\nprotocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`.\nVersions before TLSv1.2 may require downgrading the [OpenSSL Security Level](#openssl-security-level).","summary":"","examples":[],"children":[]},{"kind":"property","id":"tlsdefault_ciphers","name":"DEFAULT_CIPHERS","title":"`tls.DEFAULT_CIPHERS`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The default value of the `ciphers` option of\n[`tls.createSecureContext()`](#tlscreatesecurecontextoptions). It can be assigned any of the supported\nOpenSSL ciphers.  Defaults to the content of\n`crypto.constants.defaultCoreCipherList`, unless changed using CLI options\nusing `--tls-default-ciphers`.","summary":"","examples":[],"children":[]}]}