Skip to content

Commit ffbba49

Browse files
committed
fixup! tls: add certificateCompression option
Drop openssl from the tests entirely, and change build config to not include the various compression libraries if we're configured to use shared libs instead.
1 parent 3bbaede commit ffbba49

2 files changed

Lines changed: 19 additions & 45 deletions

File tree

deps/openssl/openssl.gyp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
{
2020
'target_name': 'openssl',
2121
'type': '<(library)',
22-
'dependencies': [
23-
'../zlib/zlib.gyp:zlib',
24-
'../brotli/brotli.gyp:brotli',
25-
'../zstd/zstd.gyp:zstd',
26-
],
2722
'includes': ['./openssl_common.gypi'],
2823
'defines': [
2924
# Compile out hardware engines. Most are stubs that dynamically load
@@ -54,6 +49,15 @@
5449
'MODULESDIR="<(modules_dir)"',
5550
]
5651
}],
52+
['node_shared_zlib=="false"', {
53+
'dependencies': [ '../zlib/zlib.gyp:zlib' ],
54+
}],
55+
['node_shared_brotli=="false"', {
56+
'dependencies': [ '../brotli/brotli.gyp:brotli' ],
57+
}],
58+
['node_shared_zstd=="false"', {
59+
'dependencies': [ '../zstd/zstd.gyp:zstd' ],
60+
}],
5761
],
5862
'direct_dependent_settings': {
5963
'include_dirs': [ 'openssl/include', 'openssl/crypto/include']

test/parallel/test-tls-certificate-compression.js

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ const assert = require('assert');
66
const tls = require('tls');
77
const net = require('net');
88
const { once } = require('events');
9-
const { execFileSync } = require('child_process');
10-
const fs = require('fs');
11-
const os = require('os');
12-
const path = require('path');
139
const fixtures = require('../common/fixtures');
14-
const { opensslCli } = require('../common/crypto');
1510

1611
const supportedAlgs = tls.getCertificateCompressionAlgorithms();
1712
if (supportedAlgs.length === 0)
@@ -156,35 +151,12 @@ const fixtureCert = fixtures.readKey('agent1-cert.pem');
156151
})().then(common.mustCall());
157152

158153
// Test: TLS connection with certificate compression reduces handshake size.
159-
//
160-
// To see meaningful compression, we generate a certificate with many SANs to
161-
// show easily testable differences. With a ~6 KB DER certificate, compression
162-
// reduces the total handshake bytes by roughly 40-50% (but we assert 75%).
163154
(async () => {
164-
// Generating the large certificates needs the openssl CLI, which isn't
165-
// available everywhere (Alpine). We just skip this in those envs.
166-
if (!opensslCli) return;
167-
168-
// Generate a large self-signed certificate for testing.
169-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tls-comp-'));
170-
const keyFile = path.join(tmpDir, 'key.pem');
171-
const certFile = path.join(tmpDir, 'cert.pem');
172-
173-
const sans = [];
174-
for (let i = 0; i < 200; i++) {
175-
sans.push(`DNS:server${i}.example.com`);
176-
}
155+
const key = fixtureKey;
177156

178-
execFileSync(opensslCli, [
179-
'req', '-new', '-x509', '-nodes', '-days', '1',
180-
'-newkey', 'rsa:2048',
181-
'-keyout', keyFile, '-out', certFile,
182-
'-subj', '/CN=test',
183-
'-addext', `subjectAltName=${sans.join(',')}`,
184-
]);
185-
186-
const key = fs.readFileSync(keyFile);
187-
const cert = fs.readFileSync(certFile);
157+
// Include a massive certificate list. Doesn't matter that they're not a valid chain,
158+
// we'll send them all and the client uses rejectUnauthorized: false.
159+
const cert = Buffer.concat(Array(20).fill(Buffer.from(fixtureCert)));
188160

189161
// Helper: perform a TLS 1.3 handshake via a TCP proxy and return the total
190162
// raw bytes transferred. The proxy counts bytes to measure the on-the-wire
@@ -234,18 +206,18 @@ const fixtureCert = fixtures.readKey('agent1-cert.pem');
234206

235207
// Test each compression algorithm produces a measurably smaller handshake.
236208
// Certificate compression (RFC 8879) compresses the Certificate message
237-
// during the TLS 1.3 handshake. With a ~6 KB certificate containing many
238-
// SANs, all supported algorithms achieve ratios well below 0.75.
209+
// during the TLS 1.3 handshake. With the large repeated cert list above, all
210+
// supported algorithms achieve ratios well below 0.5.
239211
for (const algo of supportedAlgs) {
240212
const compressed = await measureHandshakeBytes(
241213
{ key, cert, minVersion: 'TLSv1.3', certificateCompression: [algo] },
242214
{ certificateCompression: [algo] },
243215
);
244216
const ratio = compressed / baseline;
245217
assert.ok(
246-
ratio < 0.75,
218+
ratio < 0.5,
247219
`Expected ${algo} compressed handshake (${compressed} bytes, ` +
248-
`ratio=${ratio.toFixed(3)}) to be <75% of baseline ` +
220+
`ratio=${ratio.toFixed(3)}) to be <50% of baseline ` +
249221
`(${baseline} bytes)`
250222
);
251223
}
@@ -280,12 +252,10 @@ const fixtureCert = fixtures.readKey('agent1-cert.pem');
280252
);
281253
const sniRatio = sniBytes / baseline;
282254
assert.ok(
283-
sniRatio < 0.75,
255+
sniRatio < 0.5,
284256
`Expected SNI compressed handshake (${sniBytes} bytes, ` +
285-
`ratio=${sniRatio.toFixed(3)}) to be <75% of baseline ` +
257+
`ratio=${sniRatio.toFixed(3)}) to be <50% of baseline ` +
286258
`(${baseline} bytes)`
287259
);
288260
}
289-
290-
fs.rmSync(tmpDir, { recursive: true });
291261
})().then(common.mustCall());

0 commit comments

Comments
 (0)