UNPKG

learnyounode

Version:

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.

541 lines (531 loc) 171 kB
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>TLS (SSL) | Node.js v12.10.0 Documentation</title> <link rel="stylesheet" href="data:text/css;base64,LyogbGF0aW4tZXh0ICovCkBmb250LWZhY2UgewogIGZvbnQtZmFtaWx5OiAnTGF0byc7CiAgZm9udC1zdHlsZTogaXRhbGljOwogIGZvbnQtd2VpZ2h0OiA0MDA7CiAgc3JjOiBsb2NhbCgnTGF0byBJdGFsaWMnKSwgbG9jYWwoJ0xhdG8tSXRhbGljJyksIHVybChodHRwczovL2ZvbnRzLmdzdGF0aWMuY29tL3MvbGF0by92MTYvUzZ1OHc0Qk1VVFBIanhzQVVpLXFOaVhnN2VVMC53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDEwMC0wMjRGLCBVKzAyNTksIFUrMUUwMC0xRUZGLCBVKzIwMjAsIFUrMjBBMC0yMEFCLCBVKzIwQUQtMjBDRiwgVSsyMTEzLCBVKzJDNjAtMkM3RiwgVStBNzIwLUE3RkY7Cn0KLyogbGF0aW4gKi8KQGZvbnQtZmFjZSB7CiAgZm9udC1mYW1pbHk6ICdMYXRvJzsKICBmb250LXN0eWxlOiBpdGFsaWM7CiAgZm9udC13ZWlnaHQ6IDQwMDsKICBzcmM6IGxvY2FsKCdMYXRvIEl0YWxpYycpLCBsb2NhbCgnTGF0by1JdGFsaWMnKSwgdXJsKGh0dHBzOi8vZm9udHMuZ3N0YXRpYy5jb20vcy9sYXRvL3YxNi9TNnU4dzRCTVVUUEhqeHNBWEMtcU5pWGc3US53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDAwMC0wMEZGLCBVKzAxMzEsIFUrMDE1Mi0wMTUzLCBVKzAyQkItMDJCQywgVSswMkM2LCB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aF9jb21tZW50IHsKICBjb2xvcjogIzY2NjsKICBmb250LXdlaWdodDogbGlnaHRlcjsKfQo="> <link rel="canonical" href="https://nodejs.org/api/tls.html"> </head> <body class="alt apidoc" id="api-section-tls"> <div id="content" class="clearfix"> <div id="column2" class="interior"> <div id="intro" class="interior"> <a href="https://nodejs.org/" title="Go back to the home page"> Node.js </a> </div> <ul> <li><a href="https://nodejs.org/api/documentation.html" class="nav-documentation">About these Docs</a></li> <li><a href="https://nodejs.org/api/synopsis.html" class="nav-synopsis">Usage &amp; Example</a></li> </ul> <div class="line"></div> <ul> <li><a href="https://nodejs.org/api/assert.html" class="nav-assert">Assertion Testing</a></li> <li><a href="https://nodejs.org/api/async_hooks.html" class="nav-async_hooks">Async Hooks</a></li> <li><a href="https://nodejs.org/api/buffer.html" class="nav-buffer">Buffer</a></li> <li><a href="https://nodejs.org/api/addons.html" class="nav-addons">C++ Addons</a></li> <li><a href="https://nodejs.org/api/n-api.html" class="nav-n-api">C/C++ Addons - N-API</a></li> <li><a href="https://nodejs.org/api/child_process.html" class="nav-child_process">Child Processes</a></li> <li><a href="https://nodejs.org/api/cluster.html" class="nav-cluster">Cluster</a></li> <li><a href="https://nodejs.org/api/cli.html" class="nav-cli">Command Line Options</a></li> <li><a href="https://nodejs.org/api/console.html" class="nav-console">Console</a></li> <li><a href="https://nodejs.org/api/crypto.html" class="nav-crypto">Crypto</a></li> <li><a href="https://nodejs.org/api/debugger.html" class="nav-debugger">Debugger</a></li> <li><a href="https://nodejs.org/api/deprecations.html" class="nav-deprecations">Deprecated APIs</a></li> <li><a href="https://nodejs.org/api/dns.html" class="nav-dns">DNS</a></li> <li><a href="https://nodejs.org/api/domain.html" class="nav-domain">Domain</a></li> <li><a href="https://nodejs.org/api/esm.html" class="nav-esm">ECMAScript Modules</a></li> <li><a href="https://nodejs.org/api/errors.html" class="nav-errors">Errors</a></li> <li><a href="https://nodejs.org/api/events.html" class="nav-events">Events</a></li> <li><a href="https://nodejs.org/api/fs.html" class="nav-fs">File System</a></li> <li><a href="https://nodejs.org/api/globals.html" class="nav-globals">Globals</a></li> <li><a href="https://nodejs.org/api/http.html" class="nav-http">HTTP</a></li> <li><a href="https://nodejs.org/api/http2.html" class="nav-http2">HTTP/2</a></li> <li><a href="https://nodejs.org/api/https.html" class="nav-https">HTTPS</a></li> <li><a href="https://nodejs.org/api/inspector.html" class="nav-inspector">Inspector</a></li> <li><a href="https://nodejs.org/api/intl.html" class="nav-intl">Internationalization</a></li> <li><a href="https://nodejs.org/api/modules.html" class="nav-modules">Modules</a></li> <li><a href="https://nodejs.org/api/net.html" class="nav-net">Net</a></li> <li><a href="https://nodejs.org/api/os.html" class="nav-os">OS</a></li> <li><a href="https://nodejs.org/api/path.html" class="nav-path">Path</a></li> <li><a href="https://nodejs.org/api/perf_hooks.html" class="nav-perf_hooks">Performance Hooks</a></li> <li><a href="https://nodejs.org/api/policy.html" class="nav-policy">Policies</a></li> <li><a href="https://nodejs.org/api/process.html" class="nav-process">Process</a></li> <li><a href="https://nodejs.org/api/punycode.html" class="nav-punycode">Punycode</a></li> <li><a href="https://nodejs.org/api/querystring.html" class="nav-querystring">Query Strings</a></li> <li><a href="https://nodejs.org/api/readline.html" class="nav-readline">Readline</a></li> <li><a href="https://nodejs.org/api/repl.html" class="nav-repl">REPL</a></li> <li><a href="https://nodejs.org/api/report.html" class="nav-report">Report</a></li> <li><a href="https://nodejs.org/api/stream.html" class="nav-stream">Stream</a></li> <li><a href="https://nodejs.org/api/string_decoder.html" class="nav-string_decoder">String Decoder</a></li> <li><a href="https://nodejs.org/api/timers.html" class="nav-timers">Timers</a></li> <li><a href="https://nodejs.org/api/tls.html" class="nav-tls active">TLS/SSL</a></li> <li><a href="https://nodejs.org/api/tracing.html" class="nav-tracing">Trace Events</a></li> <li><a href="https://nodejs.org/api/tty.html" class="nav-tty">TTY</a></li> <li><a href="https://nodejs.org/api/dgram.html" class="nav-dgram">UDP/Datagram</a></li> <li><a href="https://nodejs.org/api/url.html" class="nav-url">URL</a></li> <li><a href="https://nodejs.org/api/util.html" class="nav-util">Utilities</a></li> <li><a href="https://nodejs.org/api/v8.html" class="nav-v8">V8</a></li> <li><a href="https://nodejs.org/api/vm.html" class="nav-vm">VM</a></li> <li><a href="https://nodejs.org/api/worker_threads.html" class="nav-worker_threads">Worker Threads</a></li> <li><a href="https://nodejs.org/api/zlib.html" class="nav-zlib">Zlib</a></li> </ul> <div class="line"></div> <ul> <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">GitHub Repo &amp; Issue Tracker</a></li> </ul> </div> <div id="column1" data-id="tls" class="interior"> <header> <h1>Node.js v12.10.0 Documentation</h1> <div id="gtoc"> <ul> <li> <a href="https://nodejs.org/api/index.html" name="toc">Index</a> </li> <li> <a href="https://nodejs.org/api/all.html">View on single page</a> </li> <li> <a href="https://nodejs.org/api/tls.json">View as JSON</a> </li> <li class="version-picker"> <a href="#">View another version <span>▼</span></a> <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v12.x/api/tls.html">12.x</a></li> <li><a href="https://nodejs.org/docs/latest-v11.x/api/tls.html">11.x</a></li> <li><a href="https://nodejs.org/docs/latest-v10.x/api/tls.html">10.x <b>LTS</b></a></li> <li><a href="https://nodejs.org/docs/latest-v9.x/api/tls.html">9.x</a></li> <li><a href="https://nodejs.org/docs/latest-v8.x/api/tls.html">8.x <b>LTS</b></a></li> <li><a href="https://nodejs.org/docs/latest-v7.x/api/tls.html">7.x</a></li> <li><a href="https://nodejs.org/docs/latest-v6.x/api/tls.html">6.x</a></li> <li><a href="https://nodejs.org/docs/latest-v5.x/api/tls.html">5.x</a></li> <li><a href="https://nodejs.org/docs/latest-v4.x/api/tls.html">4.x</a></li> <li><a href="https://nodejs.org/docs/latest-v0.12.x/api/tls.html">0.12.x</a></li> <li><a href="https://nodejs.org/docs/latest-v0.10.x/api/tls.html">0.10.x</a></li></ol> </li> <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/tls.md"><span class="github_icon"><svg height="16" width="16" viewBox="0 0 16.1 16.1" fill="currentColor"><path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"></path></svg></span>Edit on GitHub</a></li> </ul> </div> <hr> </header> <div id="toc"> <h2>Table of Contents</h2> <ul> <li> <p><span class="stability_2"><a href="#tls_tls_ssl">TLS (SSL)</a></span></p> <ul> <li> <p><a href="#tls_tls_ssl_concepts">TLS/SSL Concepts</a></p> <ul> <li><a href="#tls_perfect_forward_secrecy">Perfect Forward Secrecy</a></li> <li><a href="#tls_alpn_and_sni">ALPN and SNI</a></li> <li><a href="#tls_client_initiated_renegotiation_attack_mitigation">Client-initiated renegotiation attack mitigation</a></li> <li><a href="#tls_session_resumption">Session Resumption</a></li> </ul> </li> <li><a href="#tls_modifying_the_default_tls_cipher_suite">Modifying the Default TLS Cipher suite</a></li> <li> <p><a href="#tls_class_tls_server">Class: tls.Server</a></p> <ul> <li><a href="#tls_event_keylog">Event: 'keylog'</a></li> <li><a href="#tls_event_newsession">Event: 'newSession'</a></li> <li><a href="#tls_event_ocsprequest">Event: 'OCSPRequest'</a></li> <li><a href="#tls_event_resumesession">Event: 'resumeSession'</a></li> <li><a href="#tls_event_secureconnection">Event: 'secureConnection'</a></li> <li><a href="#tls_event_tlsclienterror">Event: 'tlsClientError'</a></li> <li><a href="#tls_server_addcontext_hostname_context">server.addContext(hostname, context)</a></li> <li><a href="#tls_server_address">server.address()</a></li> <li><a href="#tls_server_close_callback">server.close([callback])</a></li> <li><span class="stability_0"><a href="#tls_server_connections">server.connections</a></span></li> <li><a href="#tls_server_getticketkeys">server.getTicketKeys()</a></li> <li><a href="#tls_server_listen">server.listen()</a></li> <li><a href="#tls_server_setsecurecontext_options">server.setSecureContext(options)</a></li> <li><a href="#tls_server_setticketkeys_keys">server.setTicketKeys(keys)</a></li> </ul> </li> <li> <p><a href="#tls_class_tls_tlssocket">Class: tls.TLSSocket</a></p> <ul> <li><a href="#tls_new_tls_tlssocket_socket_options">new tls.TLSSocket(socket[, options])</a></li> <li><a href="#tls_event_keylog_1">Event: 'keylog'</a></li> <li><a href="#tls_event_ocspresponse">Event: 'OCSPResponse'</a></li> <li><a href="#tls_event_secureconnect">Event: 'secureConnect'</a></li> <li><a href="#tls_event_session">Event: 'session'</a></li> <li><a href="#tls_tlssocket_address">tlsSocket.address()</a></li> <li><a href="#tls_tlssocket_authorizationerror">tlsSocket.authorizationError</a></li> <li><a href="#tls_tlssocket_authorized">tlsSocket.authorized</a></li> <li><a href="#tls_tlssocket_disablerenegotiation">tlsSocket.disableRenegotiation()</a></li> <li><a href="#tls_tlssocket_enabletrace">tlsSocket.enableTrace()</a></li> <li><a href="#tls_tlssocket_encrypted">tlsSocket.encrypted</a></li> <li><a href="#tls_tlssocket_getcertificate">tlsSocket.getCertificate()</a></li> <li><a href="#tls_tlssocket_getcipher">tlsSocket.getCipher()</a></li> <li><a href="#tls_tlssocket_getephemeralkeyinfo">tlsSocket.getEphemeralKeyInfo()</a></li> <li><a href="#tls_tlssocket_getfinished">tlsSocket.getFinished()</a></li> <li> <p><a href="#tls_tlssocket_getpeercertificate_detailed">tlsSocket.getPeerCertificate([detailed])</a></p> <ul> <li><a href="#tls_certificate_object">Certificate Object</a></li> </ul> </li> <li><a href="#tls_tlssocket_getpeerfinished">tlsSocket.getPeerFinished()</a></li> <li><a href="#tls_tlssocket_getprotocol">tlsSocket.getProtocol()</a></li> <li><a href="#tls_tlssocket_getsession">tlsSocket.getSession()</a></li> <li><a href="#tls_tlssocket_gettlsticket">tlsSocket.getTLSTicket()</a></li> <li><a href="#tls_tlssocket_issessionreused">tlsSocket.isSessionReused()</a></li> <li><a href="#tls_tlssocket_localaddress">tlsSocket.localAddress</a></li> <li><a href="#tls_tlssocket_localport">tlsSocket.localPort</a></li> <li><a href="#tls_tlssocket_remoteaddress">tlsSocket.remoteAddress</a></li> <li><a href="#tls_tlssocket_remotefamily">tlsSocket.remoteFamily</a></li> <li><a href="#tls_tlssocket_remoteport">tlsSocket.remotePort</a></li> <li><a href="#tls_tlssocket_renegotiate_options_callback">tlsSocket.renegotiate(options, callback)</a></li> <li><a href="#tls_tlssocket_setmaxsendfragment_size">tlsSocket.setMaxSendFragment(size)</a></li> </ul> </li> <li><a href="#tls_tls_checkserveridentity_hostname_cert">tls.checkServerIdentity(hostname, cert)</a></li> <li><a href="#tls_tls_connect_options_callback">tls.connect(options[, callback])</a></li> <li><a href="#tls_tls_connect_path_options_callback">tls.connect(path[, options][, callback])</a></li> <li><a href="#tls_tls_connect_port_host_options_callback">tls.connect(port[, host][, options][, callback])</a></li> <li><a href="#tls_tls_createsecurecontext_options">tls.createSecureContext([options])</a></li> <li><a href="#tls_tls_createserver_options_secureconnectionlistener">tls.createServer([options][, secureConnectionListener])</a></li> <li><a href="#tls_tls_getciphers">tls.getCiphers()</a></li> <li><a href="#tls_tls_rootcertificates">tls.rootCertificates</a></li> <li><a href="#tls_tls_default_ecdh_curve">tls.DEFAULT_ECDH_CURVE</a></li> <li><a href="#tls_tls_default_max_version">tls.DEFAULT_MAX_VERSION</a></li> <li><a href="#tls_tls_default_min_version">tls.DEFAULT_MIN_VERSION</a></li> <li> <p><a href="#tls_deprecated_apis">Deprecated APIs</a></p> <ul> <li> <p><span class="stability_0"><a href="#tls_class_cryptostream">Class: CryptoStream</a></span></p> <ul> <li><a href="#tls_cryptostream_byteswritten">cryptoStream.bytesWritten</a></li> </ul> </li> <li> <p><span class="stability_0"><a href="#tls_class_securepair">Class: SecurePair</a></span></p> <ul> <li><a href="#tls_event_secure">Event: 'secure'</a></li> </ul> </li> <li><span class="stability_0"><a href="#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options">tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])</a></span></li> </ul> </li> </ul> </li> </ul> </div> <div id="apicontent"> <h1>TLS (SSL)<span><a class="mark" href="#tls_tls_ssl" id="tls_tls_ssl">#</a></span></h1> <p></p><div class="api_stability api_stability_2"><a href="https://nodejs.org/api/documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p> <p>The <code>tls</code> module provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL) protocols that is built on top of OpenSSL. The module can be accessed using:</p> <pre><code class="language-js">const tls = require('tls'); </code></pre> <h2>TLS/SSL Concepts<span><a class="mark" href="#tls_tls_ssl_concepts" id="tls_tls_ssl_concepts">#</a></span></h2> <p>The TLS/SSL is a public/private key infrastructure (PKI). For most common cases, each client and server must have a <em>private key</em>.</p> <p>Private keys can be generated in multiple ways. The example below illustrates use of the OpenSSL command-line interface to generate a 2048-bit RSA private key:</p> <pre><code class="language-sh">openssl genrsa -out ryans-key.pem 2048 </code></pre> <p>With TLS/SSL, all servers (and some clients) must have a <em>certificate</em>. Certificates are <em>public keys</em> that correspond to a private key, and that are digitally signed either by a Certificate Authority or by the owner of the private key (such certificates are referred to as "self-signed"). The first step to obtaining a certificate is to create a <em>Certificate Signing Request</em> (CSR) file.</p> <p>The OpenSSL command-line interface can be used to generate a CSR for a private key:</p> <pre><code class="language-sh">openssl req -new -sha256 -key ryans-key.pem -out ryans-csr.pem </code></pre> <p>Once the CSR file is generated, it can either be sent to a Certificate Authority for signing or used to generate a self-signed certificate.</p> <p>Creating a self-signed certificate using the OpenSSL command-line interface is illustrated in the example below:</p> <pre><code class="language-sh">openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem </code></pre> <p>Once the certificate is generated, it can be used to generate a <code>.pfx</code> or <code>.p12</code> file:</p> <pre><code class="language-sh">openssl pkcs12 -export -in ryans-cert.pem -inkey ryans-key.pem \ -certfile ca-cert.pem -out ryans.pfx </code></pre> <p>Where:</p> <ul> <li><code>in</code>: is the signed certificate</li> <li><code>inkey</code>: is the associated private key</li> <li><code>certfile</code>: is a concatenation of all Certificate Authority (CA) certs into a single file, e.g. <code>cat ca1-cert.pem ca2-cert.pem &gt; ca-cert.pem</code></li> </ul> <h3>Perfect Forward Secrecy<span><a class="mark" href="#tls_perfect_forward_secrecy" id="tls_perfect_forward_secrecy">#</a></span></h3> <p>The term "<a href="https://en.wikipedia.org/wiki/Perfect_forward_secrecy">Forward Secrecy</a>" or "Perfect Forward Secrecy" describes a feature of key-agreement (i.e., key-exchange) methods. That is, the server and client keys are used to negotiate new temporary keys that are used specifically and only for the current communication session. Practically, this means that even if the server's private key is compromised, communication can only be decrypted by eavesdroppers if the attacker manages to obtain the key-pair specifically generated for the session.</p> <p>Perfect Forward Secrecy is achieved by randomly generating a key pair for key-agreement on every TLS/SSL handshake (in contrast to using the same key for all sessions). Methods implementing this technique are called "ephemeral".</p> <p>Currently two methods are commonly used to achieve Perfect Forward Secrecy (note the character "E" appended to the traditional abbreviations):</p> <ul> <li><a href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">DHE</a> - An ephemeral version of the Diffie Hellman key-agreement protocol.</li> <li><a href="https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman">ECDHE</a> - An ephemeral version of the Elliptic Curve Diffie Hellman key-agreement protocol.</li> </ul> <p>Ephemeral methods may have some performance drawbacks, because key generation is expensive.</p> <p>To use Perfect Forward Secrecy using <code>DHE</code> with the <code>tls</code> module, it is required to generate Diffie-Hellman parameters and specify them with the <code>dhparam</code> option to <a href="#tls_tls_createsecurecontext_options"><code>tls.createSecureContext()</code></a>. The following illustrates the use of the OpenSSL command-line interface to generate such parameters:</p> <pre><code class="language-sh">openssl dhparam -outform PEM -out dhparam.pem 2048 </code></pre> <p>If using Perfect Forward Secrecy using <code>ECDHE</code>, Diffie-Hellman parameters are not required and a default ECDHE curve will be used. The <code>ecdhCurve</code> property can be used when creating a TLS Server to specify the list of names of supported curves to use, see <a href="#tls_tls_createserver_options_secureconnectionlistener"><code>tls.createServer()</code></a> for more info.</p> <p>Perfect Forward Secrecy was optional up to TLSv1.2, but it is not optional for TLSv1.3, because all TLSv1.3 cipher suites use ECDHE.</p> <h3>ALPN and SNI<span><a class="mark" href="#tls_alpn_and_sni" id="tls_alpn_and_sni">#</a></span></h3> <p>ALPN (Application-Layer Protocol Negotiation Extension) and SNI (Server Name Indication) are TLS handshake extensions:</p> <ul> <li>ALPN - Allows the use of one TLS server for multiple protocols (HTTP, HTTP/2)</li> <li>SNI - Allows the use of one TLS server for multiple hostnames with different SSL certificates.</li> </ul> <h3>Client-initiated renegotiation attack mitigation<span><a class="mark" href="#tls_client_initiated_renegotiation_attack_mitigation" id="tls_client_initiated_renegotiation_attack_mitigation">#</a></span></h3> <p>The TLS protocol allows clients to renegotiate certain aspects of the TLS session. Unfortunately, session renegotiation requires a disproportionate amount of server-side resources, making it a potential vector for denial-of-service attacks.</p> <p>To mitigate the risk, renegotiation is limited to three times every ten minutes. An <code>'error'</code> event is emitted on the <a href="#tls_class_tls_tlssocket"><code>tls.TLSSocket</code></a> instance when this threshold is exceeded. The limits are configurable:</p> <ul> <li><code>tls.CLIENT_RENEG_LIMIT</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Specifies the number of renegotiation requests. <strong>Default:</strong> <code>3</code>.</li> <li><code>tls.CLIENT_RENEG_WINDOW</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Specifies the time renegotiation window in seconds. <strong>Default:</strong> <code>600</code> (10 minutes).</li> </ul> <p>The default renegotiation limits should not be modified without a full understanding of the implications and risks.</p> <p>TLSv1.3 does not support renegotiation.</p> <h3>Session Resumption<span><a class="mark" href="#tls_session_resumption" id="tls_session_resumption">#</a></span></h3> <p>Establishing a TLS session can be relatively slow. The process can be sped up by saving and later reusing the session state. There are several mechanisms to do so, discussed here from oldest to newest (and preferred).</p> <p><strong><em>Session Identifiers</em></strong> Servers generate a unique ID for new connections and send it to the client. Clients and servers save the session state. When reconnecting, clients send the ID of their saved session state and if the server also has the state for that ID, it can agree to use it. Otherwise, the server will create a new session. See <a href="https://www.ietf.org/rfc/rfc2246.txt">RFC 2246</a> for more information, page 23 and 30.</p> <p>Resumption using session identifiers is supported by most web browsers when making HTTPS requests.</p> <p>For Node.js, clients wait for the <a href="#tls_event_session"><code>'session'</code></a> event to get the session data, and provide the data to the <code>session</code> option of a subsequent <a href="#tls_tls_connect_options_callback"><code>tls.connect()</code></a> to reuse the session. Servers must implement handlers for the <a href="#tls_event_newsession"><code>'newSession'</code></a> and <a href="#tls_event_resumesession"><code>'resumeSession'</code></a> events to save and restore the session data using the session ID as the lookup key to reuse sessions. To reuse sessions across load balancers or cluster workers, servers must use a shared session cache (such as Redis) in their session handlers.</p> <p><strong><em>Session Tickets</em></strong> The servers encrypt the entire session state and send it to the client as a "ticket". When reconnecting, the state is sent to the server in the initial connection. This mechanism avoids the need for server-side session cache. If the server doesn't use the ticket, for any reason (failure to decrypt it, it's too old, etc.), it will create a new session and send a new ticket. See <a href="https://tools.ietf.org/html/rfc5077">RFC 5077</a> for more information.</p> <p>Resumption using session tickets is becoming commonly supported by many web browsers when making HTTPS requests.</p> <p>For Node.js, clients use the same APIs for resumption with session identifiers as for resumption with session tickets. For debugging, if <a href="#tls_tlssocket_gettlsticket"><code>tls.TLSSocket.getTLSTicket()</code></a> returns a value, the session data contains a ticket, otherwise it contains client-side session state.</p> <p>With TLSv1.3, be aware that multiple tickets may be sent by the server, resulting in multiple <code>'session'</code> events, see <a href="#tls_event_session"><code>'session'</code></a> for more information.</p> <p>Single process servers need no specific implementation to use session tickets. To use session tickets across server restarts or load balancers, servers must all have the same ticket keys. There are three 16-byte keys internally, but the tls API exposes them as a single 48-byte buffer for convenience.</p> <p>Its possible to get the ticket keys by calling <a href="#tls_server_getticketkeys"><code>server.getTicketKeys()</code></a> on one server instance and then distribute them, but it is more reasonable to securely generate 48 bytes of secure random data and set them with the <code>ticketKeys</code> option of <a href="#tls_tls_createserver_options_secureconnectionlistener"><code>tls.createServer()</code></a>. The keys should be regularly regenerated and server's keys can be reset with <a href="#tls_server_setticketkeys_keys"><code>server.setTicketKeys()</code></a>.</p> <p>Session ticket keys are cryptographic keys, and they <strong><em>must be stored securely</em></strong>. With TLS 1.2 and below, if they are compromised all sessions that used tickets encrypted with them can be decrypted. They should not be stored on disk, and they should be regenerated regularly.</p> <p>If clients advertise support for tickets, the server will send them. The server can disable tickets by supplying <code>require('constants').SSL_OP_NO_TICKET</code> in <code>secureOptions</code>.</p> <p>Both session identifiers and session tickets timeout, causing the server to create new sessions. The timeout can be configured with the <code>sessionTimeout</code> option of <a href="#tls_tls_createserver_options_secureconnectionlistener"><code>tls.createServer()</code></a>.</p> <p>For all the mechanisms, when resumption fails, servers will create new sessions. Since failing to resume the session does not cause TLS/HTTPS connection failures, it is easy to not notice unnecessarily poor TLS performance. The OpenSSL CLI can be used to verify that servers are resuming sessions. Use the <code>-reconnect</code> option to <code>openssl s_client</code>, for example:</p> <pre><code class="language-sh">$ openssl s_client -connect localhost:443 -reconnect </code></pre> <p>Read through the debug output. The first connection should say "New", for example:</p> <pre><code class="language-text">New, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256 </code></pre> <p>Subsequent connections should say "Reused", for example:</p> <pre><code class="language-text">Reused, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256 </code></pre> <h2>Modifying the Default TLS Cipher suite<span><a class="mark" href="#tls_modifying_the_default_tls_cipher_suite" id="tls_modifying_the_default_tls_cipher_suite">#</a></span></h2> <p>Node.js is built with a default suite of enabled and disabled TLS ciphers. Currently, the default cipher suite is:</p> <pre><code class="language-txt">TLS_AES_256_GCM_SHA384: TLS_CHACHA20_POLY1305_SHA256: TLS_AES_128_GCM_SHA256: ECDHE-RSA-AES128-GCM-SHA256: ECDHE-ECDSA-AES128-GCM-SHA256: ECDHE-RSA-AES256-GCM-SHA384: ECDHE-ECDSA-AES256-GCM-SHA384: DHE-RSA-AES128-GCM-SHA256: ECDHE-RSA-AES128-SHA256: DHE-RSA-AES128-SHA256: ECDHE-RSA-AES256-SHA384: DHE-RSA-AES256-SHA384: ECDHE-RSA-AES256-SHA256: DHE-RSA-AES256-SHA256: HIGH: !aNULL: !eNULL: !EXPORT: !DES: !RC4: !MD5: !PSK: !SRP: !CAMELLIA </code></pre> <p>This default can be replaced entirely using the <a href="https://nodejs.org/api/cli.html#cli_tls_cipher_list_list"><code>--tls-cipher-list</code></a> command line switch (directly, or via the <a href="https://nodejs.org/api/cli.html#cli_node_options_options"><code>NODE_OPTIONS</code></a> environment variable). For instance, the following makes <code>ECDHE-RSA-AES128-GCM-SHA256:!RC4</code> the default TLS cipher suite:</p> <pre><code class="language-sh">node --tls-cipher-list="ECDHE-RSA-AES128-GCM-SHA256:!RC4" server.js export NODE_OPTIONS=--tls-cipher-list="ECDHE-RSA-AES128-GCM-SHA256:!RC4" node server.js </code></pre> <p>The default can also be replaced on a per client or server basis using the <code>ciphers</code> option from <a href="#tls_tls_createsecurecontext_options"><code>tls.createSecureContext()</code></a>, which is also available in <a href="#tls_tls_createserver_options_secureconnectionlistener"><code>tls.createServer()</code></a>, <a href="#tls_tls_connect_options_callback"><code>tls.connect()</code></a>, and when creating new <a href="#tls_class_tls_tlssocket"><code>tls.TLSSocket</code></a>s.</p> <p>The ciphers list can contain a mixture of TLSv1.3 cipher suite names, the ones that start with <code>'TLS_'</code>, and specifications for TLSv1.2 and below cipher suites. The TLSv1.2 ciphers support a legacy specification format, consult the OpenSSL <a href="https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT">cipher list format</a> documentation for details, but those specifications do <em>not</em> apply to TLSv1.3 ciphers. The TLSv1.3 suites can only be enabled by including their full name in the cipher list. They cannot, for example, be enabled or disabled by using the legacy TLSv1.2 <code>'EECDH'</code> or <code>'!EECDH'</code> specification.</p> <p>Despite the relative order of TLSv1.3 and TLSv1.2 cipher suites, the TLSv1.3 protocol is significantly more secure than TLSv1.2, and will always be chosen over TLSv1.2 if the handshake indicates it is supported, and if any TLSv1.3 cipher suites are enabled.</p> <p>The default cipher suite included within Node.js has been carefully selected to reflect current security best practices and risk mitigation. Changing the default cipher suite can have a significant impact on the security of an application. The <code>--tls-cipher-list</code> switch and <code>ciphers</code> option should by used only if absolutely necessary.</p> <p>The default cipher suite prefers GCM ciphers for <a href="https://www.chromium.org/Home/chromium-security/education/tls#TOC-Cipher-Suites">Chrome's 'modern cryptography' setting</a> and also prefers ECDHE and DHE ciphers for Perfect Forward Secrecy, while offering <em>some</em> backward compatibility.</p> <p>128 bit AES is preferred over 192 and 256 bit AES in light of <a href="https://www.schneier.com/blog/archives/2009/07/another_new_aes.html">specific attacks affecting larger AES key sizes</a>.</p> <p>Old clients that rely on insecure and deprecated RC4 or DES-based ciphers (like Internet Explorer 6) cannot complete the handshaking process with the default configuration. If these clients <em>must</em> be supported, the <a href="https://wiki.mozilla.org/Security/Server_Side_TLS">TLS recommendations</a> may offer a compatible cipher suite. For more details on the format, see the OpenSSL <a href="https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT">cipher list format</a> documentation.</p> <p>There are only 5 TLSv1.3 cipher suites:</p> <ul> <li><code>'TLS_AES_256_GCM_SHA384'</code></li> <li><code>'TLS_CHACHA20_POLY1305_SHA256'</code></li> <li><code>'TLS_AES_128_GCM_SHA256'</code></li> <li><code>'TLS_AES_128_CCM_SHA256'</code></li> <li><code>'TLS_AES_128_CCM_8_SHA256'</code></li> </ul> <p>The first 3 are enabled by default. The last 2 <code>CCM</code>-based suites are supported by TLSv1.3 because they may be more performant on constrained systems, but they are not enabled by default since they offer less security.</p> <h2>Class: tls.Server<span><a class="mark" href="#tls_class_tls_server" id="tls_class_tls_server">#</a></span></h2> <div class="api_metadata"> <span>Added in: v0.3.2</span> </div> <ul> <li>Extends: <a href="https://nodejs.org/api/net.html#net_class_net_server" class="type">&lt;net.Server&gt;</a></li> </ul> <p>Accepts encrypted connections using TLS or SSL.</p> <h3>Event: 'keylog'<span><a class="mark" href="#tls_event_keylog" id="tls_event_keylog">#</a></span></h3> <div class="api_metadata"> <span>Added in: v12.3.0</span> </div> <ul> <li><code>line</code> <a href="https://nodejs.org/api/buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> Line of ASCII text, in NSS <code>SSLKEYLOGFILE</code> format.</li> <li><code>tlsSocket</code> <a href="https://nodejs.org/api/tls.html#tls_class_tls_tlssocket" class="type">&lt;tls.TLSSocket&gt;</a> The <code>tls.TLSSocket</code> instance on which it was generated.</li> </ul> <p>The <code>keylog</code> event is emitted when key material is generated or received by a connection to this server (typically before handshake has completed, but not necessarily). This keying material can be stored for debugging, as it allows captured TLS traffic to be decrypted. It may be emitted multiple times for each socket.</p> <p>A typical use case is to append received lines to a common text file, which is later used by software (such as Wireshark) to decrypt the traffic:</p> <pre><code class="language-js">const logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' }); // ... server.on('keylog', (line, tlsSocket) =&gt; { if (tlsSocket.remoteAddress !== '...') return; // Only log keys for a particular IP logFile.write(line); }); </code></pre> <h3>Event: 'newSession'<span><a class="mark" href="#tls_event_newsession" id="tls_event_newsession">#</a></span></h3> <div class="api_metadata"> <span>Added in: v0.9.2</span> </div> <p>The <code>'newSession'</code> event is emitted upon creation of a new TLS session. This may be used to store sessions in external storage. The data should be provided to the <a href="#tls_event_resumesession"><code>'resumeSession'</code></a> callback.</p> <p>The listener callback is passed three arguments when called:</p> <ul> <li><code>sessionId</code> <a href="https://nodejs.org/api/buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The TLS session identifier</li> <li><code>sessionData</code> <a href="https://nodejs.org/api/buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The TLS session data</li> <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A callback function taking no arguments that must be invoked in order for data to be sent or received over the secure connection.</li> </ul> <p>Listening for this event will have an effect only on connections established after the addition of the event listener.</p> <h3>Event: 'OCSPRequest'<span><a class="mark" href="#tls_event_ocsprequest" id="tls_event_ocsprequest">#</a></span></h3> <div class="api_metadata"> <span>Added in: v0.11.13</span> </div> <p>The <code>'OCSPRequest'</code> event is emitted when the client sends a certificate status request. The listener callback is passed three arguments when called:</p> <ul> <li><code>certificate</code> <a href="https://nodejs.org/api/buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The server certificate</li> <li><code>issuer</code> <a href="https://nodejs.org/api/buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The issuer's certificate</li> <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A callback function that must be invoked to provide the results of the OCSP request.</li> </ul> <p>The server's current certificate can be parsed to obtain the OCSP URL and certificate ID; after obtaining an OCSP response, <code>callback(null, resp)</code> is then invoked, where <code>resp</code> is a <code>Buffer</code> instance containing the OCSP response. Both <code>certificate</code> and <code>issuer</code> are <code>Buffer</code> DER-representations of the primary and issuer's certificates. These can be used to obtain the OCSP certificate I