Skip to content

Commit

Permalink
fix: client params must not include the 4 param
Browse files Browse the repository at this point in the history
  • Loading branch information
huster-zhangpeng committed Dec 9, 2024
1 parent e749964 commit 19fb45d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 93 deletions.
134 changes: 42 additions & 92 deletions qbase/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ impl Parameters {
client,
server: ServerParameters::default(),
remembered,
requirements: Requirements {
initial_source_connection_id: ConnectionId::default(),
retry_source_connection_id: None,
original_destination_connection_id: None,
},
requirements: Requirements::default(),
wakers: Vec::with_capacity(2),
}
}
Expand All @@ -70,11 +66,7 @@ impl Parameters {
client: ClientParameters::default(),
server,
remembered: None,
requirements: Requirements {
initial_source_connection_id: ConnectionId::default(),
retry_source_connection_id: None,
original_destination_connection_id: None,
},
requirements: Requirements::default(),
wakers: Vec::with_capacity(2),
}
}
Expand All @@ -87,21 +79,12 @@ impl Parameters {
}

fn remote(&self) -> Option<&CommonParameters> {
match self.role {
Role::Client => {
if self.state & Self::SERVER_READY != 0 {
Some(self.server.deref())
} else {
None
}
}
Role::Server => {
if self.state & Self::CLIENT_READY != 0 {
Some(self.client.deref())
} else {
None
}
}
if self.role == Role::Client && self.state & Self::SERVER_READY != 0 {
Some(self.server.deref())
} else if self.role == Role::Server && self.state & Self::CLIENT_READY != 0 {
Some(self.client.deref())
} else {
None
}
}

Expand Down Expand Up @@ -188,98 +171,65 @@ impl Parameters {
}

fn authenticate_cids(&self) -> Result<(), Error> {
let mut reason = None;
if self.role == Role::Client {
if self.server.initial_source_connection_id
!= self.requirements.initial_source_connection_id
{
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"Initial Source Connection ID mismatch",
));
}

if self.server.retry_source_connection_id
reason = Some("Initial Source Connection ID mismatch");
} else if self.server.retry_source_connection_id
!= self.requirements.retry_source_connection_id
{
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"Retry Source Connection ID mismatch",
));
}

if self.server.original_destination_connection_id
reason = Some("Retry Source Connection ID mismatch");
} else if self.server.original_destination_connection_id
!= self
.requirements
.original_destination_connection_id
.expect("The original_destination_connection_id transport parameter MUST be present in the Initial packet from the server")
{
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"Original Destination Connection ID mismatch",
));
reason = Some("Original Destination Connection ID mismatch");
}
} else if self.client.initial_source_connection_id
!= self.requirements.initial_source_connection_id
{
return Err(Error::new(
reason = Some("Initial Source Connection ID mismatch");
}

match reason {
Some(reason) => Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"Initial Source Connection ID mismatch",
));
reason,
)),
None => Ok(()),
}

Ok(())
}

fn validate_remote_params(&self) -> Result<(), Error> {
let remote_params = self.remote().unwrap();
if remote_params.max_udp_payload_size.into_inner() < 1200 {
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"ack_delay_exponent must be at most 20",
));
}
if remote_params.ack_delay_exponent.into_inner() > 20 {
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"ack_delay_exponent must be at most 20",
));
}
if remote_params.max_ack_delay.into_inner() > 1 << 14 {
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"max_ack_delay must be at most 2^14",
));
}
if remote_params.active_connection_id_limit.into_inner() < 2 {
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"active_connection_id_limit must be at least 2",
));
}
if remote_params.initial_max_streams_bidi.into_inner() > MAX_STREAMS_LIMIT {
return Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"active_connection_id_limit must be at least 2",
));
}
if remote_params.initial_max_streams_uni.into_inner() > MAX_STREAMS_LIMIT {
return Err(Error::new(
let reason = if remote_params.max_udp_payload_size.into_inner() < 1200 {
Some("max_udp_payload_size from peer must be at least 1200")
} else if remote_params.ack_delay_exponent.into_inner() > 20 {
Some("ack_delay_exponent from peer must be at most 20")
} else if remote_params.max_ack_delay.into_inner() > 1 << 14 {
Some("max_ack_delay from peer must be at most 2^14")
} else if remote_params.active_connection_id_limit.into_inner() < 2 {
Some("active_connection_id_limit from peer must be at least 2")
} else if remote_params.initial_max_streams_bidi.into_inner() > MAX_STREAMS_LIMIT {
Some("initial_max_streams_bidi from peer must be at most 2^60 - 1")
} else if remote_params.initial_max_streams_uni.into_inner() > MAX_STREAMS_LIMIT {
Some("initial_max_streams_uni from peer must be at most 2^60 - 1")
} else {
None
};
match reason {
Some(reason) => Err(Error::new(
ErrorKind::TransportParameter,
FrameType::Crypto,
"active_connection_id_limit must be at least 2",
));
reason,
)),
None => Ok(()),
}

Ok(())
}
}

Expand Down
7 changes: 6 additions & 1 deletion qbase/src/param/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ pub(super) fn be_client_parameters<'b>(
(input, params.max_datagram_frame_size) = be_varint(remain)?
}
ParameterId::GreaseQuicBit => (input, params.grease_quic_bit) = (remain, true),
_ => (),
_ => {
return Err(nom::Err::Failure(nom::error::Error::new(
input,
nom::error::ErrorKind::IsNot,
)))
}
}
}
Ok((input, ()))
Expand Down

0 comments on commit 19fb45d

Please sign in to comment.