Skip to content

Commit

Permalink
fixed bug where the length of the stateless reset token was not being…
Browse files Browse the repository at this point in the history
… encoded
  • Loading branch information
ilumary committed Aug 9, 2024
1 parent 92242c1 commit bc583fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
25 changes: 16 additions & 9 deletions project/src/quic/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use tokio::{
sync::{mpsc, oneshot, RwLock},
task::JoinHandle,
};
use transport_parameters::TransportConfig;
use transport_parameters::{
InitialSourceConnectionId, OriginalDestinationConnectionId, StatelessResetTokenTP,
TransportConfig,
};

const MAX_CID_SIZE: usize = 20;

Expand Down Expand Up @@ -349,14 +352,18 @@ impl Connection {
let initial_local_scid = ConnectionId::generate_with_length(8);
let orig_dcid = head.dcid.clone();

let mut tpc = transport_parameters::TransportConfig::default();
tpc.original_destination_connection_id =
transport_parameters::OriginalDestinationConnectionId::try_from(orig_dcid.clone())?;
tpc.initial_source_connection_id =
transport_parameters::InitialSourceConnectionId::try_from(initial_local_scid.clone())?;
tpc.stateless_reset_token = transport_parameters::StatelessResetTokenTP::try_from(
token::StatelessResetToken::new(&hmac_reset_key, &initial_local_scid),
)?;
let tpc = TransportConfig {
original_destination_connection_id: OriginalDestinationConnectionId::try_from(
orig_dcid.clone(),
)?,
initial_source_connection_id: InitialSourceConnectionId::try_from(
initial_local_scid.clone(),
)?,
stateless_reset_token: StatelessResetTokenTP::try_from(
token::StatelessResetToken::new(&hmac_reset_key, &initial_local_scid),
)?,
..TransportConfig::default()
};

let data = tpc.encode(Side::Server)?;

Expand Down
11 changes: 8 additions & 3 deletions project/src/quic/transport_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ impl IOHandler<StatelessResetToken> for StatelessResetToken {
token: &StatelessResetToken,
buf: &mut OctetsMut,
) -> Result<(), octets::BufferTooShortError> {
//stateless_reset_token is always 16 bytes long
buf.put_varint(0x10)?;
buf.put_bytes(&token.token)?;
Ok(())
}

fn decode(buf: &mut Octets) -> Result<StatelessResetToken, octets::BufferTooShortError> {
let length = buf.get_varint()?;
Ok(StatelessResetToken::from(
buf.get_bytes(length.try_into().unwrap())?.to_vec(),
))
if length == 16 {
return Ok(StatelessResetToken::from(
buf.get_bytes(length.try_into().unwrap())?.to_vec(),
));
}
Err(octets::BufferTooShortError)
}
}

Expand Down

0 comments on commit bc583fd

Please sign in to comment.