From 5e901b5cd97ecb7a6fe9d9f84e88c9dd7becdf12 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 11 Mar 2026 17:20:36 +0100 Subject: [PATCH] tls: add certificateCompression option This changes enables compression within OpenSSL *without* enabling record compression, so this only affects compression of certificates delivered within the TLS handshake. This certificate compression remains disabled by default for now, but becomes available via the new certificateCompression option in TLS context APIs. Enabling this shrinks handshakes significantly, and also reduces fingerprintability of Node.js client handshakes, as these are enabled in all modern browsers by default. Signed-off-by: Tim Perry PR-URL: https://github.com/nodejs/node/pull/62217 Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell --- deps/openssl/openssl.gyp | 14 +- doc/api/tls.md | 29 ++ lib/internal/tls/secure-context.js | 38 +++ lib/internal/tls/wrap.js | 2 + lib/tls.js | 5 + src/crypto/crypto_context.cc | 113 +++++++- src/crypto/crypto_context.h | 35 +++ src/crypto/crypto_tls.cc | 18 ++ src/crypto/crypto_util.h | 4 + .../test-tls-certificate-compression.js | 261 ++++++++++++++++++ 10 files changed, 513 insertions(+), 6 deletions(-) create mode 100644 test/parallel/test-tls-certificate-compression.js diff --git a/deps/openssl/openssl.gyp b/deps/openssl/openssl.gyp index a2248e7a565..4e16412a028 100644 --- a/deps/openssl/openssl.gyp +++ b/deps/openssl/openssl.gyp @@ -19,11 +19,6 @@ { 'target_name': 'openssl', 'type': '<(library)', - 'dependencies': [ - '../zlib/zlib.gyp:zlib', - '../brotli/brotli.gyp:brotli', - '../zstd/zstd.gyp:zstd', - ], 'includes': ['./openssl_common.gypi'], 'defines': [ # Compile out hardware engines. Most are stubs that dynamically load @@ -54,6 +49,15 @@ 'MODULESDIR="<(modules_dir)"', ] }], + ['node_shared_zlib=="false"', { + 'dependencies': [ '../zlib/zlib.gyp:zlib' ], + }], + ['node_shared_brotli=="false"', { + 'dependencies': [ '../brotli/brotli.gyp:brotli' ], + }], + ['node_shared_zstd=="false"', { + 'dependencies': [ '../zstd/zstd.gyp:zstd' ], + }], ], 'direct_dependent_settings': { 'include_dirs': [ 'openssl/include', 'openssl/crypto/include'] diff --git a/doc/api/tls.md b/doc/api/tls.md index 0fed13e2ee5..e2231c65448 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -1895,6 +1895,9 @@ argument. + +* Returns: {string\[]} + +Returns an array with the names of the RFC 8879 certificate compression +algorithms supported by the current OpenSSL build, suitable for use in the +`certificateCompression` option of [`tls.createSecureContext()`][]. Possible +values include `'zlib'`, `'brotli'`, and `'zstd'`. + +The array is empty when certificate compression is unavailable. + +```js +console.log(tls.getCertificateCompressionAlgorithms()); // ['zlib', 'brotli', 'zstd'] +``` + ## `tls.rootCertificates`