Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -6808,10 +6808,18 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
if (nread2 < 0) {
return nread2;
}

return (ngtcp2_ssize)pktlen;
}

/* Discard 0-RTT packet if we don't have a key to decrypt it. */
return (ngtcp2_ssize)pktlen;
/* Discard 0-RTT packet if we don't have a key to decrypt it and
the ClientHello has been processed. Until then (the
ClientHello spans several Initial packets, or the TLS stack
interrupted the handshake), the 0-RTT key might still be
installed, so buffer the packet. */
if (!conn->hs_pktns || conn->hs_pktns->crypto.rx.ckm) {
return (ngtcp2_ssize)pktlen;
}
}

/* Buffer re-ordered 0-RTT packet. */
Expand Down
12 changes: 10 additions & 2 deletions doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@
* {string}

The default TLS 1.3 key-exchange group list used when
[`sessionOptions.groups`][] is not specified.
[`sessionOptions.groups`][] is not specified. The list prefers the
`X25519MLKEM768` hybrid post-quantum group and sends key shares for both
`X25519MLKEM768` and `X25519`.

## Class: `QuicEndpoint`

Expand Down Expand Up @@ -3282,13 +3284,18 @@

#### `sessionOptions.groups`

<!-- YAML

Check warning on line 3287 in doc/api/quic.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
added: v23.8.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000
description: The default now includes the `X25519MLKEM768` group.
-->

* Type: {string}

The list of supported TLS 1.3 cipher groups.
The colon-separated list of TLS 1.3 key-exchange groups, in the
OpenSSL group list format. **Default:** [`quic.constants.DEFAULT_GROUPS`][].

#### `sessionOptions.keylog`

Expand Down Expand Up @@ -4901,6 +4908,7 @@
[`maxDatagramFrameSize`]: #transportparamsmaxdatagramframesize
[`net.BlockList`]: net.md#class-netblocklist
[`quic.connect()`]: #quicconnectaddress-options
[`quic.constants.DEFAULT_GROUPS`]: #quicconstantsdefault_groups
[`quic.listen()`]: #quiclistenonsession-options
[`session.close()`]: #sessioncloseoptions
[`session.createBidirectionalStream()`]: #sessioncreatebidirectionalstreamoptions
Expand Down
3 changes: 2 additions & 1 deletion src/quic/tlscontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class TLSContext final : public MemoryRetainer,
"TLS_AES_256_GCM_SHA384:"
"TLS_CHACHA20_POLY1305_"
"SHA256:TLS_AES_128_CCM_SHA256";
static constexpr auto DEFAULT_GROUPS = "X25519:P-256:P-384:P-521";
static constexpr auto DEFAULT_GROUPS =
"?*X25519MLKEM768:*X25519:P-256:P-384:P-521";

struct Options final : public MemoryRetainer {
// The SNI servername to use for this session. This option is only used by
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-quic-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ assert.strictEqual(quic.constants.cc.BBR, 'bbr');
assert.strictEqual(quic.constants.DEFAULT_CIPHERS,
'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:' +
'TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256');
assert.strictEqual(quic.constants.DEFAULT_GROUPS, 'X25519:P-256:P-384:P-521');
assert.strictEqual(quic.constants.DEFAULT_GROUPS,
'?*X25519MLKEM768:*X25519:P-256:P-384:P-521');

// Ensure the constants are.. well, constant.
assert.throws(() => { quic.constants.cc.RENO = 'foo'; }, TypeError);
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-quic-tls-default-groups.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Flags: --experimental-quic --no-warnings

// Test: the default groups let a client handshake with a server that
// accepts only X25519MLKEM768 and with a server that accepts only X25519.

import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';

if (!hasQuic) {
skip('QUIC is not enabled');
}

const { listen, connect } = await import('node:quic');
const { createPrivateKey } = await import('node:crypto');

const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
const cert = fixtures.readKey('agent1-cert.pem');

for (const groups of ['X25519MLKEM768', 'X25519']) {
const serverEndpoint = await listen(mustCall(async (serverSession) => {
await serverSession.opened;
serverSession.close();
}), {
sni: { '*': { keys: [key], certs: [cert] } },
alpn: ['quic-test'],
groups,
});

const clientSession = await connect(serverEndpoint.address, {
alpn: 'quic-test',
verifyPeer: 'manual',
servername: 'localhost',
});

const info = await clientSession.opened;
assert.strictEqual(info.cipherVersion, 'TLSv1.3');

await clientSession.closed;
await serverEndpoint.close();
}
61 changes: 61 additions & 0 deletions test/parallel/test-quic-zero-rtt-split-client-hello.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Flags: --experimental-quic --no-warnings

// Test: 0-RTT data is accepted when the ClientHello spans more than one
// Initial packet. The X25519MLKEM768 key share makes the ClientHello too
// large for one packet, and the 0-RTT packet is coalesced with the last
// Initial packet while the server's handshake is paused for the new
// session callback. A datagram is used because it is not retransmitted.

import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';

if (!hasQuic) {
skip('QUIC is not enabled');
}

const { listen, connect } = await import('../common/quic.mjs');

const groups = 'X25519MLKEM768';
const transportParams = { maxDatagramFrameSize: 1200 };

const gotTicket = Promise.withResolvers();
const gotToken = Promise.withResolvers();
const serverGotDatagram = Promise.withResolvers();

let serverSessionCount = 0;
const serverEndpoint = await listen(mustCall((serverSession) => {
if (++serverSessionCount === 2) {
serverSession.ondatagram = mustCall((data, early) => {
serverGotDatagram.resolve({ data: Buffer.from(data), early });
});
}
}, 2), { groups, transportParams });

const cs1 = await connect(serverEndpoint.address, {
groups,
transportParams,
onsessionticket: mustCall((ticket) => gotTicket.resolve(ticket)),
onnewtoken: mustCall((token) => gotToken.resolve(token)),
});
await cs1.opened;
const [sessionTicket, token] =
await Promise.all([gotTicket.promise, gotToken.promise]);
await cs1.close();

const cs2 = await connect(serverEndpoint.address, {
groups,
transportParams,
sessionTicket,
token,
});
await cs2.sendDatagram(new Uint8Array([0xCA, 0xFE]));

const info = await cs2.opened;
assert.strictEqual(info.earlyDataAccepted, true);

const { data, early } = await serverGotDatagram.promise;
assert.deepStrictEqual(data, Buffer.from([0xCA, 0xFE]));
assert.strictEqual(early, true);

await cs2.close();
await serverEndpoint.close();
Loading