|
| 1 | +// Flags: --experimental-quic --experimental-stream-iter --no-warnings |
| 2 | + |
| 3 | +// A large post-quantum key share splits the ClientHello across QUIC Initial |
| 4 | +// packets. The server must accept the incomplete first packet before ALPN has |
| 5 | +// selected its application, then complete the handshake and process streams. |
| 6 | + |
| 7 | +import { hasQuic, skip, mustCall } from '../common/index.mjs'; |
| 8 | +import assert from 'node:assert'; |
| 9 | +import * as fixtures from '../common/fixtures.mjs'; |
| 10 | + |
| 11 | +if (!hasQuic) { |
| 12 | + skip('QUIC is not enabled'); |
| 13 | +} |
| 14 | + |
| 15 | +const { createPrivateKey } = await import('node:crypto'); |
| 16 | +const { listen, connect } = await import('node:quic'); |
| 17 | +const { bytes } = await import('stream/iter'); |
| 18 | + |
| 19 | +const key = createPrivateKey(fixtures.readKey('agent1-key.pem')); |
| 20 | +const cert = fixtures.readKey('agent1-cert.pem'); |
| 21 | +const alpn = 'quic-multipacket-clienthello'; |
| 22 | +const groups = 'X25519MLKEM768'; |
| 23 | +const streamReceived = Promise.withResolvers(); |
| 24 | + |
| 25 | +const endpoint = await listen(mustCall(async (session) => { |
| 26 | + const info = await session.opened; |
| 27 | + assert.strictEqual(session.alpnProtocol, alpn); |
| 28 | + assert.strictEqual(info.cipherVersion, 'TLSv1.3'); |
| 29 | + |
| 30 | + session.onstream = mustCall(async (stream) => { |
| 31 | + assert.strictEqual( |
| 32 | + Buffer.from(await bytes(stream)).toString(), |
| 33 | + 'application event survived', |
| 34 | + ); |
| 35 | + stream.writer.endSync(); |
| 36 | + await stream.closed; |
| 37 | + streamReceived.resolve(); |
| 38 | + }); |
| 39 | +}), { |
| 40 | + host: '127.0.0.1', |
| 41 | + port: 0, |
| 42 | + alpn: [alpn], |
| 43 | + groups, |
| 44 | + sni: { '*': { keys: [key], certs: [cert] } }, |
| 45 | +}); |
| 46 | + |
| 47 | +const session = await connect(endpoint.address, { |
| 48 | + alpn, |
| 49 | + groups, |
| 50 | + servername: 'localhost', |
| 51 | + verifyPeer: 'manual', |
| 52 | +}); |
| 53 | + |
| 54 | +await session.opened; |
| 55 | +const stream = await session.createBidirectionalStream({ |
| 56 | + body: 'application event survived', |
| 57 | +}); |
| 58 | +await Promise.all([stream.closed, streamReceived.promise]); |
| 59 | +await session.close(); |
| 60 | +await endpoint.close(); |
0 commit comments