|
| 1 | +// Flags: --experimental-quic --no-warnings |
| 2 | + |
| 3 | +import{hasQuic,skip,mustCall}from'../common/index.mjs'; |
| 4 | +importassertfrom'node:assert'; |
| 5 | +import*asfixturesfrom'../common/fixtures.mjs'; |
| 6 | + |
| 7 | +if(!hasQuic){ |
| 8 | +skip('QUIC is not enabled'); |
| 9 | +} |
| 10 | + |
| 11 | +const{ listen, connect }=awaitimport('node:quic'); |
| 12 | +const{ createPrivateKey }=awaitimport('node:crypto'); |
| 13 | +consttls=awaitimport('node:tls'); |
| 14 | + |
| 15 | +constkey=createPrivateKey(fixtures.readKey('agent1-key.pem')); |
| 16 | +constcert=fixtures.readKey('agent1-cert.pem'); |
| 17 | + |
| 18 | +// Certificate compression (RFC 8879) depends on the OpenSSL build linking in |
| 19 | +// the compression libraries. Reuse the node:tls detection helper to decide |
| 20 | +// whether the feature is available. |
| 21 | +constsupported=tls.getCertificateCompressionAlgorithms(); |
| 22 | +if(supported.length===0){ |
| 23 | +skip('certificate compression not supported by this OpenSSL build'); |
| 24 | +} |
| 25 | + |
| 26 | +// --------------------------------------------------------------------------- |
| 27 | +// Option validation. The certificateCompression option is parsed by |
| 28 | +// processTlsOptions during connect()/listen(), so invalid values reject the |
| 29 | +// returned promise before any network activity happens. |
| 30 | +// --------------------------------------------------------------------------- |
| 31 | +{ |
| 32 | +// Non-array values are rejected. |
| 33 | +awaitassert.rejects( |
| 34 | +connect('127.0.0.1:4433',{certificateCompression: true}), |
| 35 | +{code: 'ERR_INVALID_ARG_TYPE'}); |
| 36 | + |
| 37 | +awaitassert.rejects( |
| 38 | +connect('127.0.0.1:4433',{certificateCompression: 'zlib'}), |
| 39 | +{code: 'ERR_INVALID_ARG_TYPE'}); |
| 40 | + |
| 41 | +// Unknown algorithm names are rejected. |
| 42 | +awaitassert.rejects( |
| 43 | +connect('127.0.0.1:4433',{certificateCompression: ['invalid']}), |
| 44 | +{code: 'ERR_INVALID_ARG_VALUE', |
| 45 | +message: /mustbe'zlib','brotli',or'zstd'/}); |
| 46 | + |
| 47 | +// Non-string entries are rejected. |
| 48 | +awaitassert.rejects( |
| 49 | +connect('127.0.0.1:4433',{certificateCompression: [1]}), |
| 50 | +{code: 'ERR_INVALID_ARG_VALUE', |
| 51 | +message: /mustbe'zlib','brotli',or'zstd'/}); |
| 52 | + |
| 53 | +// At most three algorithms may be specified. |
| 54 | +awaitassert.rejects( |
| 55 | +connect('127.0.0.1:4433',{ |
| 56 | +certificateCompression: ['zlib','brotli','zstd','zlib'], |
| 57 | +}), |
| 58 | +{code: 'ERR_INVALID_ARG_VALUE',message: /atmost3algorithms/}); |
| 59 | +} |
| 60 | + |
| 61 | +// --------------------------------------------------------------------------- |
| 62 | +// Functional handshakes. Enabling certificate compression must not break the |
| 63 | +// TLS 1.3 handshake. The on-the-wire size reduction is exercised by the |
| 64 | +// node:tls certificate compression test; over QUIC the payload is encrypted |
| 65 | +// and carried in UDP datagrams, so here we assert the handshake completes |
| 66 | +// successfully with the option enabled on the server, the client, or both. |
| 67 | +// --------------------------------------------------------------------------- |
| 68 | +asyncfunctionhandshake({ serverAlgs, clientAlgs }){ |
| 69 | +constserverOpened=Promise.withResolvers(); |
| 70 | + |
| 71 | +constendpoint=awaitlisten(mustCall(async(serverSession)=>{ |
| 72 | +constinfo=awaitserverSession.opened; |
| 73 | +assert.strictEqual(info.protocol,'h3'); |
| 74 | +serverOpened.resolve(); |
| 75 | +serverSession.close(); |
| 76 | +}),{ |
| 77 | +sni: {'*': {keys: [key],certs: [cert]}}, |
| 78 | + ...(serverAlgs!==undefined ? |
| 79 | +{certificateCompression: serverAlgs} : {}), |
| 80 | +}); |
| 81 | + |
| 82 | +constclientSession=awaitconnect(endpoint.address,{ |
| 83 | +servername: 'localhost', |
| 84 | +verifyPeer: 'manual', |
| 85 | + ...(clientAlgs!==undefined ? |
| 86 | +{certificateCompression: clientAlgs} : {}), |
| 87 | +}); |
| 88 | + |
| 89 | +constinfo=awaitclientSession.opened; |
| 90 | +assert.strictEqual(info.protocol,'h3'); |
| 91 | + |
| 92 | +awaitserverOpened.promise; |
| 93 | +awaitclientSession.close(); |
| 94 | +awaitendpoint.close(); |
| 95 | +} |
| 96 | + |
| 97 | +// Each supported algorithm negotiates a successful handshake when enabled on |
| 98 | +// both peers. |
| 99 | +for(constalgoofsupported){ |
| 100 | +awaithandshake({serverAlgs: [algo],clientAlgs: [algo]}); |
| 101 | +} |
| 102 | + |
| 103 | +// All supported algorithms advertised together. |
| 104 | +awaithandshake({serverAlgs: supported,clientAlgs: supported}); |
| 105 | + |
| 106 | +// Asymmetric configurations must also complete: a peer that does not advertise |
| 107 | +// compression simply receives an uncompressed certificate. |
| 108 | +awaithandshake({serverAlgs: [supported[0]],clientAlgs: undefined}); |
| 109 | +awaithandshake({serverAlgs: undefined,clientAlgs: [supported[0]]}); |
| 110 | + |
| 111 | +// An empty array is equivalent to disabling compression. |
| 112 | +awaithandshake({serverAlgs: [],clientAlgs: []}); |
0 commit comments