@@ -6,12 +6,7 @@ const assert = require('assert');
66const tls = require ( 'tls' ) ;
77const net = require ( 'net' ) ;
88const { once } = require ( 'events' ) ;
9- const { execFileSync } = require ( 'child_process' ) ;
10- const fs = require ( 'fs' ) ;
11- const os = require ( 'os' ) ;
12- const path = require ( 'path' ) ;
139const fixtures = require ( '../common/fixtures' ) ;
14- const { opensslCli } = require ( '../common/crypto' ) ;
1510
1611const supportedAlgs = tls . getCertificateCompressionAlgorithms ( ) ;
1712if ( 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