Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the final RFC9369 version of QUIC v2 #1515

Merged
merged 3 commits into from
Dec 14, 2023
Merged
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
6 changes: 3 additions & 3 deletions neqo-transport/src/connection/tests/vn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ fn invalid_current_version_client() {
assert_ne!(OTHER_VERSION, client.version());
client
.set_local_tparam(
tparams::VERSION_NEGOTIATION,
tparams::VERSION_INFORMATION,
TransportParameter::Versions {
current: OTHER_VERSION.wire_version(),
other: Version::all()
Expand Down Expand Up @@ -394,7 +394,7 @@ fn invalid_current_version_server() {
assert!(!Version::default().is_compatible(OTHER_VERSION));
server
.set_local_tparam(
tparams::VERSION_NEGOTIATION,
tparams::VERSION_INFORMATION,
TransportParameter::Versions {
current: OTHER_VERSION.wire_version(),
other: vec![OTHER_VERSION.wire_version()],
Expand All @@ -420,7 +420,7 @@ fn no_compatible_version() {
assert_ne!(OTHER_VERSION, client.version());
client
.set_local_tparam(
tparams::VERSION_NEGOTIATION,
tparams::VERSION_INFORMATION,
TransportParameter::Versions {
current: Version::default().wire_version(),
other: vec![OTHER_VERSION.wire_version()],
Expand Down
8 changes: 4 additions & 4 deletions neqo-transport/src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,9 +1170,9 @@ mod tests {
}

const SAMPLE_RETRY_V2: &[u8] = &[
0xcf, 0x70, 0x9a, 0x50, 0xc4, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x1d, 0xc7, 0x11, 0x30, 0xcd, 0x1e, 0xd3, 0x9d, 0x6e, 0xfc,
0xee, 0x5c, 0x85, 0x80, 0x65, 0x01,
0xcf, 0x6b, 0x33, 0x43, 0xcf, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0xc8, 0x64, 0x6c, 0xe8, 0xbf, 0xe3, 0x39, 0x52, 0xd9, 0x55,
0x54, 0x36, 0x65, 0xdc, 0xc7, 0xb6,
];

const SAMPLE_RETRY_V1: &[u8] = &[
Expand Down Expand Up @@ -1353,7 +1353,7 @@ mod tests {

const SAMPLE_VN: &[u8] = &[
0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, 0x08,
0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08, 0x70, 0x9a, 0x50, 0xc4, 0x00, 0x00, 0x00,
0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08, 0x6b, 0x33, 0x43, 0xcf, 0x00, 0x00, 0x00,
0x01, 0xff, 0x00, 0x00, 0x20, 0xff, 0x00, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x1e, 0xff, 0x00,
0x00, 0x1d, 0x0a, 0x0a, 0x0a, 0x0a,
];
Expand Down
29 changes: 13 additions & 16 deletions neqo-transport/src/tparams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ tpids! {
ACTIVE_CONNECTION_ID_LIMIT = 0x0e,
INITIAL_SOURCE_CONNECTION_ID = 0x0f,
RETRY_SOURCE_CONNECTION_ID = 0x10,
VERSION_INFORMATION = 0x11,
GREASE_QUIC_BIT = 0x2ab2,
MIN_ACK_DELAY = 0xff02_de1a,
MAX_DATAGRAM_FRAME_SIZE = 0x0020,
VERSION_NEGOTIATION = 0xff73db,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -298,7 +298,7 @@ impl TransportParameter {
_ => return Err(Error::TransportParameterError),
},

VERSION_NEGOTIATION => Self::decode_versions(&mut d)?,
VERSION_INFORMATION => Self::decode_versions(&mut d)?,

// Skip.
_ => return Ok(None),
Expand Down Expand Up @@ -450,15 +450,15 @@ impl TransportParameters {
}
let current = versions.initial().wire_version();
self.set(
VERSION_NEGOTIATION,
VERSION_INFORMATION,
TransportParameter::Versions { current, other },
);
}

fn compatible_upgrade(&mut self, v: Version) {
if let Some(TransportParameter::Versions {
ref mut current, ..
}) = self.params.get_mut(&VERSION_NEGOTIATION)
}) = self.params.get_mut(&VERSION_INFORMATION)
{
*current = v.wire_version();
} else {
Expand Down Expand Up @@ -543,7 +543,7 @@ impl TransportParameters {
#[must_use]
pub fn get_versions(&self) -> Option<(WireVersion, &[WireVersion])> {
if let Some(TransportParameter::Versions { current, other }) =
self.params.get(&VERSION_NEGOTIATION)
self.params.get(&VERSION_INFORMATION)
{
Some((*current, other))
} else {
Expand Down Expand Up @@ -1043,21 +1043,20 @@ mod tests {
#[test]
fn versions_encode_decode() {
const ENCODED: &[u8] = &[
0x80, 0xff, 0x73, 0xdb, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x1a, 0x2a, 0x3a, 0x4a, 0x5a,
0x6a, 0x7a, 0x8a,
0x11, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x1a, 0x2a, 0x3a, 0x4a, 0x5a, 0x6a, 0x7a, 0x8a,
];
let vn = TransportParameter::Versions {
current: Version::Version1.wire_version(),
other: vec![0x1a2a_3a4a, 0x5a6a_7a8a],
};

let mut enc = Encoder::new();
vn.encode(&mut enc, VERSION_NEGOTIATION);
vn.encode(&mut enc, VERSION_INFORMATION);
assert_eq!(enc.as_ref(), ENCODED);

let mut dec = enc.as_decoder();
let (id, decoded) = TransportParameter::decode(&mut dec).unwrap().unwrap();
assert_eq!(id, VERSION_NEGOTIATION);
assert_eq!(id, VERSION_INFORMATION);
assert_eq!(decoded, vn);
}

Expand All @@ -1076,10 +1075,8 @@ mod tests {

#[test]
fn versions_zero() {
const ZERO1: &[u8] = &[0x80, 0xff, 0x73, 0xdb, 0x04, 0x00, 0x00, 0x00, 0x00];
const ZERO2: &[u8] = &[
0x80, 0xff, 0x73, 0xdb, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
];
const ZERO1: &[u8] = &[0x11, 0x04, 0x00, 0x00, 0x00, 0x00];
const ZERO2: &[u8] = &[0x11, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00];

let mut dec = Decoder::from(&ZERO1);
assert_eq!(
Expand All @@ -1097,7 +1094,7 @@ mod tests {
fn versions_equal_0rtt() {
let mut current = TransportParameters::default();
current.set(
VERSION_NEGOTIATION,
VERSION_INFORMATION,
TransportParameter::Versions {
current: Version::Version1.wire_version(),
other: vec![0x1a2a_3a4a],
Expand All @@ -1112,7 +1109,7 @@ mod tests {

// If the version matches, it's OK to use 0-RTT.
remembered.set(
VERSION_NEGOTIATION,
VERSION_INFORMATION,
TransportParameter::Versions {
current: Version::Version1.wire_version(),
other: vec![0x5a6a_7a8a, 0x9aaa_baca],
Expand All @@ -1123,7 +1120,7 @@ mod tests {

// An apparent "upgrade" is still cause to reject 0-RTT.
remembered.set(
VERSION_NEGOTIATION,
VERSION_INFORMATION,
TransportParameter::Versions {
current: Version::Version1.wire_version() + 1,
other: vec![],
Expand Down
24 changes: 12 additions & 12 deletions neqo-transport/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Version {
impl Version {
pub const fn wire_version(self) -> WireVersion {
match self {
Self::Version2 => 0x709a50c4,
Self::Version2 => 0x6b3343cf,
Self::Version1 => 1,
Self::Draft29 => 0xff00_0000 + 29,
Self::Draft30 => 0xff00_0000 + 30,
Expand All @@ -34,8 +34,8 @@ impl Version {

pub(crate) fn initial_salt(self) -> &'static [u8] {
const INITIAL_SALT_V2: &[u8] = &[
0xa7, 0x07, 0xc2, 0x03, 0xa5, 0x9b, 0x47, 0x18, 0x4a, 0x1d, 0x62, 0xca, 0x57, 0x04,
0x06, 0xea, 0x7a, 0xe3, 0xe5, 0xd3,
0x0d, 0xed, 0xe3, 0xde, 0xf7, 0x00, 0xa6, 0xdb, 0x81, 0x93, 0x81, 0xbe, 0x6e, 0x26,
0x9d, 0xcb, 0xf9, 0xbd, 0x2e, 0xd9,
];
const INITIAL_SALT_V1: &[u8] = &[
0x38, 0x76, 0x2c, 0xf7, 0xf5, 0x59, 0x34, 0xb3, 0x4d, 0x17, 0x9a, 0xe6, 0xa4, 0xc8,
Expand All @@ -62,20 +62,20 @@ impl Version {
}

pub(crate) fn retry_secret(self) -> &'static [u8] {
const RETRY_SECRET_29: &[u8] = &[
0x8b, 0x0d, 0x37, 0xeb, 0x85, 0x35, 0x02, 0x2e, 0xbc, 0x8d, 0x76, 0xa2, 0x07, 0xd8,
0x0d, 0xf2, 0x26, 0x46, 0xec, 0x06, 0xdc, 0x80, 0x96, 0x42, 0xc3, 0x0a, 0x8b, 0xaa,
0x2b, 0xaa, 0xff, 0x4c,
const RETRY_SECRET_V2: &[u8] = &[
0xc4, 0xdd, 0x24, 0x84, 0xd6, 0x81, 0xae, 0xfa, 0x4f, 0xf4, 0xd6, 0x9c, 0x2c, 0x20,
0x29, 0x99, 0x84, 0xa7, 0x65, 0xa5, 0xd3, 0xc3, 0x19, 0x82, 0xf3, 0x8f, 0xc7, 0x41,
0x62, 0x15, 0x5e, 0x9f,
];
const RETRY_SECRET_V1: &[u8] = &[
0xd9, 0xc9, 0x94, 0x3e, 0x61, 0x01, 0xfd, 0x20, 0x00, 0x21, 0x50, 0x6b, 0xcc, 0x02,
0x81, 0x4c, 0x73, 0x03, 0x0f, 0x25, 0xc7, 0x9d, 0x71, 0xce, 0x87, 0x6e, 0xca, 0x87,
0x6e, 0x6f, 0xca, 0x8e,
];
const RETRY_SECRET_V2: &[u8] = &[
0x34, 0x25, 0xc2, 0x0c, 0xf8, 0x87, 0x79, 0xdf, 0x2f, 0xf7, 0x1e, 0x8a, 0xbf, 0xa7,
0x82, 0x49, 0x89, 0x1e, 0x76, 0x3b, 0xbe, 0xd2, 0xf1, 0x3c, 0x04, 0x83, 0x43, 0xd3,
0x48, 0xc0, 0x60, 0xe2,
const RETRY_SECRET_29: &[u8] = &[
0x8b, 0x0d, 0x37, 0xeb, 0x85, 0x35, 0x02, 0x2e, 0xbc, 0x8d, 0x76, 0xa2, 0x07, 0xd8,
0x0d, 0xf2, 0x26, 0x46, 0xec, 0x06, 0xdc, 0x80, 0x96, 0x42, 0xc3, 0x0a, 0x8b, 0xaa,
0x2b, 0xaa, 0xff, 0x4c,
];
match self {
Self::Version2 => RETRY_SECRET_V2,
Expand Down Expand Up @@ -131,7 +131,7 @@ impl TryFrom<WireVersion> for Version {
fn try_from(wire: WireVersion) -> Res<Self> {
if wire == 1 {
Ok(Self::Version1)
} else if wire == 0x709a50c4 {
} else if wire == 0x6b3343cf {
Ok(Self::Version2)
} else if wire == 0xff00_0000 + 29 {
Ok(Self::Draft29)
Expand Down
Loading
Loading