1# TLS (SSL) 2 3<!--introduced_in=v0.10.0--> 4 5> Stability: 2 - Stable 6 7<!-- source_link=lib/tls.js --> 8 9The `node:tls` module provides an implementation of the Transport Layer Security 10(TLS) and Secure Socket Layer (SSL) protocols that is built on top of OpenSSL. 11The module can be accessed using: 12 13```js 14const tls = require('node:tls'); 15``` 16 17## Determining if crypto support is unavailable 18 19It is possible for Node.js to be built without including support for the 20`node:crypto` module. In such cases, attempting to `import` from `tls` or 21calling `require('node:tls')` will result in an error being thrown. 22 23When using CommonJS, the error thrown can be caught using try/catch: 24 25<!-- eslint-skip --> 26 27```cjs 28let tls; 29try { 30 tls = require('node:tls'); 31} catch (err) { 32 console.error('tls support is disabled!'); 33} 34``` 35 36When using the lexical ESM `import` keyword, the error can only be 37caught if a handler for `process.on('uncaughtException')` is registered 38_before_ any attempt to load the module is made (using, for instance, 39a preload module). 40 41When using ESM, if there is a chance that the code may be run on a build 42of Node.js where crypto support is not enabled, consider using the 43[`import()`][] function instead of the lexical `import` keyword: 44 45```mjs 46let tls; 47try { 48 tls = await import('node:tls'); 49} catch (err) { 50 console.error('tls support is disabled!'); 51} 52``` 53 54## TLS/SSL concepts 55 56TLS/SSL is a set of protocols that rely on a public key infrastructure (PKI) to 57enable secure communication between a client and a server. For most common 58cases, each server must have a private key. 59 60Private keys can be generated in multiple ways. The example below illustrates 61use of the OpenSSL command-line interface to generate a 2048-bit RSA private 62key: 63 64```bash 65openssl genrsa -out ryans-key.pem 2048 66``` 67 68With TLS/SSL, all servers (and some clients) must have a _certificate_. 69Certificates are _public keys_ that correspond to a private key, and that are 70digitally signed either by a Certificate Authority or by the owner of the 71private key (such certificates are referred to as "self-signed"). The first 72step to obtaining a certificate is to create a _Certificate Signing Request_ 73(CSR) file. 74 75The OpenSSL command-line interface can be used to generate a CSR for a private 76key: 77 78```bash 79openssl req -new -sha256 -key ryans-key.pem -out ryans-csr.pem 80``` 81 82Once the CSR file is generated, it can either be sent to a Certificate 83Authority for signing or used to generate a self-signed certificate. 84 85Creating a self-signed certificate using the OpenSSL command-line interface 86is illustrated in the example below: 87 88```bash 89openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem 90``` 91 92Once the certificate is generated, it can be used to generate a `.pfx` or 93`.p12` file: 94 95```bash 96openssl pkcs12 -export -in ryans-cert.pem -inkey ryans-key.pem \ 97 -certfile ca-cert.pem -out ryans.pfx 98``` 99 100Where: 101 102* `in`: is the signed certificate 103* `inkey`: is the associated private key 104* `certfile`: is a concatenation of all Certificate Authority (CA) certs into 105 a single file, e.g. `cat ca1-cert.pem ca2-cert.pem > ca-cert.pem` 106 107### Perfect forward secrecy 108 109<!-- type=misc --> 110 111The term _[forward secrecy][]_ or _perfect forward secrecy_ describes a feature 112of key-agreement (i.e., key-exchange) methods. That is, the server and client 113keys are used to negotiate new temporary keys that are used specifically and 114only for the current communication session. Practically, this means that even 115if the server's private key is compromised, communication can only be decrypted 116by eavesdroppers if the attacker manages to obtain the key-pair specifically 117generated for the session. 118 119Perfect forward secrecy is achieved by randomly generating a key pair for 120key-agreement on every TLS/SSL handshake (in contrast to using the same key for 121all sessions). Methods implementing this technique are called "ephemeral". 122 123Currently two methods are commonly used to achieve perfect forward secrecy (note 124the character "E" appended to the traditional abbreviations): 125 126* [ECDHE][]: An ephemeral version of the Elliptic Curve Diffie-Hellman 127 key-agreement protocol. 128* [DHE][]: An ephemeral version of the Diffie-Hellman key-agreement protocol. 129 130Perfect forward secrecy using ECDHE is enabled by default. The `ecdhCurve` 131option can be used when creating a TLS server to customize the list of supported 132ECDH curves to use. See [`tls.createServer()`][] for more info. 133 134DHE is disabled by default but can be enabled alongside ECDHE by setting the 135`dhparam` option to `'auto'`. Custom DHE parameters are also supported but 136discouraged in favor of automatically selected, well-known parameters. 137 138Perfect forward secrecy was optional up to TLSv1.2. As of TLSv1.3, (EC)DHE is 139always used (with the exception of PSK-only connections). 140 141### ALPN and SNI 142 143<!-- type=misc --> 144 145ALPN (Application-Layer Protocol Negotiation Extension) and 146SNI (Server Name Indication) are TLS handshake extensions: 147 148* ALPN: Allows the use of one TLS server for multiple protocols (HTTP, HTTP/2) 149* SNI: Allows the use of one TLS server for multiple hostnames with different 150 certificates. 151 152### Pre-shared keys 153 154<!-- type=misc --> 155 156TLS-PSK support is available as an alternative to normal certificate-based 157authentication. It uses a pre-shared key instead of certificates to 158authenticate a TLS connection, providing mutual authentication. 159TLS-PSK and public key infrastructure are not mutually exclusive. Clients and 160servers can accommodate both, choosing either of them during the normal cipher 161negotiation step. 162 163TLS-PSK is only a good choice where means exist to securely share a 164key with every connecting machine, so it does not replace the public key 165infrastructure (PKI) for the majority of TLS uses. 166The TLS-PSK implementation in OpenSSL has seen many security flaws in 167recent years, mostly because it is used only by a minority of applications. 168Please consider all alternative solutions before switching to PSK ciphers. 169Upon generating PSK it is of critical importance to use sufficient entropy as 170discussed in [RFC 4086][]. Deriving a shared secret from a password or other 171low-entropy sources is not secure. 172 173PSK ciphers are disabled by default, and using TLS-PSK thus requires explicitly 174specifying a cipher suite with the `ciphers` option. The list of available 175ciphers can be retrieved via `openssl ciphers -v 'PSK'`. All TLS 1.3 176ciphers are eligible for PSK and can be retrieved via 177`openssl ciphers -v -s -tls1_3 -psk`. 178 179According to the [RFC 4279][], PSK identities up to 128 bytes in length and 180PSKs up to 64 bytes in length must be supported. As of OpenSSL 1.1.0 181maximum identity size is 128 bytes, and maximum PSK length is 256 bytes. 182 183The current implementation doesn't support asynchronous PSK callbacks due to the 184limitations of the underlying OpenSSL API. 185 186### Client-initiated renegotiation attack mitigation 187 188<!-- type=misc --> 189 190The TLS protocol allows clients to renegotiate certain aspects of the TLS 191session. Unfortunately, session renegotiation requires a disproportionate amount 192of server-side resources, making it a potential vector for denial-of-service 193attacks. 194 195To mitigate the risk, renegotiation is limited to three times every ten minutes. 196An `'error'` event is emitted on the [`tls.TLSSocket`][] instance when this 197threshold is exceeded. The limits are configurable: 198 199* `tls.CLIENT_RENEG_LIMIT` {number} Specifies the number of renegotiation 200 requests. **Default:** `3`. 201* `tls.CLIENT_RENEG_WINDOW` {number} Specifies the time renegotiation window 202 in seconds. **Default:** `600` (10 minutes). 203 204The default renegotiation limits should not be modified without a full 205understanding of the implications and risks. 206 207TLSv1.3 does not support renegotiation. 208 209### Session resumption 210 211Establishing a TLS session can be relatively slow. The process can be sped 212up by saving and later reusing the session state. There are several mechanisms 213to do so, discussed here from oldest to newest (and preferred). 214 215#### Session identifiers 216 217Servers generate a unique ID for new connections and 218send it to the client. Clients and servers save the session state. When 219reconnecting, clients send the ID of their saved session state and if the server 220also has the state for that ID, it can agree to use it. Otherwise, the server 221will create a new session. See [RFC 2246][] for more information, page 23 and 22230\. 223 224Resumption using session identifiers is supported by most web browsers when 225making HTTPS requests. 226 227For Node.js, clients wait for the [`'session'`][] event to get the session data, 228and provide the data to the `session` option of a subsequent [`tls.connect()`][] 229to reuse the session. Servers must 230implement handlers for the [`'newSession'`][] and [`'resumeSession'`][] events 231to save and restore the session data using the session ID as the lookup key to 232reuse sessions. To reuse sessions across load balancers or cluster workers, 233servers must use a shared session cache (such as Redis) in their session 234handlers. 235 236#### Session tickets 237 238The servers encrypt the entire session state and send it 239to the client as a "ticket". When reconnecting, the state is sent to the server 240in the initial connection. This mechanism avoids the need for a server-side 241session cache. If the server doesn't use the ticket, for any reason (failure 242to decrypt it, it's too old, etc.), it will create a new session and send a new 243ticket. See [RFC 5077][] for more information. 244 245Resumption using session tickets is becoming commonly supported by many web 246browsers when making HTTPS requests. 247 248For Node.js, clients use the same APIs for resumption with session identifiers 249as for resumption with session tickets. For debugging, if 250[`tls.TLSSocket.getTLSTicket()`][] returns a value, the session data contains a 251ticket, otherwise it contains client-side session state. 252 253With TLSv1.3, be aware that multiple tickets may be sent by the server, 254resulting in multiple `'session'` events, see [`'session'`][] for more 255information. 256 257Single process servers need no specific implementation to use session tickets. 258To use session tickets across server restarts or load balancers, servers must 259all have the same ticket keys. There are three 16-byte keys internally, but the 260tls API exposes them as a single 48-byte buffer for convenience. 261 262It's possible to get the ticket keys by calling [`server.getTicketKeys()`][] on 263one server instance and then distribute them, but it is more reasonable to 264securely generate 48 bytes of secure random data and set them with the 265`ticketKeys` option of [`tls.createServer()`][]. The keys should be regularly 266regenerated and server's keys can be reset with 267[`server.setTicketKeys()`][]. 268 269Session ticket keys are cryptographic keys, and they _**must be stored 270securely**_. With TLS 1.2 and below, if they are compromised all sessions that 271used tickets encrypted with them can be decrypted. They should not be stored 272on disk, and they should be regenerated regularly. 273 274If clients advertise support for tickets, the server will send them. The 275server can disable tickets by supplying 276`require('node:constants').SSL_OP_NO_TICKET` in `secureOptions`. 277 278Both session identifiers and session tickets timeout, causing the server to 279create new sessions. The timeout can be configured with the `sessionTimeout` 280option of [`tls.createServer()`][]. 281 282For all the mechanisms, when resumption fails, servers will create new sessions. 283Since failing to resume the session does not cause TLS/HTTPS connection 284failures, it is easy to not notice unnecessarily poor TLS performance. The 285OpenSSL CLI can be used to verify that servers are resuming sessions. Use the 286`-reconnect` option to `openssl s_client`, for example: 287 288```console 289$ openssl s_client -connect localhost:443 -reconnect 290``` 291 292Read through the debug output. The first connection should say "New", for 293example: 294 295```text 296New, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256 297``` 298 299Subsequent connections should say "Reused", for example: 300 301```text 302Reused, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256 303``` 304 305## Modifying the default TLS cipher suite 306 307Node.js is built with a default suite of enabled and disabled TLS ciphers. This 308default cipher list can be configured when building Node.js to allow 309distributions to provide their own default list. 310 311The following command can be used to show the default cipher suite: 312 313```console 314node -p crypto.constants.defaultCoreCipherList | tr ':' '\n' 315TLS_AES_256_GCM_SHA384 316TLS_CHACHA20_POLY1305_SHA256 317TLS_AES_128_GCM_SHA256 318ECDHE-RSA-AES128-GCM-SHA256 319ECDHE-ECDSA-AES128-GCM-SHA256 320ECDHE-RSA-AES256-GCM-SHA384 321ECDHE-ECDSA-AES256-GCM-SHA384 322DHE-RSA-AES128-GCM-SHA256 323ECDHE-RSA-AES128-SHA256 324DHE-RSA-AES128-SHA256 325ECDHE-RSA-AES256-SHA384 326DHE-RSA-AES256-SHA384 327ECDHE-RSA-AES256-SHA256 328DHE-RSA-AES256-SHA256 329HIGH 330!aNULL 331!eNULL 332!EXPORT 333!DES 334!RC4 335!MD5 336!PSK 337!SRP 338!CAMELLIA 339``` 340 341This default can be replaced entirely using the [`--tls-cipher-list`][] 342command-line switch (directly, or via the [`NODE_OPTIONS`][] environment 343variable). For instance, the following makes `ECDHE-RSA-AES128-GCM-SHA256:!RC4` 344the default TLS cipher suite: 345 346```bash 347node --tls-cipher-list='ECDHE-RSA-AES128-GCM-SHA256:!RC4' server.js 348 349export NODE_OPTIONS=--tls-cipher-list='ECDHE-RSA-AES128-GCM-SHA256:!RC4' 350node server.js 351``` 352 353To verify, use the following command to show the set cipher list, note the 354difference between `defaultCoreCipherList` and `defaultCipherList`: 355 356```bash 357node --tls-cipher-list='ECDHE-RSA-AES128-GCM-SHA256:!RC4' -p crypto.constants.defaultCipherList | tr ':' '\n' 358ECDHE-RSA-AES128-GCM-SHA256 359!RC4 360``` 361 362i.e. the `defaultCoreCipherList` list is set at compilation time and the 363`defaultCipherList` is set at runtime. 364 365To modify the default cipher suites from within the runtime, modify the 366`tls.DEFAULT_CIPHERS` variable, this must be performed before listening on any 367sockets, it will not affect sockets already opened. For example: 368 369```js 370// Remove Obsolete CBC Ciphers and RSA Key Exchange based Ciphers as they don't provide Forward Secrecy 371tls.DEFAULT_CIPHERS += 372 ':!ECDHE-RSA-AES128-SHA:!ECDHE-RSA-AES128-SHA256:!ECDHE-RSA-AES256-SHA:!ECDHE-RSA-AES256-SHA384' + 373 ':!ECDHE-ECDSA-AES128-SHA:!ECDHE-ECDSA-AES128-SHA256:!ECDHE-ECDSA-AES256-SHA:!ECDHE-ECDSA-AES256-SHA384' + 374 ':!kRSA'; 375``` 376 377The default can also be replaced on a per client or server basis using the 378`ciphers` option from [`tls.createSecureContext()`][], which is also available 379in [`tls.createServer()`][], [`tls.connect()`][], and when creating new 380[`tls.TLSSocket`][]s. 381 382The ciphers list can contain a mixture of TLSv1.3 cipher suite names, the ones 383that start with `'TLS_'`, and specifications for TLSv1.2 and below cipher 384suites. The TLSv1.2 ciphers support a legacy specification format, consult 385the OpenSSL [cipher list format][] documentation for details, but those 386specifications do _not_ apply to TLSv1.3 ciphers. The TLSv1.3 suites can only 387be enabled by including their full name in the cipher list. They cannot, for 388example, be enabled or disabled by using the legacy TLSv1.2 `'EECDH'` or 389`'!EECDH'` specification. 390 391Despite the relative order of TLSv1.3 and TLSv1.2 cipher suites, the TLSv1.3 392protocol is significantly more secure than TLSv1.2, and will always be chosen 393over TLSv1.2 if the handshake indicates it is supported, and if any TLSv1.3 394cipher suites are enabled. 395 396The default cipher suite included within Node.js has been carefully 397selected to reflect current security best practices and risk mitigation. 398Changing the default cipher suite can have a significant impact on the security 399of an application. The `--tls-cipher-list` switch and `ciphers` option should by 400used only if absolutely necessary. 401 402The default cipher suite prefers GCM ciphers for [Chrome's 'modern 403cryptography' setting][] and also prefers ECDHE and DHE ciphers for perfect 404forward secrecy, while offering _some_ backward compatibility. 405 406Old clients that rely on insecure and deprecated RC4 or DES-based ciphers 407(like Internet Explorer 6) cannot complete the handshaking process with 408the default configuration. If these clients _must_ be supported, the 409[TLS recommendations][] may offer a compatible cipher suite. For more details 410on the format, see the OpenSSL [cipher list format][] documentation. 411 412There are only five TLSv1.3 cipher suites: 413 414* `'TLS_AES_256_GCM_SHA384'` 415* `'TLS_CHACHA20_POLY1305_SHA256'` 416* `'TLS_AES_128_GCM_SHA256'` 417* `'TLS_AES_128_CCM_SHA256'` 418* `'TLS_AES_128_CCM_8_SHA256'` 419 420The first three are enabled by default. The two `CCM`-based suites are supported 421by TLSv1.3 because they may be more performant on constrained systems, but they 422are not enabled by default since they offer less security. 423 424## X509 certificate error codes 425 426Multiple functions can fail due to certificate errors that are reported by 427OpenSSL. In such a case, the function provides an {Error} via its callback that 428has the property `code` which can take one of the following values: 429 430<!-- 431values are taken from src/crypto/crypto_common.cc 432description are taken from deps/openssl/openssl/crypto/x509/x509_txt.c 433--> 434 435* `'UNABLE_TO_GET_ISSUER_CERT'`: Unable to get issuer certificate. 436* `'UNABLE_TO_GET_CRL'`: Unable to get certificate CRL. 437* `'UNABLE_TO_DECRYPT_CERT_SIGNATURE'`: Unable to decrypt certificate's 438 signature. 439* `'UNABLE_TO_DECRYPT_CRL_SIGNATURE'`: Unable to decrypt CRL's signature. 440* `'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY'`: Unable to decode issuer public key. 441* `'CERT_SIGNATURE_FAILURE'`: Certificate signature failure. 442* `'CRL_SIGNATURE_FAILURE'`: CRL signature failure. 443* `'CERT_NOT_YET_VALID'`: Certificate is not yet valid. 444* `'CERT_HAS_EXPIRED'`: Certificate has expired. 445* `'CRL_NOT_YET_VALID'`: CRL is not yet valid. 446* `'CRL_HAS_EXPIRED'`: CRL has expired. 447* `'ERROR_IN_CERT_NOT_BEFORE_FIELD'`: Format error in certificate's notBefore 448 field. 449* `'ERROR_IN_CERT_NOT_AFTER_FIELD'`: Format error in certificate's notAfter 450 field. 451* `'ERROR_IN_CRL_LAST_UPDATE_FIELD'`: Format error in CRL's lastUpdate field. 452* `'ERROR_IN_CRL_NEXT_UPDATE_FIELD'`: Format error in CRL's nextUpdate field. 453* `'OUT_OF_MEM'`: Out of memory. 454* `'DEPTH_ZERO_SELF_SIGNED_CERT'`: Self signed certificate. 455* `'SELF_SIGNED_CERT_IN_CHAIN'`: Self signed certificate in certificate chain. 456* `'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'`: Unable to get local issuer certificate. 457* `'UNABLE_TO_VERIFY_LEAF_SIGNATURE'`: Unable to verify the first certificate. 458* `'CERT_CHAIN_TOO_LONG'`: Certificate chain too long. 459* `'CERT_REVOKED'`: Certificate revoked. 460* `'INVALID_CA'`: Invalid CA certificate. 461* `'PATH_LENGTH_EXCEEDED'`: Path length constraint exceeded. 462* `'INVALID_PURPOSE'`: Unsupported certificate purpose. 463* `'CERT_UNTRUSTED'`: Certificate not trusted. 464* `'CERT_REJECTED'`: Certificate rejected. 465* `'HOSTNAME_MISMATCH'`: Hostname mismatch. 466 467## Class: `tls.CryptoStream` 468 469<!-- YAML 470added: v0.3.4 471deprecated: v0.11.3 472--> 473 474> Stability: 0 - Deprecated: Use [`tls.TLSSocket`][] instead. 475 476The `tls.CryptoStream` class represents a stream of encrypted data. This class 477is deprecated and should no longer be used. 478 479### `cryptoStream.bytesWritten` 480 481<!-- YAML 482added: v0.3.4 483deprecated: v0.11.3 484--> 485 486The `cryptoStream.bytesWritten` property returns the total number of bytes 487written to the underlying socket _including_ the bytes required for the 488implementation of the TLS protocol. 489 490## Class: `tls.SecurePair` 491 492<!-- YAML 493added: v0.3.2 494deprecated: v0.11.3 495--> 496 497> Stability: 0 - Deprecated: Use [`tls.TLSSocket`][] instead. 498 499Returned by [`tls.createSecurePair()`][]. 500 501### Event: `'secure'` 502 503<!-- YAML 504added: v0.3.2 505deprecated: v0.11.3 506--> 507 508The `'secure'` event is emitted by the `SecurePair` object once a secure 509connection has been established. 510 511As with checking for the server 512[`'secureConnection'`][] 513event, `pair.cleartext.authorized` should be inspected to confirm whether the 514certificate used is properly authorized. 515 516## Class: `tls.Server` 517 518<!-- YAML 519added: v0.3.2 520--> 521 522* Extends: {net.Server} 523 524Accepts encrypted connections using TLS or SSL. 525 526### Event: `'connection'` 527 528<!-- YAML 529added: v0.3.2 530--> 531 532* `socket` {stream.Duplex} 533 534This event is emitted when a new TCP stream is established, before the TLS 535handshake begins. `socket` is typically an object of type [`net.Socket`][] but 536will not receive events unlike the socket created from the [`net.Server`][] 537`'connection'` event. Usually users will not want to access this event. 538 539This event can also be explicitly emitted by users to inject connections 540into the TLS server. In that case, any [`Duplex`][] stream can be passed. 541 542### Event: `'keylog'` 543 544<!-- YAML 545added: 546 - v12.3.0 547 - v10.20.0 548--> 549 550* `line` {Buffer} Line of ASCII text, in NSS `SSLKEYLOGFILE` format. 551* `tlsSocket` {tls.TLSSocket} The `tls.TLSSocket` instance on which it was 552 generated. 553 554The `keylog` event is emitted when key material is generated or received by 555a connection to this server (typically before handshake has completed, but not 556necessarily). This keying material can be stored for debugging, as it allows 557captured TLS traffic to be decrypted. It may be emitted multiple times for 558each socket. 559 560A typical use case is to append received lines to a common text file, which 561is later used by software (such as Wireshark) to decrypt the traffic: 562 563```js 564const logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' }); 565// ... 566server.on('keylog', (line, tlsSocket) => { 567 if (tlsSocket.remoteAddress !== '...') 568 return; // Only log keys for a particular IP 569 logFile.write(line); 570}); 571``` 572 573### Event: `'newSession'` 574 575<!-- YAML 576added: v0.9.2 577changes: 578 - version: v0.11.12 579 pr-url: https://github.com/nodejs/node-v0.x-archive/pull/7118 580 description: The `callback` argument is now supported. 581--> 582 583The `'newSession'` event is emitted upon creation of a new TLS session. This may 584be used to store sessions in external storage. The data should be provided to 585the [`'resumeSession'`][] callback. 586 587The listener callback is passed three arguments when called: 588 589* `sessionId` {Buffer} The TLS session identifier 590* `sessionData` {Buffer} The TLS session data 591* `callback` {Function} A callback function taking no arguments that must be 592 invoked in order for data to be sent or received over the secure connection. 593 594Listening for this event will have an effect only on connections established 595after the addition of the event listener. 596 597### Event: `'OCSPRequest'` 598 599<!-- YAML 600added: v0.11.13 601--> 602 603The `'OCSPRequest'` event is emitted when the client sends a certificate status 604request. The listener callback is passed three arguments when called: 605 606* `certificate` {Buffer} The server certificate 607* `issuer` {Buffer} The issuer's certificate 608* `callback` {Function} A callback function that must be invoked to provide 609 the results of the OCSP request. 610 611The server's current certificate can be parsed to obtain the OCSP URL 612and certificate ID; after obtaining an OCSP response, `callback(null, resp)` is 613then invoked, where `resp` is a `Buffer` instance containing the OCSP response. 614Both `certificate` and `issuer` are `Buffer` DER-representations of the 615primary and issuer's certificates. These can be used to obtain the OCSP 616certificate ID and OCSP endpoint URL. 617 618Alternatively, `callback(null, null)` may be called, indicating that there was 619no OCSP response. 620 621Calling `callback(err)` will result in a `socket.destroy(err)` call. 622 623The typical flow of an OCSP request is as follows: 624 6251. Client connects to the server and sends an `'OCSPRequest'` (via the status 626 info extension in ClientHello). 6272. Server receives the request and emits the `'OCSPRequest'` event, calling the 628 listener if registered. 6293. Server extracts the OCSP URL from either the `certificate` or `issuer` and 630 performs an [OCSP request][] to the CA. 6314. Server receives `'OCSPResponse'` from the CA and sends it back to the client 632 via the `callback` argument 6335. Client validates the response and either destroys the socket or performs a 634 handshake. 635 636The `issuer` can be `null` if the certificate is either self-signed or the 637issuer is not in the root certificates list. (An issuer may be provided 638via the `ca` option when establishing the TLS connection.) 639 640Listening for this event will have an effect only on connections established 641after the addition of the event listener. 642 643An npm module like [asn1.js][] may be used to parse the certificates. 644 645### Event: `'resumeSession'` 646 647<!-- YAML 648added: v0.9.2 649--> 650 651The `'resumeSession'` event is emitted when the client requests to resume a 652previous TLS session. The listener callback is passed two arguments when 653called: 654 655* `sessionId` {Buffer} The TLS session identifier 656* `callback` {Function} A callback function to be called when the prior session 657 has been recovered: `callback([err[, sessionData]])` 658 * `err` {Error} 659 * `sessionData` {Buffer} 660 661The event listener should perform a lookup in external storage for the 662`sessionData` saved by the [`'newSession'`][] event handler using the given 663`sessionId`. If found, call `callback(null, sessionData)` to resume the session. 664If not found, the session cannot be resumed. `callback()` must be called 665without `sessionData` so that the handshake can continue and a new session can 666be created. It is possible to call `callback(err)` to terminate the incoming 667connection and destroy the socket. 668 669Listening for this event will have an effect only on connections established 670after the addition of the event listener. 671 672The following illustrates resuming a TLS session: 673 674```js 675const tlsSessionStore = {}; 676server.on('newSession', (id, data, cb) => { 677 tlsSessionStore[id.toString('hex')] = data; 678 cb(); 679}); 680server.on('resumeSession', (id, cb) => { 681 cb(null, tlsSessionStore[id.toString('hex')] || null); 682}); 683``` 684 685### Event: `'secureConnection'` 686 687<!-- YAML 688added: v0.3.2 689--> 690 691The `'secureConnection'` event is emitted after the handshaking process for a 692new connection has successfully completed. The listener callback is passed a 693single argument when called: 694 695* `tlsSocket` {tls.TLSSocket} The established TLS socket. 696 697The `tlsSocket.authorized` property is a `boolean` indicating whether the 698client has been verified by one of the supplied Certificate Authorities for the 699server. If `tlsSocket.authorized` is `false`, then `socket.authorizationError` 700is set to describe how authorization failed. Depending on the settings 701of the TLS server, unauthorized connections may still be accepted. 702 703The `tlsSocket.alpnProtocol` property is a string that contains the selected 704ALPN protocol. When ALPN has no selected protocol, `tlsSocket.alpnProtocol` 705equals `false`. 706 707The `tlsSocket.servername` property is a string containing the server name 708requested via SNI. 709 710### Event: `'tlsClientError'` 711 712<!-- YAML 713added: v6.0.0 714--> 715 716The `'tlsClientError'` event is emitted when an error occurs before a secure 717connection is established. The listener callback is passed two arguments when 718called: 719 720* `exception` {Error} The `Error` object describing the error 721* `tlsSocket` {tls.TLSSocket} The `tls.TLSSocket` instance from which the 722 error originated. 723 724### `server.addContext(hostname, context)` 725 726<!-- YAML 727added: v0.5.3 728--> 729 730* `hostname` {string} A SNI host name or wildcard (e.g. `'*'`) 731* `context` {Object|tls.SecureContext} An object containing any of the possible 732 properties from the [`tls.createSecureContext()`][] `options` arguments 733 (e.g. `key`, `cert`, `ca`, etc), or a TLS context object created with 734 [`tls.createSecureContext()`][] itself. 735 736The `server.addContext()` method adds a secure context that will be used if 737the client request's SNI name matches the supplied `hostname` (or wildcard). 738 739When there are multiple matching contexts, the most recently added one is 740used. 741 742### `server.address()` 743 744<!-- YAML 745added: v0.6.0 746--> 747 748* Returns: {Object} 749 750Returns the bound address, the address family name, and port of the 751server as reported by the operating system. See [`net.Server.address()`][] for 752more information. 753 754### `server.close([callback])` 755 756<!-- YAML 757added: v0.3.2 758--> 759 760* `callback` {Function} A listener callback that will be registered to listen 761 for the server instance's `'close'` event. 762* Returns: {tls.Server} 763 764The `server.close()` method stops the server from accepting new connections. 765 766This function operates asynchronously. The `'close'` event will be emitted 767when the server has no more open connections. 768 769### `server.getTicketKeys()` 770 771<!-- YAML 772added: v3.0.0 773--> 774 775* Returns: {Buffer} A 48-byte buffer containing the session ticket keys. 776 777Returns the session ticket keys. 778 779See [Session Resumption][] for more information. 780 781### `server.listen()` 782 783Starts the server listening for encrypted connections. 784This method is identical to [`server.listen()`][] from [`net.Server`][]. 785 786### `server.setSecureContext(options)` 787 788<!-- YAML 789added: v11.0.0 790--> 791 792* `options` {Object} An object containing any of the possible properties from 793 the [`tls.createSecureContext()`][] `options` arguments (e.g. `key`, `cert`, 794 `ca`, etc). 795 796The `server.setSecureContext()` method replaces the secure context of an 797existing server. Existing connections to the server are not interrupted. 798 799### `server.setTicketKeys(keys)` 800 801<!-- YAML 802added: v3.0.0 803--> 804 805* `keys` {Buffer|TypedArray|DataView} A 48-byte buffer containing the session 806 ticket keys. 807 808Sets the session ticket keys. 809 810Changes to the ticket keys are effective only for future server connections. 811Existing or currently pending server connections will use the previous keys. 812 813See [Session Resumption][] for more information. 814 815## Class: `tls.TLSSocket` 816 817<!-- YAML 818added: v0.11.4 819--> 820 821* Extends: {net.Socket} 822 823Performs transparent encryption of written data and all required TLS 824negotiation. 825 826Instances of `tls.TLSSocket` implement the duplex [Stream][] interface. 827 828Methods that return TLS connection metadata (e.g. 829[`tls.TLSSocket.getPeerCertificate()`][]) will only return data while the 830connection is open. 831 832### `new tls.TLSSocket(socket[, options])` 833 834<!-- YAML 835added: v0.11.4 836changes: 837 - version: v12.2.0 838 pr-url: https://github.com/nodejs/node/pull/27497 839 description: The `enableTrace` option is now supported. 840 - version: v5.0.0 841 pr-url: https://github.com/nodejs/node/pull/2564 842 description: ALPN options are supported now. 843--> 844 845* `socket` {net.Socket|stream.Duplex} 846 On the server side, any `Duplex` stream. On the client side, any 847 instance of [`net.Socket`][] (for generic `Duplex` stream support 848 on the client side, [`tls.connect()`][] must be used). 849* `options` {Object} 850 * `enableTrace`: See [`tls.createServer()`][] 851 * `isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if 852 they are to behave as a server or a client. If `true` the TLS socket will be 853 instantiated as a server. **Default:** `false`. 854 * `server` {net.Server} A [`net.Server`][] instance. 855 * `requestCert`: Whether to authenticate the remote peer by requesting a 856 certificate. Clients always request a server certificate. Servers 857 (`isServer` is true) may set `requestCert` to true to request a client 858 certificate. 859 * `rejectUnauthorized`: See [`tls.createServer()`][] 860 * `ALPNProtocols`: See [`tls.createServer()`][] 861 * `SNICallback`: See [`tls.createServer()`][] 862 * `session` {Buffer} A `Buffer` instance containing a TLS session. 863 * `requestOCSP` {boolean} If `true`, specifies that the OCSP status request 864 extension will be added to the client hello and an `'OCSPResponse'` event 865 will be emitted on the socket before establishing a secure communication 866 * `secureContext`: TLS context object created with 867 [`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one 868 will be created by passing the entire `options` object to 869 `tls.createSecureContext()`. 870 * ...: [`tls.createSecureContext()`][] options that are used if the 871 `secureContext` option is missing. Otherwise, they are ignored. 872 873Construct a new `tls.TLSSocket` object from an existing TCP socket. 874 875### Event: `'keylog'` 876 877<!-- YAML 878added: 879 - v12.3.0 880 - v10.20.0 881--> 882 883* `line` {Buffer} Line of ASCII text, in NSS `SSLKEYLOGFILE` format. 884 885The `keylog` event is emitted on a `tls.TLSSocket` when key material 886is generated or received by the socket. This keying material can be stored 887for debugging, as it allows captured TLS traffic to be decrypted. It may 888be emitted multiple times, before or after the handshake completes. 889 890A typical use case is to append received lines to a common text file, which 891is later used by software (such as Wireshark) to decrypt the traffic: 892 893```js 894const logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' }); 895// ... 896tlsSocket.on('keylog', (line) => logFile.write(line)); 897``` 898 899### Event: `'OCSPResponse'` 900 901<!-- YAML 902added: v0.11.13 903--> 904 905The `'OCSPResponse'` event is emitted if the `requestOCSP` option was set 906when the `tls.TLSSocket` was created and an OCSP response has been received. 907The listener callback is passed a single argument when called: 908 909* `response` {Buffer} The server's OCSP response 910 911Typically, the `response` is a digitally signed object from the server's CA that 912contains information about server's certificate revocation status. 913 914### Event: `'secureConnect'` 915 916<!-- YAML 917added: v0.11.4 918--> 919 920The `'secureConnect'` event is emitted after the handshaking process for a new 921connection has successfully completed. The listener callback will be called 922regardless of whether or not the server's certificate has been authorized. It 923is the client's responsibility to check the `tlsSocket.authorized` property to 924determine if the server certificate was signed by one of the specified CAs. If 925`tlsSocket.authorized === false`, then the error can be found by examining the 926`tlsSocket.authorizationError` property. If ALPN was used, the 927`tlsSocket.alpnProtocol` property can be checked to determine the negotiated 928protocol. 929 930The `'secureConnect'` event is not emitted when a {tls.TLSSocket} is created 931using the `new tls.TLSSocket()` constructor. 932 933### Event: `'session'` 934 935<!-- YAML 936added: v11.10.0 937--> 938 939* `session` {Buffer} 940 941The `'session'` event is emitted on a client `tls.TLSSocket` when a new session 942or TLS ticket is available. This may or may not be before the handshake is 943complete, depending on the TLS protocol version that was negotiated. The event 944is not emitted on the server, or if a new session was not created, for example, 945when the connection was resumed. For some TLS protocol versions the event may be 946emitted multiple times, in which case all the sessions can be used for 947resumption. 948 949On the client, the `session` can be provided to the `session` option of 950[`tls.connect()`][] to resume the connection. 951 952See [Session Resumption][] for more information. 953 954For TLSv1.2 and below, [`tls.TLSSocket.getSession()`][] can be called once 955the handshake is complete. For TLSv1.3, only ticket-based resumption is allowed 956by the protocol, multiple tickets are sent, and the tickets aren't sent until 957after the handshake completes. So it is necessary to wait for the 958`'session'` event to get a resumable session. Applications 959should use the `'session'` event instead of `getSession()` to ensure 960they will work for all TLS versions. Applications that only expect to 961get or use one session should listen for this event only once: 962 963```js 964tlsSocket.once('session', (session) => { 965 // The session can be used immediately or later. 966 tls.connect({ 967 session: session, 968 // Other connect options... 969 }); 970}); 971``` 972 973### `tlsSocket.address()` 974 975<!-- YAML 976added: v0.11.4 977changes: 978 - version: v18.4.0 979 pr-url: https://github.com/nodejs/node/pull/43054 980 description: The `family` property now returns a string instead of a number. 981 - version: v18.0.0 982 pr-url: https://github.com/nodejs/node/pull/41431 983 description: The `family` property now returns a number instead of a string. 984--> 985 986* Returns: {Object} 987 988Returns the bound `address`, the address `family` name, and `port` of the 989underlying socket as reported by the operating system: 990`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`. 991 992### `tlsSocket.authorizationError` 993 994<!-- YAML 995added: v0.11.4 996--> 997 998Returns the reason why the peer's certificate was not been verified. This 999property is set only when `tlsSocket.authorized === false`. 1000 1001### `tlsSocket.authorized` 1002 1003<!-- YAML 1004added: v0.11.4 1005--> 1006 1007* {boolean} 1008 1009This property is `true` if the peer certificate was signed by one of the CAs 1010specified when creating the `tls.TLSSocket` instance, otherwise `false`. 1011 1012### `tlsSocket.disableRenegotiation()` 1013 1014<!-- YAML 1015added: v8.4.0 1016--> 1017 1018Disables TLS renegotiation for this `TLSSocket` instance. Once called, attempts 1019to renegotiate will trigger an `'error'` event on the `TLSSocket`. 1020 1021### `tlsSocket.enableTrace()` 1022 1023<!-- YAML 1024added: v12.2.0 1025--> 1026 1027When enabled, TLS packet trace information is written to `stderr`. This can be 1028used to debug TLS connection problems. 1029 1030The format of the output is identical to the output of 1031`openssl s_client -trace` or `openssl s_server -trace`. While it is produced by 1032OpenSSL's `SSL_trace()` function, the format is undocumented, can change 1033without notice, and should not be relied on. 1034 1035### `tlsSocket.encrypted` 1036 1037<!-- YAML 1038added: v0.11.4 1039--> 1040 1041Always returns `true`. This may be used to distinguish TLS sockets from regular 1042`net.Socket` instances. 1043 1044### `tlsSocket.exportKeyingMaterial(length, label[, context])` 1045 1046<!-- YAML 1047added: 1048 - v13.10.0 1049 - v12.17.0 1050--> 1051 1052* `length` {number} number of bytes to retrieve from keying material 1053 1054* `label` {string} an application specific label, typically this will be a 1055 value from the 1056 [IANA Exporter Label Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels). 1057 1058* `context` {Buffer} Optionally provide a context. 1059 1060* Returns: {Buffer} requested bytes of the keying material 1061 1062Keying material is used for validations to prevent different kind of attacks in 1063network protocols, for example in the specifications of IEEE 802.1X. 1064 1065Example 1066 1067```js 1068const keyingMaterial = tlsSocket.exportKeyingMaterial( 1069 128, 1070 'client finished'); 1071 1072/* 1073 Example return value of keyingMaterial: 1074 <Buffer 76 26 af 99 c5 56 8e 42 09 91 ef 9f 93 cb ad 6c 7b 65 f8 53 f1 d8 d9 1075 12 5a 33 b8 b5 25 df 7b 37 9f e0 e2 4f b8 67 83 a3 2f cd 5d 41 42 4c 91 1076 74 ef 2c ... 78 more bytes> 1077*/ 1078``` 1079 1080See the OpenSSL [`SSL_export_keying_material`][] documentation for more 1081information. 1082 1083### `tlsSocket.getCertificate()` 1084 1085<!-- YAML 1086added: v11.2.0 1087--> 1088 1089* Returns: {Object} 1090 1091Returns an object representing the local certificate. The returned object has 1092some properties corresponding to the fields of the certificate. 1093 1094See [`tls.TLSSocket.getPeerCertificate()`][] for an example of the certificate 1095structure. 1096 1097If there is no local certificate, an empty object will be returned. If the 1098socket has been destroyed, `null` will be returned. 1099 1100### `tlsSocket.getCipher()` 1101 1102<!-- YAML 1103added: v0.11.4 1104changes: 1105 - version: 1106 - v13.4.0 1107 - v12.16.0 1108 pr-url: https://github.com/nodejs/node/pull/30637 1109 description: Return the IETF cipher name as `standardName`. 1110 - version: v12.0.0 1111 pr-url: https://github.com/nodejs/node/pull/26625 1112 description: Return the minimum cipher version, instead of a fixed string 1113 (`'TLSv1/SSLv3'`). 1114--> 1115 1116* Returns: {Object} 1117 * `name` {string} OpenSSL name for the cipher suite. 1118 * `standardName` {string} IETF name for the cipher suite. 1119 * `version` {string} The minimum TLS protocol version supported by this cipher 1120 suite. For the actual negotiated protocol, see [`tls.TLSSocket.getProtocol()`][]. 1121 1122Returns an object containing information on the negotiated cipher suite. 1123 1124For example, a TLSv1.2 protocol with AES256-SHA cipher: 1125 1126```json 1127{ 1128 "name": "AES256-SHA", 1129 "standardName": "TLS_RSA_WITH_AES_256_CBC_SHA", 1130 "version": "SSLv3" 1131} 1132``` 1133 1134See 1135[SSL\_CIPHER\_get\_name](https://www.openssl.org/docs/man1.1.1/man3/SSL_CIPHER_get_name.html) 1136for more information. 1137 1138### `tlsSocket.getEphemeralKeyInfo()` 1139 1140<!-- YAML 1141added: v5.0.0 1142--> 1143 1144* Returns: {Object} 1145 1146Returns an object representing the type, name, and size of parameter of 1147an ephemeral key exchange in [perfect forward secrecy][] on a client 1148connection. It returns an empty object when the key exchange is not 1149ephemeral. As this is only supported on a client socket; `null` is returned 1150if called on a server socket. The supported types are `'DH'` and `'ECDH'`. The 1151`name` property is available only when type is `'ECDH'`. 1152 1153For example: `{ type: 'ECDH', name: 'prime256v1', size: 256 }`. 1154 1155### `tlsSocket.getFinished()` 1156 1157<!-- YAML 1158added: v9.9.0 1159--> 1160 1161* Returns: {Buffer|undefined} The latest `Finished` message that has been 1162 sent to the socket as part of a SSL/TLS handshake, or `undefined` if 1163 no `Finished` message has been sent yet. 1164 1165As the `Finished` messages are message digests of the complete handshake 1166(with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can 1167be used for external authentication procedures when the authentication 1168provided by SSL/TLS is not desired or is not enough. 1169 1170Corresponds to the `SSL_get_finished` routine in OpenSSL and may be used 1171to implement the `tls-unique` channel binding from [RFC 5929][]. 1172 1173### `tlsSocket.getPeerCertificate([detailed])` 1174 1175<!-- YAML 1176added: v0.11.4 1177--> 1178 1179* `detailed` {boolean} Include the full certificate chain if `true`, otherwise 1180 include just the peer's certificate. 1181* Returns: {Object} A certificate object. 1182 1183Returns an object representing the peer's certificate. If the peer does not 1184provide a certificate, an empty object will be returned. If the socket has been 1185destroyed, `null` will be returned. 1186 1187If the full certificate chain was requested, each certificate will include an 1188`issuerCertificate` property containing an object representing its issuer's 1189certificate. 1190 1191#### Certificate object 1192 1193<!-- YAML 1194changes: 1195 - version: v18.13.0 1196 pr-url: https://github.com/nodejs/node/pull/44935 1197 description: Add "ca" property. 1198 - version: 1199 - v17.2.0 1200 - v16.14.0 1201 pr-url: https://github.com/nodejs/node/pull/39809 1202 description: Add fingerprint512. 1203 - version: v11.4.0 1204 pr-url: https://github.com/nodejs/node/pull/24358 1205 description: Support Elliptic Curve public key info. 1206--> 1207 1208A certificate object has properties corresponding to the fields of the 1209certificate. 1210 1211* `ca` {boolean} `true` if a Certificate Authority (CA), `false` otherwise. 1212* `raw` {Buffer} The DER encoded X.509 certificate data. 1213* `subject` {Object} The certificate subject, described in terms of 1214 Country (`C`), StateOrProvince (`ST`), Locality (`L`), Organization (`O`), 1215 OrganizationalUnit (`OU`), and CommonName (`CN`). The CommonName is typically 1216 a DNS name with TLS certificates. Example: 1217 `{C: 'UK', ST: 'BC', L: 'Metro', O: 'Node Fans', OU: 'Docs', CN: 'example.com'}`. 1218* `issuer` {Object} The certificate issuer, described in the same terms as the 1219 `subject`. 1220* `valid_from` {string} The date-time the certificate is valid from. 1221* `valid_to` {string} The date-time the certificate is valid to. 1222* `serialNumber` {string} The certificate serial number, as a hex string. 1223 Example: `'B9B0D332A1AA5635'`. 1224* `fingerprint` {string} The SHA-1 digest of the DER encoded certificate. It is 1225 returned as a `:` separated hexadecimal string. Example: `'2A:7A:C2:DD:...'`. 1226* `fingerprint256` {string} The SHA-256 digest of the DER encoded certificate. 1227 It is returned as a `:` separated hexadecimal string. Example: 1228 `'2A:7A:C2:DD:...'`. 1229* `fingerprint512` {string} The SHA-512 digest of the DER encoded certificate. 1230 It is returned as a `:` separated hexadecimal string. Example: 1231 `'2A:7A:C2:DD:...'`. 1232* `ext_key_usage` {Array} (Optional) The extended key usage, a set of OIDs. 1233* `subjectaltname` {string} (Optional) A string containing concatenated names 1234 for the subject, an alternative to the `subject` names. 1235* `infoAccess` {Array} (Optional) An array describing the AuthorityInfoAccess, 1236 used with OCSP. 1237* `issuerCertificate` {Object} (Optional) The issuer certificate object. For 1238 self-signed certificates, this may be a circular reference. 1239 1240The certificate may contain information about the public key, depending on 1241the key type. 1242 1243For RSA keys, the following properties may be defined: 1244 1245* `bits` {number} The RSA bit size. Example: `1024`. 1246* `exponent` {string} The RSA exponent, as a string in hexadecimal number 1247 notation. Example: `'0x010001'`. 1248* `modulus` {string} The RSA modulus, as a hexadecimal string. Example: 1249 `'B56CE45CB7...'`. 1250* `pubkey` {Buffer} The public key. 1251 1252For EC keys, the following properties may be defined: 1253 1254* `pubkey` {Buffer} The public key. 1255* `bits` {number} The key size in bits. Example: `256`. 1256* `asn1Curve` {string} (Optional) The ASN.1 name of the OID of the elliptic 1257 curve. Well-known curves are identified by an OID. While it is unusual, it is 1258 possible that the curve is identified by its mathematical properties, in which 1259 case it will not have an OID. Example: `'prime256v1'`. 1260* `nistCurve` {string} (Optional) The NIST name for the elliptic curve, if it 1261 has one (not all well-known curves have been assigned names by NIST). Example: 1262 `'P-256'`. 1263 1264Example certificate: 1265 1266<!-- eslint-skip --> 1267 1268```js 1269{ subject: 1270 { OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ], 1271 CN: '*.nodejs.org' }, 1272 issuer: 1273 { C: 'GB', 1274 ST: 'Greater Manchester', 1275 L: 'Salford', 1276 O: 'COMODO CA Limited', 1277 CN: 'COMODO RSA Domain Validation Secure Server CA' }, 1278 subjectaltname: 'DNS:*.nodejs.org, DNS:nodejs.org', 1279 infoAccess: 1280 { 'CA Issuers - URI': 1281 [ 'http://crt.comodoca.com/COMODORSADomainValidationSecureServerCA.crt' ], 1282 'OCSP - URI': [ 'http://ocsp.comodoca.com' ] }, 1283 modulus: 'B56CE45CB740B09A13F64AC543B712FF9EE8E4C284B542A1708A27E82A8D151CA178153E12E6DDA15BF70FFD96CB8A88618641BDFCCA03527E665B70D779C8A349A6F88FD4EF6557180BD4C98192872BCFE3AF56E863C09DDD8BC1EC58DF9D94F914F0369102B2870BECFA1348A0838C9C49BD1C20124B442477572347047506B1FCD658A80D0C44BCC16BC5C5496CFE6E4A8428EF654CD3D8972BF6E5BFAD59C93006830B5EB1056BBB38B53D1464FA6E02BFDF2FF66CD949486F0775EC43034EC2602AEFBF1703AD221DAA2A88353C3B6A688EFE8387811F645CEED7B3FE46E1F8B9F59FAD028F349B9BC14211D5830994D055EEA3D547911E07A0ADDEB8A82B9188E58720D95CD478EEC9AF1F17BE8141BE80906F1A339445A7EB5B285F68039B0F294598A7D1C0005FC22B5271B0752F58CCDEF8C8FD856FB7AE21C80B8A2CE983AE94046E53EDE4CB89F42502D31B5360771C01C80155918637490550E3F555E2EE75CC8C636DDE3633CFEDD62E91BF0F7688273694EEEBA20C2FC9F14A2A435517BC1D7373922463409AB603295CEB0BB53787A334C9CA3CA8B30005C5A62FC0715083462E00719A8FA3ED0A9828C3871360A73F8B04A4FC1E71302844E9BB9940B77E745C9D91F226D71AFCAD4B113AAF68D92B24DDB4A2136B55A1CD1ADF39605B63CB639038ED0F4C987689866743A68769CC55847E4A06D6E2E3F1', 1284 exponent: '0x10001', 1285 pubkey: <Buffer ... >, 1286 valid_from: 'Aug 14 00:00:00 2017 GMT', 1287 valid_to: 'Nov 20 23:59:59 2019 GMT', 1288 fingerprint: '01:02:59:D9:C3:D2:0D:08:F7:82:4E:44:A4:B4:53:C5:E2:3A:87:4D', 1289 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', 1290 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', 1291 ext_key_usage: [ '1.3.6.1.5.5.7.3.1', '1.3.6.1.5.5.7.3.2' ], 1292 serialNumber: '66593D57F20CBC573E433381B5FEC280', 1293 raw: <Buffer ... > } 1294``` 1295 1296### `tlsSocket.getPeerFinished()` 1297 1298<!-- YAML 1299added: v9.9.0 1300--> 1301 1302* Returns: {Buffer|undefined} The latest `Finished` message that is expected 1303 or has actually been received from the socket as part of a SSL/TLS handshake, 1304 or `undefined` if there is no `Finished` message so far. 1305 1306As the `Finished` messages are message digests of the complete handshake 1307(with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can 1308be used for external authentication procedures when the authentication 1309provided by SSL/TLS is not desired or is not enough. 1310 1311Corresponds to the `SSL_get_peer_finished` routine in OpenSSL and may be used 1312to implement the `tls-unique` channel binding from [RFC 5929][]. 1313 1314### `tlsSocket.getPeerX509Certificate()` 1315 1316<!-- YAML 1317added: v15.9.0 1318--> 1319 1320* Returns: {X509Certificate} 1321 1322Returns the peer certificate as an {X509Certificate} object. 1323 1324If there is no peer certificate, or the socket has been destroyed, 1325`undefined` will be returned. 1326 1327### `tlsSocket.getProtocol()` 1328 1329<!-- YAML 1330added: v5.7.0 1331--> 1332 1333* Returns: {string|null} 1334 1335Returns a string containing the negotiated SSL/TLS protocol version of the 1336current connection. The value `'unknown'` will be returned for connected 1337sockets that have not completed the handshaking process. The value `null` will 1338be returned for server sockets or disconnected client sockets. 1339 1340Protocol versions are: 1341 1342* `'SSLv3'` 1343* `'TLSv1'` 1344* `'TLSv1.1'` 1345* `'TLSv1.2'` 1346* `'TLSv1.3'` 1347 1348See the OpenSSL [`SSL_get_version`][] documentation for more information. 1349 1350### `tlsSocket.getSession()` 1351 1352<!-- YAML 1353added: v0.11.4 1354--> 1355 1356* {Buffer} 1357 1358Returns the TLS session data or `undefined` if no session was 1359negotiated. On the client, the data can be provided to the `session` option of 1360[`tls.connect()`][] to resume the connection. On the server, it may be useful 1361for debugging. 1362 1363See [Session Resumption][] for more information. 1364 1365Note: `getSession()` works only for TLSv1.2 and below. For TLSv1.3, applications 1366must use the [`'session'`][] event (it also works for TLSv1.2 and below). 1367 1368### `tlsSocket.getSharedSigalgs()` 1369 1370<!-- YAML 1371added: v12.11.0 1372--> 1373 1374* Returns: {Array} List of signature algorithms shared between the server and 1375 the client in the order of decreasing preference. 1376 1377See 1378[SSL\_get\_shared\_sigalgs](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html) 1379for more information. 1380 1381### `tlsSocket.getTLSTicket()` 1382 1383<!-- YAML 1384added: v0.11.4 1385--> 1386 1387* {Buffer} 1388 1389For a client, returns the TLS session ticket if one is available, or 1390`undefined`. For a server, always returns `undefined`. 1391 1392It may be useful for debugging. 1393 1394See [Session Resumption][] for more information. 1395 1396### `tlsSocket.getX509Certificate()` 1397 1398<!-- YAML 1399added: v15.9.0 1400--> 1401 1402* Returns: {X509Certificate} 1403 1404Returns the local certificate as an {X509Certificate} object. 1405 1406If there is no local certificate, or the socket has been destroyed, 1407`undefined` will be returned. 1408 1409### `tlsSocket.isSessionReused()` 1410 1411<!-- YAML 1412added: v0.5.6 1413--> 1414 1415* Returns: {boolean} `true` if the session was reused, `false` otherwise. 1416 1417See [Session Resumption][] for more information. 1418 1419### `tlsSocket.localAddress` 1420 1421<!-- YAML 1422added: v0.11.4 1423--> 1424 1425* {string} 1426 1427Returns the string representation of the local IP address. 1428 1429### `tlsSocket.localPort` 1430 1431<!-- YAML 1432added: v0.11.4 1433--> 1434 1435* {integer} 1436 1437Returns the numeric representation of the local port. 1438 1439### `tlsSocket.remoteAddress` 1440 1441<!-- YAML 1442added: v0.11.4 1443--> 1444 1445* {string} 1446 1447Returns the string representation of the remote IP address. For example, 1448`'74.125.127.100'` or `'2001:4860:a005::68'`. 1449 1450### `tlsSocket.remoteFamily` 1451 1452<!-- YAML 1453added: v0.11.4 1454--> 1455 1456* {string} 1457 1458Returns the string representation of the remote IP family. `'IPv4'` or `'IPv6'`. 1459 1460### `tlsSocket.remotePort` 1461 1462<!-- YAML 1463added: v0.11.4 1464--> 1465 1466* {integer} 1467 1468Returns the numeric representation of the remote port. For example, `443`. 1469 1470### `tlsSocket.renegotiate(options, callback)` 1471 1472<!-- YAML 1473added: v0.11.8 1474changes: 1475 - version: v18.0.0 1476 pr-url: https://github.com/nodejs/node/pull/41678 1477 description: Passing an invalid callback to the `callback` argument 1478 now throws `ERR_INVALID_ARG_TYPE` instead of 1479 `ERR_INVALID_CALLBACK`. 1480--> 1481 1482* `options` {Object} 1483 * `rejectUnauthorized` {boolean} If not `false`, the server certificate is 1484 verified against the list of supplied CAs. An `'error'` event is emitted if 1485 verification fails; `err.code` contains the OpenSSL error code. **Default:** 1486 `true`. 1487 * `requestCert` 1488 1489* `callback` {Function} If `renegotiate()` returned `true`, callback is 1490 attached once to the `'secure'` event. If `renegotiate()` returned `false`, 1491 `callback` will be called in the next tick with an error, unless the 1492 `tlsSocket` has been destroyed, in which case `callback` will not be called 1493 at all. 1494 1495* Returns: {boolean} `true` if renegotiation was initiated, `false` otherwise. 1496 1497The `tlsSocket.renegotiate()` method initiates a TLS renegotiation process. 1498Upon completion, the `callback` function will be passed a single argument 1499that is either an `Error` (if the request failed) or `null`. 1500 1501This method can be used to request a peer's certificate after the secure 1502connection has been established. 1503 1504When running as the server, the socket will be destroyed with an error after 1505`handshakeTimeout` timeout. 1506 1507For TLSv1.3, renegotiation cannot be initiated, it is not supported by the 1508protocol. 1509 1510### `tlsSocket.setMaxSendFragment(size)` 1511 1512<!-- YAML 1513added: v0.11.11 1514--> 1515 1516* `size` {number} The maximum TLS fragment size. The maximum value is `16384`. 1517 **Default:** `16384`. 1518* Returns: {boolean} 1519 1520The `tlsSocket.setMaxSendFragment()` method sets the maximum TLS fragment size. 1521Returns `true` if setting the limit succeeded; `false` otherwise. 1522 1523Smaller fragment sizes decrease the buffering latency on the client: larger 1524fragments are buffered by the TLS layer until the entire fragment is received 1525and its integrity is verified; large fragments can span multiple roundtrips 1526and their processing can be delayed due to packet loss or reordering. However, 1527smaller fragments add extra TLS framing bytes and CPU overhead, which may 1528decrease overall server throughput. 1529 1530## `tls.checkServerIdentity(hostname, cert)` 1531 1532<!-- YAML 1533added: v0.8.4 1534changes: 1535 - version: 1536 - v17.3.1 1537 - v16.13.2 1538 - v14.18.3 1539 - v12.22.9 1540 pr-url: https://github.com/nodejs-private/node-private/pull/300 1541 description: Support for `uniformResourceIdentifier` subject alternative 1542 names has been disabled in response to CVE-2021-44531. 1543--> 1544 1545* `hostname` {string} The host name or IP address to verify the certificate 1546 against. 1547* `cert` {Object} A [certificate object][] representing the peer's certificate. 1548* Returns: {Error|undefined} 1549 1550Verifies the certificate `cert` is issued to `hostname`. 1551 1552Returns {Error} object, populating it with `reason`, `host`, and `cert` on 1553failure. On success, returns {undefined}. 1554 1555This function is intended to be used in combination with the 1556`checkServerIdentity` option that can be passed to [`tls.connect()`][] and as 1557such operates on a [certificate object][]. For other purposes, consider using 1558[`x509.checkHost()`][] instead. 1559 1560This function can be overwritten by providing an alternative function as the 1561`options.checkServerIdentity` option that is passed to `tls.connect()`. The 1562overwriting function can call `tls.checkServerIdentity()` of course, to augment 1563the checks done with additional verification. 1564 1565This function is only called if the certificate passed all other checks, such as 1566being issued by trusted CA (`options.ca`). 1567 1568Earlier versions of Node.js incorrectly accepted certificates for a given 1569`hostname` if a matching `uniformResourceIdentifier` subject alternative name 1570was present (see [CVE-2021-44531][]). Applications that wish to accept 1571`uniformResourceIdentifier` subject alternative names can use a custom 1572`options.checkServerIdentity` function that implements the desired behavior. 1573 1574## `tls.connect(options[, callback])` 1575 1576<!-- YAML 1577added: v0.11.3 1578changes: 1579 - version: 1580 - v15.1.0 1581 - v14.18.0 1582 pr-url: https://github.com/nodejs/node/pull/35753 1583 description: Added `onread` option. 1584 - version: 1585 - v14.1.0 1586 - v13.14.0 1587 pr-url: https://github.com/nodejs/node/pull/32786 1588 description: The `highWaterMark` option is accepted now. 1589 - version: 1590 - v13.6.0 1591 - v12.16.0 1592 pr-url: https://github.com/nodejs/node/pull/23188 1593 description: The `pskCallback` option is now supported. 1594 - version: v12.9.0 1595 pr-url: https://github.com/nodejs/node/pull/27836 1596 description: Support the `allowHalfOpen` option. 1597 - version: v12.4.0 1598 pr-url: https://github.com/nodejs/node/pull/27816 1599 description: The `hints` option is now supported. 1600 - version: v12.2.0 1601 pr-url: https://github.com/nodejs/node/pull/27497 1602 description: The `enableTrace` option is now supported. 1603 - version: 1604 - v11.8.0 1605 - v10.16.0 1606 pr-url: https://github.com/nodejs/node/pull/25517 1607 description: The `timeout` option is supported now. 1608 - version: v8.0.0 1609 pr-url: https://github.com/nodejs/node/pull/12839 1610 description: The `lookup` option is supported now. 1611 - version: v8.0.0 1612 pr-url: https://github.com/nodejs/node/pull/11984 1613 description: The `ALPNProtocols` option can be a `TypedArray` or 1614 `DataView` now. 1615 - version: 1616 - v5.3.0 1617 - v4.7.0 1618 pr-url: https://github.com/nodejs/node/pull/4246 1619 description: The `secureContext` option is supported now. 1620 - version: v5.0.0 1621 pr-url: https://github.com/nodejs/node/pull/2564 1622 description: ALPN options are supported now. 1623--> 1624 1625* `options` {Object} 1626 * `enableTrace`: See [`tls.createServer()`][] 1627 * `host` {string} Host the client should connect to. **Default:** 1628 `'localhost'`. 1629 * `port` {number} Port the client should connect to. 1630 * `path` {string} Creates Unix socket connection to path. If this option is 1631 specified, `host` and `port` are ignored. 1632 * `socket` {stream.Duplex} Establish secure connection on a given socket 1633 rather than creating a new socket. Typically, this is an instance of 1634 [`net.Socket`][], but any `Duplex` stream is allowed. 1635 If this option is specified, `path`, `host`, and `port` are ignored, 1636 except for certificate validation. Usually, a socket is already connected 1637 when passed to `tls.connect()`, but it can be connected later. 1638 Connection/disconnection/destruction of `socket` is the user's 1639 responsibility; calling `tls.connect()` will not cause `net.connect()` to be 1640 called. 1641 * `allowHalfOpen` {boolean} If set to `false`, then the socket will 1642 automatically end the writable side when the readable side ends. If the 1643 `socket` option is set, this option has no effect. See the `allowHalfOpen` 1644 option of [`net.Socket`][] for details. **Default:** `false`. 1645 * `rejectUnauthorized` {boolean} If not `false`, the server certificate is 1646 verified against the list of supplied CAs. An `'error'` event is emitted if 1647 verification fails; `err.code` contains the OpenSSL error code. **Default:** 1648 `true`. 1649 * `pskCallback` {Function} 1650 1651 * hint: {string} optional message sent from the server to help client 1652 decide which identity to use during negotiation. 1653 Always `null` if TLS 1.3 is used. 1654 * Returns: {Object} in the form 1655 `{ psk: <Buffer|TypedArray|DataView>, identity: <string> }` 1656 or `null` to stop the negotiation process. `psk` must be 1657 compatible with the selected cipher's digest. 1658 `identity` must use UTF-8 encoding. 1659 1660 When negotiating TLS-PSK (pre-shared keys), this function is called 1661 with optional identity `hint` provided by the server or `null` 1662 in case of TLS 1.3 where `hint` was removed. 1663 It will be necessary to provide a custom `tls.checkServerIdentity()` 1664 for the connection as the default one will try to check host name/IP 1665 of the server against the certificate but that's not applicable for PSK 1666 because there won't be a certificate present. 1667 More information can be found in the [RFC 4279][]. 1668 * `ALPNProtocols`: {string\[]|Buffer\[]|TypedArray\[]|DataView\[]|Buffer| 1669 TypedArray|DataView} 1670 An array of strings, `Buffer`s, `TypedArray`s, or `DataView`s, or a 1671 single `Buffer`, `TypedArray`, or `DataView` containing the supported ALPN 1672 protocols. `Buffer`s should have the format `[len][name][len][name]...` 1673 e.g. `'\x08http/1.1\x08http/1.0'`, where the `len` byte is the length of the 1674 next protocol name. Passing an array is usually much simpler, e.g. 1675 `['http/1.1', 'http/1.0']`. Protocols earlier in the list have higher 1676 preference than those later. 1677 * `servername`: {string} Server name for the SNI (Server Name Indication) TLS 1678 extension. It is the name of the host being connected to, and must be a host 1679 name, and not an IP address. It can be used by a multi-homed server to 1680 choose the correct certificate to present to the client, see the 1681 `SNICallback` option to [`tls.createServer()`][]. 1682 * `checkServerIdentity(servername, cert)` {Function} A callback function 1683 to be used (instead of the builtin `tls.checkServerIdentity()` function) 1684 when checking the server's host name (or the provided `servername` when 1685 explicitly set) against the certificate. This should return an {Error} if 1686 verification fails. The method should return `undefined` if the `servername` 1687 and `cert` are verified. 1688 * `session` {Buffer} A `Buffer` instance, containing TLS session. 1689 * `minDHSize` {number} Minimum size of the DH parameter in bits to accept a 1690 TLS connection. When a server offers a DH parameter with a size less 1691 than `minDHSize`, the TLS connection is destroyed and an error is thrown. 1692 **Default:** `1024`. 1693 * `highWaterMark`: {number} Consistent with the readable stream `highWaterMark` parameter. 1694 **Default:** `16 * 1024`. 1695 * `secureContext`: TLS context object created with 1696 [`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one 1697 will be created by passing the entire `options` object to 1698 `tls.createSecureContext()`. 1699 * `onread` {Object} If the `socket` option is missing, incoming data is 1700 stored in a single `buffer` and passed to the supplied `callback` when 1701 data arrives on the socket, otherwise the option is ignored. See the 1702 `onread` option of [`net.Socket`][] for details. 1703 * ...: [`tls.createSecureContext()`][] options that are used if the 1704 `secureContext` option is missing, otherwise they are ignored. 1705 * ...: Any [`socket.connect()`][] option not already listed. 1706* `callback` {Function} 1707* Returns: {tls.TLSSocket} 1708 1709The `callback` function, if specified, will be added as a listener for the 1710[`'secureConnect'`][] event. 1711 1712`tls.connect()` returns a [`tls.TLSSocket`][] object. 1713 1714Unlike the `https` API, `tls.connect()` does not enable the 1715SNI (Server Name Indication) extension by default, which may cause some 1716servers to return an incorrect certificate or reject the connection 1717altogether. To enable SNI, set the `servername` option in addition 1718to `host`. 1719 1720The following illustrates a client for the echo server example from 1721[`tls.createServer()`][]: 1722 1723```js 1724// Assumes an echo server that is listening on port 8000. 1725const tls = require('node:tls'); 1726const fs = require('node:fs'); 1727 1728const options = { 1729 // Necessary only if the server requires client certificate authentication. 1730 key: fs.readFileSync('client-key.pem'), 1731 cert: fs.readFileSync('client-cert.pem'), 1732 1733 // Necessary only if the server uses a self-signed certificate. 1734 ca: [ fs.readFileSync('server-cert.pem') ], 1735 1736 // Necessary only if the server's cert isn't for "localhost". 1737 checkServerIdentity: () => { return null; }, 1738}; 1739 1740const socket = tls.connect(8000, options, () => { 1741 console.log('client connected', 1742 socket.authorized ? 'authorized' : 'unauthorized'); 1743 process.stdin.pipe(socket); 1744 process.stdin.resume(); 1745}); 1746socket.setEncoding('utf8'); 1747socket.on('data', (data) => { 1748 console.log(data); 1749}); 1750socket.on('end', () => { 1751 console.log('server ends connection'); 1752}); 1753``` 1754 1755## `tls.connect(path[, options][, callback])` 1756 1757<!-- YAML 1758added: v0.11.3 1759--> 1760 1761* `path` {string} Default value for `options.path`. 1762* `options` {Object} See [`tls.connect()`][]. 1763* `callback` {Function} See [`tls.connect()`][]. 1764* Returns: {tls.TLSSocket} 1765 1766Same as [`tls.connect()`][] except that `path` can be provided 1767as an argument instead of an option. 1768 1769A path option, if specified, will take precedence over the path argument. 1770 1771## `tls.connect(port[, host][, options][, callback])` 1772 1773<!-- YAML 1774added: v0.11.3 1775--> 1776 1777* `port` {number} Default value for `options.port`. 1778* `host` {string} Default value for `options.host`. 1779* `options` {Object} See [`tls.connect()`][]. 1780* `callback` {Function} See [`tls.connect()`][]. 1781* Returns: {tls.TLSSocket} 1782 1783Same as [`tls.connect()`][] except that `port` and `host` can be provided 1784as arguments instead of options. 1785 1786A port or host option, if specified, will take precedence over any port or host 1787argument. 1788 1789## `tls.createSecureContext([options])` 1790 1791<!-- YAML 1792added: v0.11.13 1793changes: 1794 - version: v18.16.0 1795 pr-url: https://github.com/nodejs/node/pull/46978 1796 description: The `dhparam` option can now be set to `'auto'` to 1797 enable DHE with appropriate well-known parameters. 1798 - version: v12.12.0 1799 pr-url: https://github.com/nodejs/node/pull/28973 1800 description: Added `privateKeyIdentifier` and `privateKeyEngine` options 1801 to get private key from an OpenSSL engine. 1802 - version: v12.11.0 1803 pr-url: https://github.com/nodejs/node/pull/29598 1804 description: Added `sigalgs` option to override supported signature 1805 algorithms. 1806 - version: v12.0.0 1807 pr-url: https://github.com/nodejs/node/pull/26209 1808 description: TLSv1.3 support added. 1809 - version: v11.5.0 1810 pr-url: https://github.com/nodejs/node/pull/24733 1811 description: The `ca:` option now supports `BEGIN TRUSTED CERTIFICATE`. 1812 - version: 1813 - v11.4.0 1814 - v10.16.0 1815 pr-url: https://github.com/nodejs/node/pull/24405 1816 description: The `minVersion` and `maxVersion` can be used to restrict 1817 the allowed TLS protocol versions. 1818 - version: v10.0.0 1819 pr-url: https://github.com/nodejs/node/pull/19794 1820 description: The `ecdhCurve` cannot be set to `false` anymore due to a 1821 change in OpenSSL. 1822 - version: v9.3.0 1823 pr-url: https://github.com/nodejs/node/pull/14903 1824 description: The `options` parameter can now include `clientCertEngine`. 1825 - version: v9.0.0 1826 pr-url: https://github.com/nodejs/node/pull/15206 1827 description: The `ecdhCurve` option can now be multiple `':'` separated 1828 curve names or `'auto'`. 1829 - version: v7.3.0 1830 pr-url: https://github.com/nodejs/node/pull/10294 1831 description: If the `key` option is an array, individual entries do not 1832 need a `passphrase` property anymore. `Array` entries can also 1833 just be `string`s or `Buffer`s now. 1834 - version: v5.2.0 1835 pr-url: https://github.com/nodejs/node/pull/4099 1836 description: The `ca` option can now be a single string containing multiple 1837 CA certificates. 1838--> 1839 1840* `options` {Object} 1841 * `ca` {string|string\[]|Buffer|Buffer\[]} Optionally override the trusted CA 1842 certificates. Default is to trust the well-known CAs curated by Mozilla. 1843 Mozilla's CAs are completely replaced when CAs are explicitly specified 1844 using this option. The value can be a string or `Buffer`, or an `Array` of 1845 strings and/or `Buffer`s. Any string or `Buffer` can contain multiple PEM 1846 CAs concatenated together. The peer's certificate must be chainable to a CA 1847 trusted by the server for the connection to be authenticated. When using 1848 certificates that are not chainable to a well-known CA, the certificate's CA 1849 must be explicitly specified as a trusted or the connection will fail to 1850 authenticate. 1851 If the peer uses a certificate that doesn't match or chain to one of the 1852 default CAs, use the `ca` option to provide a CA certificate that the peer's 1853 certificate can match or chain to. 1854 For self-signed certificates, the certificate is its own CA, and must be 1855 provided. 1856 For PEM encoded certificates, supported types are "TRUSTED CERTIFICATE", 1857 "X509 CERTIFICATE", and "CERTIFICATE". 1858 See also [`tls.rootCertificates`][]. 1859 * `cert` {string|string\[]|Buffer|Buffer\[]} Cert chains in PEM format. One 1860 cert chain should be provided per private key. Each cert chain should 1861 consist of the PEM formatted certificate for a provided private `key`, 1862 followed by the PEM formatted intermediate certificates (if any), in order, 1863 and not including the root CA (the root CA must be pre-known to the peer, 1864 see `ca`). When providing multiple cert chains, they do not have to be in 1865 the same order as their private keys in `key`. If the intermediate 1866 certificates are not provided, the peer will not be able to validate the 1867 certificate, and the handshake will fail. 1868 * `sigalgs` {string} Colon-separated list of supported signature algorithms. 1869 The list can contain digest algorithms (`SHA256`, `MD5` etc.), public key 1870 algorithms (`RSA-PSS`, `ECDSA` etc.), combination of both (e.g 1871 'RSA+SHA384') or TLS v1.3 scheme names (e.g. `rsa_pss_pss_sha512`). 1872 See [OpenSSL man pages](https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set1_sigalgs_list.html) 1873 for more info. 1874 * `ciphers` {string} Cipher suite specification, replacing the default. For 1875 more information, see [Modifying the default TLS cipher suite][]. Permitted 1876 ciphers can be obtained via [`tls.getCiphers()`][]. Cipher names must be 1877 uppercased in order for OpenSSL to accept them. 1878 * `clientCertEngine` {string} Name of an OpenSSL engine which can provide the 1879 client certificate. 1880 * `crl` {string|string\[]|Buffer|Buffer\[]} PEM formatted CRLs (Certificate 1881 Revocation Lists). 1882 * `dhparam` {string|Buffer} `'auto'` or custom Diffie-Hellman parameters, 1883 required for non-ECDHE [perfect forward secrecy][]. If omitted or invalid, 1884 the parameters are silently discarded and DHE ciphers will not be available. 1885 [ECDHE][]-based [perfect forward secrecy][] will still be available. 1886 * `ecdhCurve` {string} A string describing a named curve or a colon separated 1887 list of curve NIDs or names, for example `P-521:P-384:P-256`, to use for 1888 ECDH key agreement. Set to `auto` to select the 1889 curve automatically. Use [`crypto.getCurves()`][] to obtain a list of 1890 available curve names. On recent releases, `openssl ecparam -list_curves` 1891 will also display the name and description of each available elliptic curve. 1892 **Default:** [`tls.DEFAULT_ECDH_CURVE`][]. 1893 * `honorCipherOrder` {boolean} Attempt to use the server's cipher suite 1894 preferences instead of the client's. When `true`, causes 1895 `SSL_OP_CIPHER_SERVER_PREFERENCE` to be set in `secureOptions`, see 1896 [OpenSSL Options][] for more information. 1897 * `key` {string|string\[]|Buffer|Buffer\[]|Object\[]} Private keys in PEM 1898 format. PEM allows the option of private keys being encrypted. Encrypted 1899 keys will be decrypted with `options.passphrase`. Multiple keys using 1900 different algorithms can be provided either as an array of unencrypted key 1901 strings or buffers, or an array of objects in the form 1902 `{pem: <string|buffer>[, passphrase: <string>]}`. The object form can only 1903 occur in an array. `object.passphrase` is optional. Encrypted keys will be 1904 decrypted with `object.passphrase` if provided, or `options.passphrase` if 1905 it is not. 1906 * `privateKeyEngine` {string} Name of an OpenSSL engine to get private key 1907 from. Should be used together with `privateKeyIdentifier`. 1908 * `privateKeyIdentifier` {string} Identifier of a private key managed by 1909 an OpenSSL engine. Should be used together with `privateKeyEngine`. 1910 Should not be set together with `key`, because both options define a 1911 private key in different ways. 1912 * `maxVersion` {string} Optionally set the maximum TLS version to allow. One 1913 of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified 1914 along with the `secureProtocol` option; use one or the other. 1915 **Default:** [`tls.DEFAULT_MAX_VERSION`][]. 1916 * `minVersion` {string} Optionally set the minimum TLS version to allow. One 1917 of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified 1918 along with the `secureProtocol` option; use one or the other. Avoid 1919 setting to less than TLSv1.2, but it may be required for 1920 interoperability. 1921 **Default:** [`tls.DEFAULT_MIN_VERSION`][]. 1922 * `passphrase` {string} Shared passphrase used for a single private key and/or 1923 a PFX. 1924 * `pfx` {string|string\[]|Buffer|Buffer\[]|Object\[]} PFX or PKCS12 encoded 1925 private key and certificate chain. `pfx` is an alternative to providing 1926 `key` and `cert` individually. PFX is usually encrypted, if it is, 1927 `passphrase` will be used to decrypt it. Multiple PFX can be provided either 1928 as an array of unencrypted PFX buffers, or an array of objects in the form 1929 `{buf: <string|buffer>[, passphrase: <string>]}`. The object form can only 1930 occur in an array. `object.passphrase` is optional. Encrypted PFX will be 1931 decrypted with `object.passphrase` if provided, or `options.passphrase` if 1932 it is not. 1933 * `secureOptions` {number} Optionally affect the OpenSSL protocol behavior, 1934 which is not usually necessary. This should be used carefully if at all! 1935 Value is a numeric bitmask of the `SSL_OP_*` options from 1936 [OpenSSL Options][]. 1937 * `secureProtocol` {string} Legacy mechanism to select the TLS protocol 1938 version to use, it does not support independent control of the minimum and 1939 maximum version, and does not support limiting the protocol to TLSv1.3. Use 1940 `minVersion` and `maxVersion` instead. The possible values are listed as 1941 [SSL\_METHODS][SSL_METHODS], use the function names as strings. For example, 1942 use `'TLSv1_1_method'` to force TLS version 1.1, or `'TLS_method'` to allow 1943 any TLS protocol version up to TLSv1.3. It is not recommended to use TLS 1944 versions less than 1.2, but it may be required for interoperability. 1945 **Default:** none, see `minVersion`. 1946 * `sessionIdContext` {string} Opaque identifier used by servers to ensure 1947 session state is not shared between applications. Unused by clients. 1948 * `ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudorandom 1949 data. See [Session Resumption][] for more information. 1950 * `sessionTimeout` {number} The number of seconds after which a TLS session 1951 created by the server will no longer be resumable. See 1952 [Session Resumption][] for more information. **Default:** `300`. 1953 1954[`tls.createServer()`][] sets the default value of the `honorCipherOrder` option 1955to `true`, other APIs that create secure contexts leave it unset. 1956 1957[`tls.createServer()`][] uses a 128 bit truncated SHA1 hash value generated 1958from `process.argv` as the default value of the `sessionIdContext` option, other 1959APIs that create secure contexts have no default value. 1960 1961The `tls.createSecureContext()` method creates a `SecureContext` object. It is 1962usable as an argument to several `tls` APIs, such as [`server.addContext()`][], 1963but has no public methods. The [`tls.Server`][] constructor and the 1964[`tls.createServer()`][] method do not support the `secureContext` option. 1965 1966A key is _required_ for ciphers that use certificates. Either `key` or 1967`pfx` can be used to provide it. 1968 1969If the `ca` option is not given, then Node.js will default to using 1970[Mozilla's publicly trusted list of CAs][]. 1971 1972Custom DHE parameters are discouraged in favor of the new `dhparam: 'auto'` 1973option. When set to `'auto'`, well-known DHE parameters of sufficient strength 1974will be selected automatically. Otherwise, if necessary, `openssl dhparam` can 1975be used to create custom parameters. The key length must be greater than or 1976equal to 1024 bits or else an error will be thrown. Although 1024 bits is 1977permissible, use 2048 bits or larger for stronger security. 1978 1979## `tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])` 1980 1981<!-- YAML 1982added: v0.3.2 1983deprecated: v0.11.3 1984changes: 1985 - version: v5.0.0 1986 pr-url: https://github.com/nodejs/node/pull/2564 1987 description: ALPN options are supported now. 1988--> 1989 1990> Stability: 0 - Deprecated: Use [`tls.TLSSocket`][] instead. 1991 1992* `context` {Object} A secure context object as returned by 1993 `tls.createSecureContext()` 1994* `isServer` {boolean} `true` to specify that this TLS connection should be 1995 opened as a server. 1996* `requestCert` {boolean} `true` to specify whether a server should request a 1997 certificate from a connecting client. Only applies when `isServer` is `true`. 1998* `rejectUnauthorized` {boolean} If not `false` a server automatically reject 1999 clients with invalid certificates. Only applies when `isServer` is `true`. 2000* `options` 2001 * `enableTrace`: See [`tls.createServer()`][] 2002 * `secureContext`: A TLS context object from [`tls.createSecureContext()`][] 2003 * `isServer`: If `true` the TLS socket will be instantiated in server-mode. 2004 **Default:** `false`. 2005 * `server` {net.Server} A [`net.Server`][] instance 2006 * `requestCert`: See [`tls.createServer()`][] 2007 * `rejectUnauthorized`: See [`tls.createServer()`][] 2008 * `ALPNProtocols`: See [`tls.createServer()`][] 2009 * `SNICallback`: See [`tls.createServer()`][] 2010 * `session` {Buffer} A `Buffer` instance containing a TLS session. 2011 * `requestOCSP` {boolean} If `true`, specifies that the OCSP status request 2012 extension will be added to the client hello and an `'OCSPResponse'` event 2013 will be emitted on the socket before establishing a secure communication. 2014 2015Creates a new secure pair object with two streams, one of which reads and writes 2016the encrypted data and the other of which reads and writes the cleartext data. 2017Generally, the encrypted stream is piped to/from an incoming encrypted data 2018stream and the cleartext one is used as a replacement for the initial encrypted 2019stream. 2020 2021`tls.createSecurePair()` returns a `tls.SecurePair` object with `cleartext` and 2022`encrypted` stream properties. 2023 2024Using `cleartext` has the same API as [`tls.TLSSocket`][]. 2025 2026The `tls.createSecurePair()` method is now deprecated in favor of 2027`tls.TLSSocket()`. For example, the code: 2028 2029```js 2030pair = tls.createSecurePair(/* ... */); 2031pair.encrypted.pipe(socket); 2032socket.pipe(pair.encrypted); 2033``` 2034 2035can be replaced by: 2036 2037```js 2038secureSocket = tls.TLSSocket(socket, options); 2039``` 2040 2041where `secureSocket` has the same API as `pair.cleartext`. 2042 2043## `tls.createServer([options][, secureConnectionListener])` 2044 2045<!-- YAML 2046added: v0.3.2 2047changes: 2048 - version: v18.19.0 2049 pr-url: https://github.com/nodejs/node/pull/45190 2050 description: The `options` parameter can now include `ALPNCallback`. 2051 - version: v12.3.0 2052 pr-url: https://github.com/nodejs/node/pull/27665 2053 description: The `options` parameter now supports `net.createServer()` 2054 options. 2055 - version: v9.3.0 2056 pr-url: https://github.com/nodejs/node/pull/14903 2057 description: The `options` parameter can now include `clientCertEngine`. 2058 - version: v8.0.0 2059 pr-url: https://github.com/nodejs/node/pull/11984 2060 description: The `ALPNProtocols` option can be a `TypedArray` or 2061 `DataView` now. 2062 - version: v5.0.0 2063 pr-url: https://github.com/nodejs/node/pull/2564 2064 description: ALPN options are supported now. 2065--> 2066 2067* `options` {Object} 2068 * `ALPNProtocols`: {string\[]|Buffer\[]|TypedArray\[]|DataView\[]|Buffer| 2069 TypedArray|DataView} 2070 An array of strings, `Buffer`s, `TypedArray`s, or `DataView`s, or a single 2071 `Buffer`, `TypedArray`, or `DataView` containing the supported ALPN 2072 protocols. `Buffer`s should have the format `[len][name][len][name]...` 2073 e.g. `0x05hello0x05world`, where the first byte is the length of the next 2074 protocol name. Passing an array is usually much simpler, e.g. 2075 `['hello', 'world']`. (Protocols should be ordered by their priority.) 2076 * `ALPNCallback`: {Function} If set, this will be called when a 2077 client opens a connection using the ALPN extension. One argument will 2078 be passed to the callback: an object containing `servername` and 2079 `protocols` fields, respectively containing the server name from 2080 the SNI extension (if any) and an array of ALPN protocol name strings. The 2081 callback must return either one of the strings listed in 2082 `protocols`, which will be returned to the client as the selected 2083 ALPN protocol, or `undefined`, to reject the connection with a fatal alert. 2084 If a string is returned that does not match one of the client's ALPN 2085 protocols, an error will be thrown. This option cannot be used with the 2086 `ALPNProtocols` option, and setting both options will throw an error. 2087 * `clientCertEngine` {string} Name of an OpenSSL engine which can provide the 2088 client certificate. 2089 * `enableTrace` {boolean} If `true`, [`tls.TLSSocket.enableTrace()`][] will be 2090 called on new connections. Tracing can be enabled after the secure 2091 connection is established, but this option must be used to trace the secure 2092 connection setup. **Default:** `false`. 2093 * `handshakeTimeout` {number} Abort the connection if the SSL/TLS handshake 2094 does not finish in the specified number of milliseconds. 2095 A `'tlsClientError'` is emitted on the `tls.Server` object whenever 2096 a handshake times out. **Default:** `120000` (120 seconds). 2097 * `rejectUnauthorized` {boolean} If not `false` the server will reject any 2098 connection which is not authorized with the list of supplied CAs. This 2099 option only has an effect if `requestCert` is `true`. **Default:** `true`. 2100 * `requestCert` {boolean} If `true` the server will request a certificate from 2101 clients that connect and attempt to verify that certificate. **Default:** 2102 `false`. 2103 * `sessionTimeout` {number} The number of seconds after which a TLS session 2104 created by the server will no longer be resumable. See 2105 [Session Resumption][] for more information. **Default:** `300`. 2106 * `SNICallback(servername, callback)` {Function} A function that will be 2107 called if the client supports SNI TLS extension. Two arguments will be 2108 passed when called: `servername` and `callback`. `callback` is an 2109 error-first callback that takes two optional arguments: `error` and `ctx`. 2110 `ctx`, if provided, is a `SecureContext` instance. 2111 [`tls.createSecureContext()`][] can be used to get a proper `SecureContext`. 2112 If `callback` is called with a falsy `ctx` argument, the default secure 2113 context of the server will be used. If `SNICallback` wasn't provided the 2114 default callback with high-level API will be used (see below). 2115 * `ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudorandom 2116 data. See [Session Resumption][] for more information. 2117 * `pskCallback` {Function} 2118 2119 * socket: {tls.TLSSocket} the server [`tls.TLSSocket`][] instance for 2120 this connection. 2121 * identity: {string} identity parameter sent from the client. 2122 * Returns: {Buffer|TypedArray|DataView} pre-shared key that must either be 2123 a buffer or `null` to stop the negotiation process. Returned PSK must be 2124 compatible with the selected cipher's digest. 2125 2126 When negotiating TLS-PSK (pre-shared keys), this function is called 2127 with the identity provided by the client. 2128 If the return value is `null` the negotiation process will stop and an 2129 "unknown\_psk\_identity" alert message will be sent to the other party. 2130 If the server wishes to hide the fact that the PSK identity was not known, 2131 the callback must provide some random data as `psk` to make the connection 2132 fail with "decrypt\_error" before negotiation is finished. 2133 PSK ciphers are disabled by default, and using TLS-PSK thus 2134 requires explicitly specifying a cipher suite with the `ciphers` option. 2135 More information can be found in the [RFC 4279][]. 2136 * `pskIdentityHint` {string} optional hint to send to a client to help 2137 with selecting the identity during TLS-PSK negotiation. Will be ignored 2138 in TLS 1.3. Upon failing to set pskIdentityHint `'tlsClientError'` will be 2139 emitted with `'ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED'` code. 2140 * ...: Any [`tls.createSecureContext()`][] option can be provided. For 2141 servers, the identity options (`pfx`, `key`/`cert`, or `pskCallback`) 2142 are usually required. 2143 * ...: Any [`net.createServer()`][] option can be provided. 2144* `secureConnectionListener` {Function} 2145* Returns: {tls.Server} 2146 2147Creates a new [`tls.Server`][]. The `secureConnectionListener`, if provided, is 2148automatically set as a listener for the [`'secureConnection'`][] event. 2149 2150The `ticketKeys` options is automatically shared between `node:cluster` module 2151workers. 2152 2153The following illustrates a simple echo server: 2154 2155```js 2156const tls = require('node:tls'); 2157const fs = require('node:fs'); 2158 2159const options = { 2160 key: fs.readFileSync('server-key.pem'), 2161 cert: fs.readFileSync('server-cert.pem'), 2162 2163 // This is necessary only if using client certificate authentication. 2164 requestCert: true, 2165 2166 // This is necessary only if the client uses a self-signed certificate. 2167 ca: [ fs.readFileSync('client-cert.pem') ], 2168}; 2169 2170const server = tls.createServer(options, (socket) => { 2171 console.log('server connected', 2172 socket.authorized ? 'authorized' : 'unauthorized'); 2173 socket.write('welcome!\n'); 2174 socket.setEncoding('utf8'); 2175 socket.pipe(socket); 2176}); 2177server.listen(8000, () => { 2178 console.log('server bound'); 2179}); 2180``` 2181 2182The server can be tested by connecting to it using the example client from 2183[`tls.connect()`][]. 2184 2185## `tls.getCiphers()` 2186 2187<!-- YAML 2188added: v0.10.2 2189--> 2190 2191* Returns: {string\[]} 2192 2193Returns an array with the names of the supported TLS ciphers. The names are 2194lower-case for historical reasons, but must be uppercased to be used in 2195the `ciphers` option of [`tls.createSecureContext()`][]. 2196 2197Not all supported ciphers are enabled by default. See 2198[Modifying the default TLS cipher suite][]. 2199 2200Cipher names that start with `'tls_'` are for TLSv1.3, all the others are for 2201TLSv1.2 and below. 2202 2203```js 2204console.log(tls.getCiphers()); // ['aes128-gcm-sha256', 'aes128-sha', ...] 2205``` 2206 2207## `tls.rootCertificates` 2208 2209<!-- YAML 2210added: v12.3.0 2211--> 2212 2213* {string\[]} 2214 2215An immutable array of strings representing the root certificates (in PEM format) 2216from the bundled Mozilla CA store as supplied by the current Node.js version. 2217 2218The bundled CA store, as supplied by Node.js, is a snapshot of Mozilla CA store 2219that is fixed at release time. It is identical on all supported platforms. 2220 2221## `tls.DEFAULT_ECDH_CURVE` 2222 2223<!-- YAML 2224added: v0.11.13 2225changes: 2226 - version: v10.0.0 2227 pr-url: https://github.com/nodejs/node/pull/16853 2228 description: Default value changed to `'auto'`. 2229--> 2230 2231The default curve name to use for ECDH key agreement in a tls server. The 2232default value is `'auto'`. See [`tls.createSecureContext()`][] for further 2233information. 2234 2235## `tls.DEFAULT_MAX_VERSION` 2236 2237<!-- YAML 2238added: v11.4.0 2239--> 2240 2241* {string} The default value of the `maxVersion` option of 2242 [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS 2243 protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. 2244 **Default:** `'TLSv1.3'`, unless changed using CLI options. Using 2245 `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets 2246 the default to `'TLSv1.3'`. If multiple of the options are provided, the 2247 highest maximum is used. 2248 2249## `tls.DEFAULT_MIN_VERSION` 2250 2251<!-- YAML 2252added: v11.4.0 2253--> 2254 2255* {string} The default value of the `minVersion` option of 2256 [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS 2257 protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. 2258 **Default:** `'TLSv1.2'`, unless changed using CLI options. Using 2259 `--tls-min-v1.0` sets the default to `'TLSv1'`. Using `--tls-min-v1.1` sets 2260 the default to `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to 2261 `'TLSv1.3'`. If multiple of the options are provided, the lowest minimum is 2262 used. 2263 2264## `tls.DEFAULT_CIPHERS` 2265 2266<!-- YAML 2267added: v18.16.0 2268--> 2269 2270* {string} The default value of the `ciphers` option of 2271 [`tls.createSecureContext()`][]. It can be assigned any of the supported 2272 OpenSSL ciphers. Defaults to the content of 2273 `crypto.constants.defaultCoreCipherList`, unless changed using CLI options 2274 using `--tls-default-ciphers`. 2275 2276[CVE-2021-44531]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44531 2277[Chrome's 'modern cryptography' setting]: https://www.chromium.org/Home/chromium-security/education/tls#TOC-Cipher-Suites 2278[DHE]: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange 2279[ECDHE]: https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman 2280[Modifying the default TLS cipher suite]: #modifying-the-default-tls-cipher-suite 2281[Mozilla's publicly trusted list of CAs]: https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt 2282[OCSP request]: https://en.wikipedia.org/wiki/OCSP_stapling 2283[OpenSSL Options]: crypto.md#openssl-options 2284[RFC 2246]: https://www.ietf.org/rfc/rfc2246.txt 2285[RFC 4086]: https://tools.ietf.org/html/rfc4086 2286[RFC 4279]: https://tools.ietf.org/html/rfc4279 2287[RFC 5077]: https://tools.ietf.org/html/rfc5077 2288[RFC 5929]: https://tools.ietf.org/html/rfc5929 2289[SSL_METHODS]: https://www.openssl.org/docs/man1.1.1/man7/ssl.html#Dealing-with-Protocol-Methods 2290[Session Resumption]: #session-resumption 2291[Stream]: stream.md#stream 2292[TLS recommendations]: https://wiki.mozilla.org/Security/Server_Side_TLS 2293[`'newSession'`]: #event-newsession 2294[`'resumeSession'`]: #event-resumesession 2295[`'secureConnect'`]: #event-secureconnect 2296[`'secureConnection'`]: #event-secureconnection 2297[`'session'`]: #event-session 2298[`--tls-cipher-list`]: cli.md#--tls-cipher-listlist 2299[`Duplex`]: stream.md#class-streamduplex 2300[`NODE_OPTIONS`]: cli.md#node_optionsoptions 2301[`SSL_export_keying_material`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_export_keying_material.html 2302[`SSL_get_version`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_get_version.html 2303[`crypto.getCurves()`]: crypto.md#cryptogetcurves 2304[`import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import 2305[`net.Server.address()`]: net.md#serveraddress 2306[`net.Server`]: net.md#class-netserver 2307[`net.Socket`]: net.md#class-netsocket 2308[`net.createServer()`]: net.md#netcreateserveroptions-connectionlistener 2309[`server.addContext()`]: #serveraddcontexthostname-context 2310[`server.getTicketKeys()`]: #servergetticketkeys 2311[`server.listen()`]: net.md#serverlisten 2312[`server.setTicketKeys()`]: #serversetticketkeyskeys 2313[`socket.connect()`]: net.md#socketconnectoptions-connectlistener 2314[`tls.DEFAULT_ECDH_CURVE`]: #tlsdefault_ecdh_curve 2315[`tls.DEFAULT_MAX_VERSION`]: #tlsdefault_max_version 2316[`tls.DEFAULT_MIN_VERSION`]: #tlsdefault_min_version 2317[`tls.Server`]: #class-tlsserver 2318[`tls.TLSSocket.enableTrace()`]: #tlssocketenabletrace 2319[`tls.TLSSocket.getPeerCertificate()`]: #tlssocketgetpeercertificatedetailed 2320[`tls.TLSSocket.getProtocol()`]: #tlssocketgetprotocol 2321[`tls.TLSSocket.getSession()`]: #tlssocketgetsession 2322[`tls.TLSSocket.getTLSTicket()`]: #tlssocketgettlsticket 2323[`tls.TLSSocket`]: #class-tlstlssocket 2324[`tls.connect()`]: #tlsconnectoptions-callback 2325[`tls.createSecureContext()`]: #tlscreatesecurecontextoptions 2326[`tls.createSecurePair()`]: #tlscreatesecurepaircontext-isserver-requestcert-rejectunauthorized-options 2327[`tls.createServer()`]: #tlscreateserveroptions-secureconnectionlistener 2328[`tls.getCiphers()`]: #tlsgetciphers 2329[`tls.rootCertificates`]: #tlsrootcertificates 2330[`x509.checkHost()`]: crypto.md#x509checkhostname-options 2331[asn1.js]: https://www.npmjs.com/package/asn1.js 2332[certificate object]: #certificate-object 2333[cipher list format]: https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT 2334[forward secrecy]: https://en.wikipedia.org/wiki/Perfect_forward_secrecy 2335[perfect forward secrecy]: #perfect-forward-secrecy 2336