From 7927a6bf36fd6048d7bc80775f05859a31b36955 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 22:50:25 -0700 Subject: [PATCH 1/5] chore(quest): claim quest/m1/quic-zero-rtt-leftovers.md Quest-Claim: 803cbd8ffc8a701b From 5623d4047161da4f7e9e9a1d52ff1701235b72d0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 22:56:37 -0700 Subject: [PATCH 2/5] fix(moq-quic): delete the remaining 0-RTT code Drop the 0-RTT to Data-space mappings, the no-op 0-RTT arm, and the rustls early-data guards, which rustls's defaults make redundant. The characterize test now proves a 0-RTT packet carrying an ACK is dropped unprocessed. Co-Authored-By: Claude Opus 5.5 --- quest/m1/README.md | 1 - quest/m1/quic-zero-rtt-leftovers.md | 20 --- rs/moq-quic/MIGRATE.md | 3 +- rs/moq-quic/README.md | 2 +- rs/moq-quic/src/connection/mod.rs | 6 +- rs/moq-quic/src/crypto/rustls.rs | 131 ++----------------- rs/moq-quic/src/packet.rs | 8 +- rs/moq-quic/src/tests/characterize/frames.rs | 35 +++-- rs/moq-uring/MIGRATE.md | 2 +- rs/moq-uring/tests/integration/endpoint.rs | 5 +- 10 files changed, 42 insertions(+), 171 deletions(-) delete mode 100644 quest/m1/quic-zero-rtt-leftovers.md diff --git a/quest/m1/README.md b/quest/m1/README.md index 0b06ea53230..9bbad213a4f 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -187,7 +187,6 @@ removed). - [A JS reader finishes after a clean close](/quest/m1/js-close-range-finish.md) - a range ending below the cache delivers what's held and then ends - [fMP4 decode times keep increasing](/quest/m1/fmp4-bframe-decode-time.md) - fragments shorter than a GOP of B-frame video never step `tfdt` backwards - [A JS relay floors an unresolved copy at its newest group](/quest/m1/js-early-latest.md) - lite-01..05 subscribes without a start don't replay the cache from group 0 -- [moq-quic deletes its remaining 0-RTT code](/quest/m1/quic-zero-rtt-leftovers.md) - only the code that drops a 0-RTT packet remains, with a test - [Gate the no-em-dash rule](/quest/m1/em-dash-gate.md) - `just check` fails on an em dash in any tracked text file ## Related diff --git a/quest/m1/quic-zero-rtt-leftovers.md b/quest/m1/quic-zero-rtt-leftovers.md deleted file mode 100644 index 0cca73b79fa..00000000000 --- a/quest/m1/quic-zero-rtt-leftovers.md +++ /dev/null @@ -1,20 +0,0 @@ -# [XS] moq-quic deletes its remaining 0-RTT code - -## Goal - -moq-quic has no 0-RTT code left beyond what it needs to recognize and drop a 0-RTT packet: no Data-space mapping for 0-RTT, no early-data guards or tests, and a test proving a peer's 0-RTT packets are dropped unprocessed. - -## Plan - -The maintainer deleted 0-RTT entirely (see [quic-api](/quest/m1/quic-api/README.md)): MoQ needs the finished handshake for CONNECT and authorization. [moq-dev/moq#6837](https://github.com/moq-dev/moq/pull/6837) already drops 0-RTT before decryption (`rs/moq-quic/src/endpoint.rs:215-227`, `rs/moq-quic/src/connection/packet_crypto.rs:16-19`), so the "ACK in 0-RTT" report on [moq-dev/moq#7334](https://github.com/moq-dev/moq/pull/7334) isn't reachable on main. - -Decided 2026-10-30 (maintainer, follow-up planning after the /quest-afk run): a standalone m1 cleanup. Remove what's left: - -- `PartialDecode::space()` and `Header::space()` mapping 0-RTT to the Data space, and `is_0rtt()` (`rs/moq-quic/src/packet.rs:82-95`, `:391-393`), keeping only the `LongType::ZeroRtt` decode needed to skip the packet. -- The no-op `LongType::ZeroRtt` arm in `rs/moq-quic/src/connection/mod.rs:2812-2814`. -- The rustls early-data guards and their test (`rs/moq-quic/src/crypto/rustls.rs:295-296, 355-356, 420-421, 458-459, 605-681`) if rustls's defaults already leave early data off; otherwise keep the guard and its test. -- The characterize test `early_packets_leave_handshake_and_application_data_usable` (`rs/moq-quic/src/tests/characterize/frames.rs:38-110`) becomes a test that a 0-RTT packet, ACK included, is dropped; fix the comment at `rs/moq-uring/tests/integration/endpoint.rs:290`. - -`process_early_payload` handles Initial and Handshake packets, not 0-RTT; leave it. - -Public API: none. Wire: none. diff --git a/rs/moq-quic/MIGRATE.md b/rs/moq-quic/MIGRATE.md index 11a13e91236..4e4aaba4d16 100644 --- a/rs/moq-quic/MIGRATE.md +++ b/rs/moq-quic/MIGRATE.md @@ -9,7 +9,8 @@ How to update your code for each breaking change, newest first. Wait for `Event::Connected` before opening streams or sending application data. `Connection::has_0rtt`, `accepted_0rtt`, and the `crypto::Session::early_crypto` and `early_data_accepted` hooks are gone. Custom crypto sessions no longer implement those hooks. -Rustls configs disable early data, including caller-supplied configs, while session tickets still resume 1-RTT handshakes. +Leave early data off in caller-supplied rustls configs, as rustls does by default, since the transport discards 0-RTT packets. +Session tickets still resume 1-RTT handshakes. ### QUIC APIs follow their consumers diff --git a/rs/moq-quic/README.md b/rs/moq-quic/README.md index 1a2822b39a5..7402a3311ae 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -43,7 +43,7 @@ Changes on top of the upstream commit, besides the renames: - **QUIC v1 only**: `Version` names the one version spoken; drafts 29 to 34, their initial salts, and their retry keys are gone, since no MoQ peer speaks them. - **Plain configs**: `transport`, `client`, `server`, and `endpoint` configs are structs with public fields instead of setters, validated when an endpoint is built or dials. `Limits` is the one spelling of the windows and stream count, at construction and on a live connection, where it also changes the stream receive window. - **Close events**: a local close reports `connection::Error::LocallyClosed` with its code and reason as the connection's `ConnectionLost`, a handshake that idles out reports `HandshakeTimeout`, and close reasons are strings, lossily decoded. -- **No early data**: TLS never offers or accepts 0-RTT, and early packets are discarded without decryption. The early keys, remembered transport parameters, stream rollback, and early-session driver APIs are removed. Session tickets still resume 1-RTT handshakes. MoQ's CONNECT and authorization already wait for the handshake. +- **No early data**: rustls's default configs never offer or accept 0-RTT, and 0-RTT packets are discarded without decryption. The early keys, remembered transport parameters, stream rollback, and early-session driver APIs are removed. Session tickets still resume 1-RTT handshakes. MoQ's CONNECT and authorization already wait for the handshake. - **BBR3**, from [quinn#2481](https://github.com/quinn-rs/quinn/pull/2481) at [`55f74c0d`](https://github.com/quinn-rs/quinn/pull/2481/commits/55f74c0dd0738b5ad7d7676c0b2869a547783f83) (open upstream), rebased onto the fork point with authorship kept. It replaces quinn's BBR and is the default controller. It carries the BBR correctness fixes moq-dev/noq shipped in `moq-noq` 1.3.1, and with them the `Controller` changes BBR needs: per-packet send and loss callbacks, `on_cwnd_limited`, `on_app_limited`, `on_ack_frequency_update`, and controller-owned pacing and burst size. `ControllerMetrics` rates are bytes per second. - **BBR3 loss samples**: a lost packet supplies its own inflight, loss, and application-limited state without borrowing or overwriting the ACK sample, including before the first ACK observation. This follows draft-06 and Google Linux BBRv3; upstream submission waits on quinn#2481 for the same callback adaptation as packet retirement. - **BBR3 packet retirement**: per-space packet lookup and round-indexed expiry retire completed snapshots incrementally, preserving the extra ACK batch of metadata for late loss callbacks. The bounded indexes handle sparse packet numbers without walking the live flight. Upstream submission is deferred while quinn#2481 remains open: this fork also carries the packet-space and loss callback adaptations, so a port needs to target that implementation after its shape settles. diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index ccb699437b4..fd042626d4d 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -2909,9 +2909,6 @@ impl Connection { } Ok(()) } - Header::Long { - ty: LongType::ZeroRtt, .. - } => Ok(()), Header::VersionNegotiate { .. } => { // RFC 9000 6.2: discard once any other packet was processed if processed_server_packet { @@ -2930,6 +2927,9 @@ impl Connection { Header::Short { .. } => { unreachable!("short packets received during handshake are discarded in handle_packet") } + Header::Long { + ty: LongType::ZeroRtt, .. + } => unreachable!("0-RTT packets are discarded in unprotect_header"), } } diff --git a/rs/moq-quic/src/crypto/rustls.rs b/rs/moq-quic/src/crypto/rustls.rs index d7f0547eb42..8698f7a7a8c 100644 --- a/rs/moq-quic/src/crypto/rustls.rs +++ b/rs/moq-quic/src/crypto/rustls.rs @@ -265,8 +265,8 @@ pub struct HandshakeData { /// Alternatively, `QuicClientConfig`'s [`TryFrom`] implementation can be used to wrap around a /// custom [`rustls::ClientConfig`], in which case care should be taken around certain points: /// -/// TLS 1.3 is required. Early data is disabled, while the inner config's resumption -/// cache still enables resumed 1-RTT handshakes. +/// TLS 1.3 is required. Leave `enable_early_data` off, its default: the transport discards +/// 0-RTT packets. The inner config's resumption cache still enables resumed 1-RTT handshakes. /// /// [root_certs]: crate::client::Config::with_root_certificates() pub struct QuicClientConfig { @@ -291,10 +291,7 @@ impl QuicClientConfig { /// Initialize a QUIC-compatible TLS client configuration with a separate initial cipher suite /// /// This is useful if you want to avoid the initial cipher suite for traffic encryption. - pub fn with_initial(mut inner: Arc, initial: Suite) -> Result { - if inner.enable_early_data { - Arc::make_mut(&mut inner).enable_early_data = false; - } + pub fn with_initial(inner: Arc, initial: Suite) -> Result { match initial.suite.common.suite { CipherSuite::TLS13_AES_128_GCM_SHA256 => Ok(Self { inner, initial }), _ => Err(NoInitialCipherSuite { specific: true }), @@ -351,10 +348,7 @@ impl TryFrom for QuicClientConfig { impl TryFrom> for QuicClientConfig { type Error = NoInitialCipherSuite; - fn try_from(mut inner: Arc) -> Result { - if inner.enable_early_data { - Arc::make_mut(&mut inner).enable_early_data = false; - } + fn try_from(inner: Arc) -> Result { Ok(Self { initial: initial_suite_from_provider(inner.crypto_provider()) .ok_or(NoInitialCipherSuite { specific: false })?, @@ -394,8 +388,8 @@ impl std::error::Error for NoInitialCipherSuite {} /// implementation or `with_initial` method can be used to wrap around a custom /// [`rustls::ServerConfig`], in which case care should be taken around certain points: /// -/// TLS 1.3 is required. Early data is disabled, while session tickets still enable -/// resumed 1-RTT handshakes. +/// TLS 1.3 is required. Leave `max_early_data_size` at 0, its default: the transport discards +/// 0-RTT packets. Session tickets still enable resumed 1-RTT handshakes. /// /// [single]: crate::server::Config::with_single_cert() pub struct QuicServerConfig { @@ -416,10 +410,7 @@ impl QuicServerConfig { /// Initialize a QUIC-compatible TLS client configuration with a separate initial cipher suite /// /// This is useful if you want to avoid the initial cipher suite for traffic encryption. - pub fn with_initial(mut inner: Arc, initial: Suite) -> Result { - if inner.max_early_data_size != 0 { - Arc::make_mut(&mut inner).max_early_data_size = 0; - } + pub fn with_initial(inner: Arc, initial: Suite) -> Result { match initial.suite.common.suite { CipherSuite::TLS13_AES_128_GCM_SHA256 => Ok(Self { inner, initial }), _ => Err(NoInitialCipherSuite { specific: true }), @@ -428,7 +419,7 @@ impl QuicServerConfig { /// Initialize a sane QUIC-compatible TLS server configuration /// - /// TLS 1.3 is required and early data stays disabled. + /// TLS 1.3 is required, and rustls leaves early data disabled by default. pub(crate) fn inner( cert_chain: Vec>, key: PrivateKeyDer<'static>, @@ -454,10 +445,7 @@ impl TryFrom for QuicServerConfig { impl TryFrom> for QuicServerConfig { type Error = NoInitialCipherSuite; - fn try_from(mut inner: Arc) -> Result { - if inner.max_early_data_size != 0 { - Arc::make_mut(&mut inner).max_early_data_size = 0; - } + fn try_from(inner: Arc) -> Result { Ok(Self { initial: initial_suite_from_provider(inner.crypto_provider()) .ok_or(NoInitialCipherSuite { specific: false })?, @@ -585,104 +573,3 @@ fn rustls_version(version: crate::Version) -> Version { crate::Version::V1 => Version::V1, } } - -#[cfg(test)] -mod tests { - use super::*; - - fn handshake( - client: Arc, - server: Arc, - ) -> (rustls::HandshakeKind, bool, bool) { - let mut client = rustls::quic::ClientConnection::new( - client, - Version::V1, - ServerName::try_from("localhost").unwrap(), - Vec::new(), - ) - .unwrap(); - let mut server = rustls::quic::ServerConnection::new(server, Version::V1, Vec::new()).unwrap(); - let early_keys = client.zero_rtt_keys().is_some(); - loop { - let mut to_server = Vec::new(); - let _ = client.write_hs(&mut to_server); - if !to_server.is_empty() { - server.read_hs(&to_server).unwrap(); - } - let mut to_client = Vec::new(); - let _ = server.write_hs(&mut to_client); - if !to_client.is_empty() { - client.read_hs(&to_client).unwrap(); - } - if to_server.is_empty() && to_client.is_empty() { - break; - } - } - assert!(!client.is_handshaking()); - assert!(!server.is_handshaking()); - ( - client.handshake_kind().unwrap(), - early_keys, - client.is_early_data_accepted(), - ) - } - - /// A ticket issued with early data still resumes after either public config entry point - /// disables it, and a caller's shared configs retain their original policy. - #[test] - fn supplied_configs_reject_early_data_and_keep_resumption() { - for explicit_suite in [false, true] { - let identity = rcgen::generate_simple_self_signed(vec!["localhost".to_string()]).unwrap(); - let cert = identity.cert.der().clone(); - let mut roots = rustls::RootCertStore::empty(); - roots.add(cert.clone()).unwrap(); - let mut client = rustls::ClientConfig::builder_with_provider(configured_provider()) - .with_protocol_versions(&[&rustls::version::TLS13]) - .unwrap() - .with_root_certificates(roots) - .with_no_client_auth(); - client.enable_early_data = true; - let mut server = QuicServerConfig::inner( - vec![cert], - PrivateKeyDer::Pkcs8(identity.signing_key.serialize_der().into()), - ) - .unwrap(); - server.max_early_data_size = u32::MAX; - let client = Arc::new(client); - let server = Arc::new(server); - assert_eq!( - handshake(client.clone(), server.clone()), - (rustls::HandshakeKind::Full, false, false) - ); - let wrapped_server = if explicit_suite { - QuicServerConfig::with_initial( - server.clone(), - initial_suite_from_provider(server.crypto_provider()).unwrap(), - ) - .unwrap() - } else { - QuicServerConfig::try_from(server.clone()).unwrap() - }; - assert_eq!(server.max_early_data_size, u32::MAX); - // A third-party client holds an older ticket and really offers early data. - assert_eq!( - handshake(client.clone(), wrapped_server.inner.clone()), - (rustls::HandshakeKind::Resumed, true, false) - ); - let wrapped_client = if explicit_suite { - QuicClientConfig::with_initial( - client.clone(), - initial_suite_from_provider(client.crypto_provider()).unwrap(), - ) - .unwrap() - } else { - QuicClientConfig::try_from(client.clone()).unwrap() - }; - assert!(client.enable_early_data); - assert_eq!( - handshake(wrapped_client.inner, wrapped_server.inner), - (rustls::HandshakeKind::Resumed, false, false) - ); - } - } -} diff --git a/rs/moq-quic/src/packet.rs b/rs/moq-quic/src/packet.rs index fbe53e21a9e..5831e2e374a 100644 --- a/rs/moq-quic/src/packet.rs +++ b/rs/moq-quic/src/packet.rs @@ -71,6 +71,7 @@ impl PartialDecode { self.space() == Some(SpaceId::Initial) } + /// The space whose keys protect this packet, or `None` for an unprotected or 0-RTT packet pub(crate) fn space(&self) -> Option { use ProtectedHeader::*; match self.plain_header { @@ -79,14 +80,12 @@ impl PartialDecode { ty: LongType::Handshake, .. } => Some(SpaceId::Handshake), - Long { - ty: LongType::ZeroRtt, .. - } => Some(SpaceId::Data), Short { .. } => Some(SpaceId::Data), _ => None, } } + /// Whether this is a 0-RTT packet, which is dropped unprocessed pub(crate) fn is_0rtt(&self) -> bool { match self.plain_header { ProtectedHeader::Long { ty, .. } => ty == LongType::ZeroRtt, @@ -388,9 +387,6 @@ impl Header { use Header::*; match *self { Short { .. } => SpaceId::Data, - Long { - ty: LongType::ZeroRtt, .. - } => SpaceId::Data, Long { ty: LongType::Handshake, .. diff --git a/rs/moq-quic/src/tests/characterize/frames.rs b/rs/moq-quic/src/tests/characterize/frames.rs index fa60fc0dbe4..7c32f25eca2 100644 --- a/rs/moq-quic/src/tests/characterize/frames.rs +++ b/rs/moq-quic/src/tests/characterize/frames.rs @@ -35,10 +35,10 @@ fn client_answer(frames: Frames) -> Option { } } -/// Early data is discarded without decryption, without losing a coalesced -/// Initial or a later 1-RTT stream on the same connection. +/// A 0-RTT packet is dropped before decryption, so an ACK inside it for a packet the server +/// never sent is not processed, and a coalesced Initial or 1-RTT packet is still read. #[test] -fn early_packets_leave_handshake_and_application_data_usable() { +fn zero_rtt_packets_are_dropped() { use crate::packet::{FixedLengthConnectionIdParser, Header, LongType, PacketNumber, PartialDecode}; for leading in [true, false] { let _guard = subscribe(); @@ -54,7 +54,7 @@ fn early_packets_leave_handshake_and_application_data_usable() { ) .unwrap(); let initial_header = decoded.initial_header().unwrap(); - let mut early = Vec::new(); + let mut zero_rtt = Vec::new(); let encoded = Header::Long { ty: LongType::ZeroRtt, src_cid: initial_header.src_cid, @@ -62,24 +62,26 @@ fn early_packets_leave_handshake_and_application_data_usable() { number: PacketNumber::U8(0), version: 1, } - .encode(&mut early); + .encode(&mut zero_rtt); + // Processing this ACK would be a PROTOCOL_VIOLATION: the server never sent packet 1000. + let ack = Frames::default().var(FrameType::ACK, &[1000, 0, 0, 0]); + zero_rtt.extend_from_slice(&ack.0); let keys = config .crypto .clone() .start_session(Version::V1, "localhost", &TransportParameters::default()) .unwrap() .initial_keys(initial_header.dst_cid, Side::Client); - // The ciphertext is deliberately opaque: early-data rejection precedes decryption, - // regardless of which ticket or keys the sender used. - early.resize(early.len() + 32 + keys.packet.local.tag_len(), 0xff); - encoded.finish(&mut early, &*keys.header.local, Some((0, &*keys.packet.local))); + // The keys don't matter: the drop precedes decryption. + zero_rtt.resize(zero_rtt.len() + 32 + keys.packet.local.tag_len(), 0); + encoded.finish(&mut zero_rtt, &*keys.header.local, Some((0, &*keys.packet.local))); let mut datagram = Vec::new(); if leading { - datagram.extend_from_slice(&early); + datagram.extend_from_slice(&zero_rtt); } datagram.extend_from_slice(&initial); if !leading { - datagram.extend_from_slice(&early); + datagram.extend_from_slice(&zero_rtt); } pair.server.inbound.push_front((now, ecn, datagram.as_slice().into())); pair.drive(); @@ -92,7 +94,7 @@ fn early_packets_leave_handshake_and_application_data_usable() { .client_streams(client_ch) .open(Dir::Uni, Default::default()) .unwrap(); - const DATA: &[u8] = b"after early data"; + const DATA: &[u8] = b"after 0-RTT"; client_sends( &mut pair, client_ch, @@ -100,8 +102,13 @@ fn early_packets_leave_handshake_and_application_data_usable() { Frames::default().stream(stream.into(), 0, DATA, true), ); let (now, ecn, application) = pair.server.inbound.pop_back().unwrap(); - early.extend_from_slice(&application); - pair.server.inbound.push_back((now, ecn, early.as_slice().into())); + zero_rtt.extend_from_slice(&application); + pair.server.inbound.push_back((now, ecn, zero_rtt.as_slice().into())); + let before = pair.server_conn_mut(server_ch).stats().frame_rx; + pair.drive_server(); + let after = pair.server_conn_mut(server_ch).stats().frame_rx; + assert_eq!(after.acks, before.acks); + assert_eq!(after.stream, before.stream + 1); pair.drive(); assert!(lost(pair.client_conn_mut(client_ch)).is_none()); assert!(lost(pair.server_conn_mut(server_ch)).is_none()); diff --git a/rs/moq-uring/MIGRATE.md b/rs/moq-uring/MIGRATE.md index 1b7f9489404..c47539282fc 100644 --- a/rs/moq-uring/MIGRATE.md +++ b/rs/moq-uring/MIGRATE.md @@ -6,7 +6,7 @@ How to update your code for each breaking change, newest first. ### QUIC early data is disabled -The shared moq-quic core no longer sends or accepts early data, including with caller-supplied rustls server configs. +The shared moq-quic core no longer sends early data and discards 0-RTT packets, so leave early data off in caller-supplied rustls server configs, as rustls does by default. The uring driver already returns established sessions, so no source migration is needed. TLS session tickets still enable resumed 1-RTT handshakes. diff --git a/rs/moq-uring/tests/integration/endpoint.rs b/rs/moq-uring/tests/integration/endpoint.rs index 3c9f1a5833f..ba88ae3ba7a 100644 --- a/rs/moq-uring/tests/integration/endpoint.rs +++ b/rs/moq-uring/tests/integration/endpoint.rs @@ -286,8 +286,9 @@ fn unsupported_version_is_negotiated_only_by_servers() { } sock.set_read_timeout(Some(Duration::from_secs(5)))?; - // The long-header type bits are version-specific. Use bits that mean - // 0-RTT in v1 to prove we negotiate before interpreting them. + // The long-header type bits are version-specific. These bits mean + // 0-RTT in v1, which moq-quic drops unanswered, so a reply proves we + // negotiate the version before interpreting them. let mut packet = Vec::new(); packet.push(0xD0); // long header, fixed bit, unknown-version type packet.extend_from_slice(&0x0a0a_0a0au32.to_be_bytes()); From c26bbaabf19469fa2c3c22603f59ee565d470a1b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 14:50:18 -0800 Subject: [PATCH 3/5] fix(moq-quic): skip 0-RTT packets while decoding PartialDecode::new now skips 0-RTT packets itself and decodes the packet coalesced after them, and ZeroRtt moves out of LongType into LongHeaderType, so no decoded header can hold one. That deletes is_0rtt(), the endpoint's leading-packet loop, the unprotect_header check, and the connection arm. A datagram holding only 0-RTT packets is PacketDecodeError::ZeroRtt. Co-Authored-By: Claude Opus 5.5 --- rs/moq-quic/src/connection/mod.rs | 3 - rs/moq-quic/src/connection/packet_crypto.rs | 4 - rs/moq-quic/src/endpoint.rs | 16 +- rs/moq-quic/src/fuzz.rs | 13 +- rs/moq-quic/src/packet.rs | 148 +++++++++++++------ rs/moq-quic/src/tests/characterize/frames.rs | 20 ++- rs/moq-quic/src/tests/token.rs | 2 +- 7 files changed, 133 insertions(+), 73 deletions(-) diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index bc2113a0e54..8880ad3777a 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -2972,9 +2972,6 @@ impl Connection { Header::Short { .. } => { unreachable!("short packets received during handshake are discarded in handle_packet") } - Header::Long { - ty: LongType::ZeroRtt, .. - } => unreachable!("0-RTT packets are discarded in unprotect_header"), } } diff --git a/rs/moq-quic/src/connection/packet_crypto.rs b/rs/moq-quic/src/connection/packet_crypto.rs index a11c0bd5d25..9cfd9a4b76d 100644 --- a/rs/moq-quic/src/connection/packet_crypto.rs +++ b/rs/moq-quic/src/connection/packet_crypto.rs @@ -13,10 +13,6 @@ pub(super) fn unprotect_header( spaces: &[PacketSpace; 3], stateless_reset_token: Option, ) -> Option { - if partial_decode.is_0rtt() { - trace!("discarding early data"); - return None; - } let header_crypto = if let Some(space) = partial_decode.space() { if let Some(crypto) = &spaces[space].crypto { Some(&*crypto.header.remote) diff --git a/rs/moq-quic/src/endpoint.rs b/rs/moq-quic/src/endpoint.rs index 4c417fac361..c6c43171839 100644 --- a/rs/moq-quic/src/endpoint.rs +++ b/rs/moq-quic/src/endpoint.rs @@ -155,7 +155,7 @@ impl Endpoint { } = received; // Partially decode packet or short-circuit if unable let datagram_len = data.len(); - let mut event = match PartialDecode::new( + let event = match PartialDecode::new( data, &FixedLengthConnectionIdParser::new(self.local_cid_generator.cid_len()), self.config.grease_quic_bit, @@ -214,20 +214,6 @@ impl Endpoint { } }; - // Drop leading early packets before routing or buffering, preserving a coalesced - // handshake packet after them. - while event.first_decode.is_0rtt() { - let data = event.remaining.take()?; - let (first_decode, remaining) = PartialDecode::new( - data, - &FixedLengthConnectionIdParser::new(self.local_cid_generator.cid_len()), - self.config.grease_quic_bit, - ) - .ok()?; - event.first_decode = first_decode; - event.remaining = remaining; - } - let addresses = FourTuple { remote, local_ip }; let dst_cid = event.first_decode.dst_cid(); diff --git a/rs/moq-quic/src/fuzz.rs b/rs/moq-quic/src/fuzz.rs index 08e35446261..0cd4cc46b05 100644 --- a/rs/moq-quic/src/fuzz.rs +++ b/rs/moq-quic/src/fuzz.rs @@ -52,7 +52,8 @@ pub const TARGETS: &[(&str, Target)] = &[ /// A cid length byte, a grease byte, and a datagram: the unprotected packet header. /// -/// A decoded packet and the coalesced remainder together account for every input byte. +/// The decoded packet is the bytes just before the coalesced remainder, and any bytes before +/// it start with a 0-RTT packet, which the decode skips. pub fn packet(data: &[u8]) -> bool { let [cid_len, grease, packet @ ..] = data else { return false; @@ -68,8 +69,14 @@ pub fn packet(data: &[u8]) -> bool { return false; }; - let rest = rest.map_or(0, |rest| rest.len()); - assert_eq!(len, decoded.len() + rest, "the decode lost bytes"); + let end = len - rest.map_or(0, |rest| rest.len()); + let skipped = end.checked_sub(decoded.len()).expect("the decode invented bytes"); + assert_eq!(decoded.data(), &packet[skipped..end], "the decode moved bytes"); + // A long header (0x80) with the 0-RTT type (0x10 of the type bits 0x30) + assert!( + skipped == 0 || packet[0] & 0xb0 == 0x90, + "the decode skipped a packet that is not 0-RTT" + ); true } diff --git a/rs/moq-quic/src/packet.rs b/rs/moq-quic/src/packet.rs index 5831e2e374a..ef9eff4b4f7 100644 --- a/rs/moq-quic/src/packet.rs +++ b/rs/moq-quic/src/packet.rs @@ -30,27 +30,41 @@ pub struct PartialDecode { impl PartialDecode { /// Begin decoding a QUIC packet from `bytes`, returning any trailing data not part of that packet + /// + /// 0-RTT packets are skipped unread, so the packet decoded is the first one after them. A + /// datagram holding nothing but 0-RTT packets is [`PacketDecodeError::ZeroRtt`]. pub fn new( - bytes: BytesMut, + mut bytes: BytesMut, cid_parser: &(impl ConnectionIdParser + ?Sized), grease_quic_bit: bool, ) -> Result<(Self, Option), PacketDecodeError> { - let mut buf = io::Cursor::new(bytes); - let plain_header = ProtectedHeader::decode(&mut buf, cid_parser, grease_quic_bit)?; - let dgram_len = buf.get_ref().len(); - let packet_len = plain_header - .payload_len() - .map(|len| (buf.position() + len) as usize) - .unwrap_or(dgram_len); - match dgram_len.cmp(&packet_len) { - Ordering::Equal => Ok((Self { plain_header, buf }, None)), - Ordering::Less => Err(PacketDecodeError::InvalidHeader( - "packet too short to contain payload length", - )), - Ordering::Greater => { - let rest = Some(buf.get_mut().split_off(packet_len)); - Ok((Self { plain_header, buf }, rest)) - } + loop { + let mut buf = io::Cursor::new(bytes); + let Some(plain_header) = ProtectedHeader::decode(&mut buf, cid_parser, grease_quic_bit)? else { + // `decode` consumed the whole 0-RTT packet; decode the one coalesced after it. + let skipped = buf.position() as usize; + bytes = buf.into_inner(); + bytes.advance(skipped); + if bytes.is_empty() { + return Err(PacketDecodeError::ZeroRtt); + } + continue; + }; + let dgram_len = buf.get_ref().len(); + let packet_len = plain_header + .payload_len() + .map(|len| (buf.position() + len) as usize) + .unwrap_or(dgram_len); + return match dgram_len.cmp(&packet_len) { + Ordering::Equal => Ok((Self { plain_header, buf }, None)), + Ordering::Less => Err(PacketDecodeError::InvalidHeader( + "packet too short to contain payload length", + )), + Ordering::Greater => { + let rest = Some(buf.get_mut().split_off(packet_len)); + Ok((Self { plain_header, buf }, rest)) + } + }; } } @@ -71,7 +85,7 @@ impl PartialDecode { self.space() == Some(SpaceId::Initial) } - /// The space whose keys protect this packet, or `None` for an unprotected or 0-RTT packet + /// The space whose keys protect this packet, or `None` for an unprotected packet pub(crate) fn space(&self) -> Option { use ProtectedHeader::*; match self.plain_header { @@ -85,14 +99,6 @@ impl PartialDecode { } } - /// Whether this is a 0-RTT packet, which is dropped unprocessed - pub(crate) fn is_0rtt(&self) -> bool { - match self.plain_header { - ProtectedHeader::Long { ty, .. } => ty == LongType::ZeroRtt, - _ => false, - } - } - /// The destination connection ID of the packet pub fn dst_cid(&self) -> ConnectionId { self.plain_header.dst_cid() @@ -544,11 +550,13 @@ impl ProtectedHeader { } /// Decode a plain header from given buffer, with given [`ConnectionIdParser`]. + /// + /// A 0-RTT packet is `None`, with `buf` advanced past its payload: it is dropped unread. pub fn decode( buf: &mut io::Cursor>, cid_parser: &(impl ConnectionIdParser + ?Sized), grease_quic_bit: bool, - ) -> Result { + ) -> Result, PacketDecodeError> { let first = buf.get::()?; if !grease_quic_bit && first & FIXED_BIT == 0 { return Err(PacketDecodeError::InvalidHeader("fixed bit unset")); @@ -556,10 +564,10 @@ impl ProtectedHeader { if first & LONG_HEADER_FORM == 0 { let spin = first & SPIN_BIT != 0; - Ok(Self::Short { + Ok(Some(Self::Short { spin, dst_cid: cid_parser.parse(buf)?, - }) + })) } else { let version = buf.get::()?; @@ -569,11 +577,11 @@ impl ProtectedHeader { // TODO: Support long CIDs for compatibility with future QUIC versions if version == 0 { let random = first & !LONG_HEADER_FORM; - return Ok(Self::VersionNegotiate { + return Ok(Some(Self::VersionNegotiate { random, dst_cid, src_cid, - }); + })); } if crate::Version::from_wire(version).is_none() { @@ -584,7 +592,7 @@ impl ProtectedHeader { }); } - match LongHeaderType::from_byte(first)? { + Ok(Some(match LongHeaderType::from_byte(first)? { LongHeaderType::Initial => { let token_len = buf.get_var()? as usize; let token_start = buf.position() as usize; @@ -594,27 +602,37 @@ impl ProtectedHeader { buf.advance(token_len); let len = buf.get_var()?; - Ok(Self::Initial(ProtectedInitialHeader { + Self::Initial(ProtectedInitialHeader { dst_cid, src_cid, token_pos: token_start..token_start + token_len, len, version, - })) + }) } - LongHeaderType::Retry => Ok(Self::Retry { + LongHeaderType::Retry => Self::Retry { dst_cid, src_cid, version, - }), - LongHeaderType::Standard(ty) => Ok(Self::Long { + }, + LongHeaderType::ZeroRtt => { + let len = buf.get_var()?; + if len > buf.remaining() as u64 { + return Err(PacketDecodeError::InvalidHeader( + "packet too short to contain payload length", + )); + } + buf.advance(len as usize); + return Ok(None); + } + LongHeaderType::Standard(ty) => Self::Long { ty, dst_cid, src_cid, len: buf.get_var()?, version, - }), - } + }, + })) } } } @@ -777,6 +795,8 @@ pub trait ConnectionIdParser { pub(crate) enum LongHeaderType { Initial, Retry, + /// Dropped as it is decoded, so no decoded header holds one + ZeroRtt, Standard(LongType), } @@ -786,7 +806,7 @@ impl LongHeaderType { debug_assert!(b & LONG_HEADER_FORM != 0, "not a long packet"); Ok(match (b & 0x30) >> 4 { 0x0 => Initial, - 0x1 => Standard(ZeroRtt), + 0x1 => ZeroRtt, 0x2 => Standard(Handshake), 0x3 => Retry, _ => unreachable!(), @@ -799,7 +819,7 @@ impl From for u8 { use {LongHeaderType::*, LongType::*}; match ty { Initial => LONG_HEADER_FORM | FIXED_BIT, - Standard(ZeroRtt) => LONG_HEADER_FORM | FIXED_BIT | (0x1 << 4), + ZeroRtt => LONG_HEADER_FORM | FIXED_BIT | (0x1 << 4), Standard(Handshake) => LONG_HEADER_FORM | FIXED_BIT | (0x2 << 4), Retry => LONG_HEADER_FORM | FIXED_BIT | (0x3 << 4), } @@ -811,8 +831,6 @@ impl From for u8 { pub enum LongType { /// Handshake packet Handshake, - /// 0-RTT packet - ZeroRtt, } /// Packet decode error @@ -831,6 +849,9 @@ pub enum PacketDecodeError { /// The packet header is invalid #[error("invalid header: {0}")] InvalidHeader(&'static str), + /// The datagram held only 0-RTT packets, which are dropped unread + #[error("only 0-RTT packets, which are dropped")] + ZeroRtt, } impl From for PacketDecodeError { @@ -894,6 +915,47 @@ mod tests { check_pn(PacketNumber::new(0x10000, 0), &hex!("010000")); } + /// A 0-RTT packet with a two-byte payload, version 1, and empty connection IDs + const ZERO_RTT: [u8; 10] = hex!("d0 00000001 00 00 02 aabb"); + const HANDSHAKE: [u8; 10] = hex!("e0 00000001 00 00 02 ccdd"); + const SHORT: [u8; 3] = hex!("40 0102"); + + fn decode(bytes: &[u8]) -> Result<(PartialDecode, Option), PacketDecodeError> { + PartialDecode::new(bytes.into(), &FixedLengthConnectionIdParser::new(0), false) + } + + #[test] + fn zero_rtt_alone_is_dropped() { + assert_eq!(decode(&ZERO_RTT).unwrap_err(), PacketDecodeError::ZeroRtt); + assert_eq!( + decode(&[ZERO_RTT, ZERO_RTT].concat()).unwrap_err(), + PacketDecodeError::ZeroRtt + ); + // A 0-RTT packet longer than the datagram is malformed, not skipped. + assert!(matches!( + decode(&ZERO_RTT[..9]).unwrap_err(), + PacketDecodeError::InvalidHeader(_) + )); + } + + #[test] + fn zero_rtt_coalesced_is_skipped() { + let datagram = [&ZERO_RTT[..], &HANDSHAKE, &ZERO_RTT, &ZERO_RTT, &SHORT].concat(); + let (handshake, rest) = decode(&datagram).unwrap(); + assert_eq!(handshake.data(), HANDSHAKE); + assert_eq!(handshake.space(), Some(SpaceId::Handshake)); + let rest = rest.unwrap(); + assert_eq!(rest[..], [&ZERO_RTT[..], &ZERO_RTT, &SHORT].concat()[..]); + let (short, rest) = decode(&rest).unwrap(); + assert_eq!(short.data(), SHORT); + assert!(rest.is_none()); + + // A trailing 0-RTT packet is left in the remainder, which then decodes to nothing. + let (handshake, rest) = decode(&[HANDSHAKE, ZERO_RTT].concat()).unwrap(); + assert_eq!(handshake.data(), HANDSHAKE); + assert_eq!(decode(&rest.unwrap()).unwrap_err(), PacketDecodeError::ZeroRtt); + } + #[test] fn pn_expand_roundtrip() { for expected in 0..1024 { diff --git a/rs/moq-quic/src/tests/characterize/frames.rs b/rs/moq-quic/src/tests/characterize/frames.rs index 44d6c952e00..008383462a7 100644 --- a/rs/moq-quic/src/tests/characterize/frames.rs +++ b/rs/moq-quic/src/tests/characterize/frames.rs @@ -35,11 +35,12 @@ fn client_answer(frames: Frames) -> Option { } } -/// A 0-RTT packet is dropped before decryption, so an ACK inside it for a packet the server -/// never sent is not processed, and a coalesced Initial or 1-RTT packet is still read. +/// A 0-RTT packet is dropped before decryption, alone or coalesced, so an ACK inside it for a +/// packet the server never sent is not processed, and a coalesced Initial or 1-RTT packet is +/// still read. #[test] fn zero_rtt_packets_are_dropped() { - use crate::packet::{FixedLengthConnectionIdParser, Header, LongType, PacketNumber, PartialDecode}; + use crate::packet::{FixedLengthConnectionIdParser, Header, LongHeaderType, LongType, PacketNumber, PartialDecode}; for leading in [true, false] { let _guard = subscribe(); let mut pair = pair_with(|_| {}); @@ -55,8 +56,9 @@ fn zero_rtt_packets_are_dropped() { .unwrap(); let initial_header = decoded.initial_header().unwrap(); let mut zero_rtt = Vec::new(); + // No header encodes as 0-RTT, so encode a Handshake one and retype it below. let encoded = Header::Long { - ty: LongType::ZeroRtt, + ty: LongType::Handshake, src_cid: initial_header.src_cid, dst_cid: initial_header.dst_cid, number: PacketNumber::U8(0), @@ -75,6 +77,9 @@ fn zero_rtt_packets_are_dropped() { // The keys don't matter: the drop precedes decryption. zero_rtt.resize(zero_rtt.len() + 32 + keys.packet.local.tag_len(), 0); encoded.finish(&mut zero_rtt, &*keys.header.local, Some((0, &*keys.packet.local))); + // The type bits are outside header protection. + const TYPE_BITS: u8 = 0x30; + zero_rtt[0] = zero_rtt[0] & !TYPE_BITS | u8::from(LongHeaderType::ZeroRtt) & TYPE_BITS; let mut datagram = Vec::new(); if leading { datagram.extend_from_slice(&zero_rtt); @@ -90,6 +95,13 @@ fn zero_rtt_packets_are_dropped() { assert_connected(pair.server_conn_mut(server_ch)); assert!(pair.server_streams(server_ch).accept(Dir::Uni).is_none()); + // Alone, the 0-RTT packet changes nothing. + let before = pair.server_conn_mut(server_ch).stats().frame_rx; + pair.server.inbound.push_back((now, ecn, zero_rtt.as_slice().into())); + pair.drive_server(); + assert_eq!(pair.server_conn_mut(server_ch).stats().frame_rx.acks, before.acks); + assert!(lost(pair.server_conn_mut(server_ch)).is_none()); + let stream = pair .client_streams(client_ch) .open(Dir::Uni, Default::default()) diff --git a/rs/moq-quic/src/tests/token.rs b/rs/moq-quic/src/tests/token.rs index 33a0e8bebda..d3ae7451d36 100644 --- a/rs/moq-quic/src/tests/token.rs +++ b/rs/moq-quic/src/tests/token.rs @@ -82,7 +82,7 @@ fn oversized_retry_token() { .unwrap(); let mut buf = Vec::new(); let _ = conn.poll_transmit(now, 1, &mut buf).unwrap(); - let ProtectedHeader::Initial(initial) = + let Some(ProtectedHeader::Initial(initial)) = ProtectedHeader::decode(&mut Cursor::new(&buf), &FixedLengthConnectionIdParser::new(0), false).unwrap() else { panic!("expected an Initial packet") From cfb28a66511dfda6180edb8a3bad39bd3999b96c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 15:22:20 -0800 Subject: [PATCH 4/5] fix(moq-quic): keep the rustls early-data guards rustls's QUIC ServerConnection::new rejects any max_early_data_size other than 0 or 0xffff_ffff, and start_session unwraps it, so a caller-supplied server config with a normal early-data size panicked on the first accepted connection once the guard was gone. 0xffff_ffff would also let TLS accept early data the transport discards, breaking the crypto::ServerConfig contract. The guards are not dead code, so the Plan's "otherwise keep the guard and its test" applies: restore them, their test, and the docs that describe them. Co-Authored-By: Claude Opus 5.5 --- rs/moq-quic/MIGRATE.md | 3 +- rs/moq-quic/README.md | 2 +- rs/moq-quic/src/crypto/rustls.rs | 131 ++++++++++++++++++++++++++++--- rs/moq-uring/MIGRATE.md | 2 +- 4 files changed, 125 insertions(+), 13 deletions(-) diff --git a/rs/moq-quic/MIGRATE.md b/rs/moq-quic/MIGRATE.md index 511471efc5e..ca642eda946 100644 --- a/rs/moq-quic/MIGRATE.md +++ b/rs/moq-quic/MIGRATE.md @@ -9,8 +9,7 @@ How to update your code for each breaking change, newest first. Wait for `Event::Connected` before opening streams or sending application data. `Connection::has_0rtt`, `accepted_0rtt`, and the `crypto::Session::early_crypto` and `early_data_accepted` hooks are gone. Custom crypto sessions no longer implement those hooks. -Leave early data off in caller-supplied rustls configs, as rustls does by default, since the transport discards 0-RTT packets. -Session tickets still resume 1-RTT handshakes. +Rustls configs disable early data, including caller-supplied configs, while session tickets still resume 1-RTT handshakes. ### QUIC APIs follow their consumers diff --git a/rs/moq-quic/README.md b/rs/moq-quic/README.md index 585fdf6a266..1f2df38cfda 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -43,7 +43,7 @@ Changes on top of the upstream commit, besides the renames: - **QUIC v1 only**: `Version` names the one version spoken; drafts 29 to 34, their initial salts, and their retry keys are gone, since no MoQ peer speaks them. - **Plain configs**: `transport`, `client`, `server`, and `endpoint` configs are structs with public fields instead of setters, validated when an endpoint is built or dials. `Limits` is the one spelling of the windows and stream count, at construction and on a live connection, where it also changes the stream receive window. - **Close events**: a local close reports `connection::Error::LocallyClosed` with its code and reason as the connection's `ConnectionLost`, a handshake that idles out reports `HandshakeTimeout`, and close reasons are strings, lossily decoded. -- **No early data**: rustls's default configs never offer or accept 0-RTT, and 0-RTT packets are discarded without decryption. The early keys, remembered transport parameters, stream rollback, and early-session driver APIs are removed. Session tickets still resume 1-RTT handshakes. MoQ's CONNECT and authorization already wait for the handshake. +- **No early data**: TLS never offers or accepts 0-RTT, and early packets are discarded without decryption. The early keys, remembered transport parameters, stream rollback, and early-session driver APIs are removed. Session tickets still resume 1-RTT handshakes. MoQ's CONNECT and authorization already wait for the handshake. - **BBR3**, from [quinn#2481](https://github.com/quinn-rs/quinn/pull/2481) at [`55f74c0d`](https://github.com/quinn-rs/quinn/pull/2481/commits/55f74c0dd0738b5ad7d7676c0b2869a547783f83) (open upstream), rebased onto the fork point with authorship kept. It replaces quinn's BBR and is the default controller. It carries the BBR correctness fixes moq-dev/noq shipped in `moq-noq` 1.3.1, and with them the `Controller` changes BBR needs: per-packet send and loss callbacks, `on_cwnd_limited`, `on_app_limited`, `on_ack_frequency_update`, and controller-owned pacing and burst size. `Metrics` rates are bytes per second. - **BBR3 loss samples**: a lost packet supplies its own inflight, loss, and application-limited state without borrowing or overwriting the ACK sample, including before the first ACK observation. This follows draft-06 and Google Linux BBRv3; upstream submission waits on quinn#2481 for the same callback adaptation as packet retirement. - **BBR3 packet retirement**: per-space packet lookup and round-indexed expiry retire completed snapshots incrementally, preserving the extra ACK batch of metadata for late loss callbacks. The bounded indexes handle sparse packet numbers without walking the live flight. Upstream submission is deferred while quinn#2481 remains open: this fork also carries the packet-space and loss callback adaptations, so a port needs to target that implementation after its shape settles. diff --git a/rs/moq-quic/src/crypto/rustls.rs b/rs/moq-quic/src/crypto/rustls.rs index 8698f7a7a8c..d7f0547eb42 100644 --- a/rs/moq-quic/src/crypto/rustls.rs +++ b/rs/moq-quic/src/crypto/rustls.rs @@ -265,8 +265,8 @@ pub struct HandshakeData { /// Alternatively, `QuicClientConfig`'s [`TryFrom`] implementation can be used to wrap around a /// custom [`rustls::ClientConfig`], in which case care should be taken around certain points: /// -/// TLS 1.3 is required. Leave `enable_early_data` off, its default: the transport discards -/// 0-RTT packets. The inner config's resumption cache still enables resumed 1-RTT handshakes. +/// TLS 1.3 is required. Early data is disabled, while the inner config's resumption +/// cache still enables resumed 1-RTT handshakes. /// /// [root_certs]: crate::client::Config::with_root_certificates() pub struct QuicClientConfig { @@ -291,7 +291,10 @@ impl QuicClientConfig { /// Initialize a QUIC-compatible TLS client configuration with a separate initial cipher suite /// /// This is useful if you want to avoid the initial cipher suite for traffic encryption. - pub fn with_initial(inner: Arc, initial: Suite) -> Result { + pub fn with_initial(mut inner: Arc, initial: Suite) -> Result { + if inner.enable_early_data { + Arc::make_mut(&mut inner).enable_early_data = false; + } match initial.suite.common.suite { CipherSuite::TLS13_AES_128_GCM_SHA256 => Ok(Self { inner, initial }), _ => Err(NoInitialCipherSuite { specific: true }), @@ -348,7 +351,10 @@ impl TryFrom for QuicClientConfig { impl TryFrom> for QuicClientConfig { type Error = NoInitialCipherSuite; - fn try_from(inner: Arc) -> Result { + fn try_from(mut inner: Arc) -> Result { + if inner.enable_early_data { + Arc::make_mut(&mut inner).enable_early_data = false; + } Ok(Self { initial: initial_suite_from_provider(inner.crypto_provider()) .ok_or(NoInitialCipherSuite { specific: false })?, @@ -388,8 +394,8 @@ impl std::error::Error for NoInitialCipherSuite {} /// implementation or `with_initial` method can be used to wrap around a custom /// [`rustls::ServerConfig`], in which case care should be taken around certain points: /// -/// TLS 1.3 is required. Leave `max_early_data_size` at 0, its default: the transport discards -/// 0-RTT packets. Session tickets still enable resumed 1-RTT handshakes. +/// TLS 1.3 is required. Early data is disabled, while session tickets still enable +/// resumed 1-RTT handshakes. /// /// [single]: crate::server::Config::with_single_cert() pub struct QuicServerConfig { @@ -410,7 +416,10 @@ impl QuicServerConfig { /// Initialize a QUIC-compatible TLS client configuration with a separate initial cipher suite /// /// This is useful if you want to avoid the initial cipher suite for traffic encryption. - pub fn with_initial(inner: Arc, initial: Suite) -> Result { + pub fn with_initial(mut inner: Arc, initial: Suite) -> Result { + if inner.max_early_data_size != 0 { + Arc::make_mut(&mut inner).max_early_data_size = 0; + } match initial.suite.common.suite { CipherSuite::TLS13_AES_128_GCM_SHA256 => Ok(Self { inner, initial }), _ => Err(NoInitialCipherSuite { specific: true }), @@ -419,7 +428,7 @@ impl QuicServerConfig { /// Initialize a sane QUIC-compatible TLS server configuration /// - /// TLS 1.3 is required, and rustls leaves early data disabled by default. + /// TLS 1.3 is required and early data stays disabled. pub(crate) fn inner( cert_chain: Vec>, key: PrivateKeyDer<'static>, @@ -445,7 +454,10 @@ impl TryFrom for QuicServerConfig { impl TryFrom> for QuicServerConfig { type Error = NoInitialCipherSuite; - fn try_from(inner: Arc) -> Result { + fn try_from(mut inner: Arc) -> Result { + if inner.max_early_data_size != 0 { + Arc::make_mut(&mut inner).max_early_data_size = 0; + } Ok(Self { initial: initial_suite_from_provider(inner.crypto_provider()) .ok_or(NoInitialCipherSuite { specific: false })?, @@ -573,3 +585,104 @@ fn rustls_version(version: crate::Version) -> Version { crate::Version::V1 => Version::V1, } } + +#[cfg(test)] +mod tests { + use super::*; + + fn handshake( + client: Arc, + server: Arc, + ) -> (rustls::HandshakeKind, bool, bool) { + let mut client = rustls::quic::ClientConnection::new( + client, + Version::V1, + ServerName::try_from("localhost").unwrap(), + Vec::new(), + ) + .unwrap(); + let mut server = rustls::quic::ServerConnection::new(server, Version::V1, Vec::new()).unwrap(); + let early_keys = client.zero_rtt_keys().is_some(); + loop { + let mut to_server = Vec::new(); + let _ = client.write_hs(&mut to_server); + if !to_server.is_empty() { + server.read_hs(&to_server).unwrap(); + } + let mut to_client = Vec::new(); + let _ = server.write_hs(&mut to_client); + if !to_client.is_empty() { + client.read_hs(&to_client).unwrap(); + } + if to_server.is_empty() && to_client.is_empty() { + break; + } + } + assert!(!client.is_handshaking()); + assert!(!server.is_handshaking()); + ( + client.handshake_kind().unwrap(), + early_keys, + client.is_early_data_accepted(), + ) + } + + /// A ticket issued with early data still resumes after either public config entry point + /// disables it, and a caller's shared configs retain their original policy. + #[test] + fn supplied_configs_reject_early_data_and_keep_resumption() { + for explicit_suite in [false, true] { + let identity = rcgen::generate_simple_self_signed(vec!["localhost".to_string()]).unwrap(); + let cert = identity.cert.der().clone(); + let mut roots = rustls::RootCertStore::empty(); + roots.add(cert.clone()).unwrap(); + let mut client = rustls::ClientConfig::builder_with_provider(configured_provider()) + .with_protocol_versions(&[&rustls::version::TLS13]) + .unwrap() + .with_root_certificates(roots) + .with_no_client_auth(); + client.enable_early_data = true; + let mut server = QuicServerConfig::inner( + vec![cert], + PrivateKeyDer::Pkcs8(identity.signing_key.serialize_der().into()), + ) + .unwrap(); + server.max_early_data_size = u32::MAX; + let client = Arc::new(client); + let server = Arc::new(server); + assert_eq!( + handshake(client.clone(), server.clone()), + (rustls::HandshakeKind::Full, false, false) + ); + let wrapped_server = if explicit_suite { + QuicServerConfig::with_initial( + server.clone(), + initial_suite_from_provider(server.crypto_provider()).unwrap(), + ) + .unwrap() + } else { + QuicServerConfig::try_from(server.clone()).unwrap() + }; + assert_eq!(server.max_early_data_size, u32::MAX); + // A third-party client holds an older ticket and really offers early data. + assert_eq!( + handshake(client.clone(), wrapped_server.inner.clone()), + (rustls::HandshakeKind::Resumed, true, false) + ); + let wrapped_client = if explicit_suite { + QuicClientConfig::with_initial( + client.clone(), + initial_suite_from_provider(client.crypto_provider()).unwrap(), + ) + .unwrap() + } else { + QuicClientConfig::try_from(client.clone()).unwrap() + }; + assert!(client.enable_early_data); + assert_eq!( + handshake(wrapped_client.inner, wrapped_server.inner), + (rustls::HandshakeKind::Resumed, false, false) + ); + } + } +} diff --git a/rs/moq-uring/MIGRATE.md b/rs/moq-uring/MIGRATE.md index 256e01ab3a2..b889d2beff2 100644 --- a/rs/moq-uring/MIGRATE.md +++ b/rs/moq-uring/MIGRATE.md @@ -6,7 +6,7 @@ How to update your code for each breaking change, newest first. ### QUIC early data is disabled -The shared moq-quic core no longer sends early data and discards 0-RTT packets, so leave early data off in caller-supplied rustls server configs, as rustls does by default. +The shared moq-quic core no longer sends or accepts early data, including with caller-supplied rustls server configs. The uring driver already returns established sessions, so no source migration is needed. TLS session tickets still enable resumed 1-RTT handshakes. From 82fcbcfb103c8c2fc16dee03a3c344430784f67f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 21:48:16 -0800 Subject: [PATCH 5/5] quest: unblock quic-long-type now that 0-RTT leaves LongType Co-Authored-By: Claude Opus 5.5 --- quest/m2/quic-long-type.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/quest/m2/quic-long-type.md b/quest/m2/quic-long-type.md index 6d71e79b8bf..4c3bbd00865 100644 --- a/quest/m2/quic-long-type.md +++ b/quest/m2/quic-long-type.md @@ -11,8 +11,3 @@ goes with it. Planned 2026-11-01 (maintainer, follow-up planning after the 2026-11-01 /quest-complete run). A mechanical change in `rs/moq-quic/src/packet.rs`. Keep the packet fuzz target and its regression seeds passing. -On main, `LongType` still has `ZeroRtt` until #7492 lands. - -## Required - -- [moq-quic deletes its remaining 0-RTT code](/quest/m1/quic-zero-rtt-leftovers.md) - moves 0-RTT out of `LongType`, in [moq-dev/moq#7492](https://github.com/moq-dev/moq/pull/7492)