-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat(s2n-quic-transport): discard client initial keys when we have handshake keys #1894
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
da6390a
feat(s2n-quic-transport): discard initial sooner
WesleyRosenblum 696d8ba
Discard initial more aggressively and ensure PTO is armed
WesleyRosenblum d8bbdbc
Merge remote-tracking branch 'origin/main' into WesleyRosenblum/disca…
WesleyRosenblum 168e44a
Allow for the initial ack to be written
WesleyRosenblum 62c0414
Add integration test
WesleyRosenblum 81ded56
Assert two initial packets are sent
WesleyRosenblum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::*; | ||
use s2n_codec::EncoderBuffer; | ||
use s2n_quic_core::{ | ||
event::api::{PacketHeader, Subject}, | ||
packet::interceptor::{Interceptor, Packet}, | ||
}; | ||
|
||
/// This test ensures the PTO timer in the Handshake space is armed even | ||
/// when the client does not otherwise receive or send any handshake | ||
/// packets | ||
#[test] | ||
fn handshake_pto_timer_is_armed() { | ||
let model = Model::default(); | ||
let pto_subscriber = recorder::Pto::new(); | ||
let packet_sent_subscriber = recorder::PacketSent::new(); | ||
let pto_events = pto_subscriber.events(); | ||
let packet_sent_events = packet_sent_subscriber.events(); | ||
|
||
test(model.clone(), |handle| { | ||
let mut server = Server::builder() | ||
.with_io(handle.builder().build()?)? | ||
.with_tls(SERVER_CERTS)? | ||
.with_packet_interceptor(DropHandshakeTx)? | ||
.start()?; | ||
|
||
let addr = server.local_addr()?; | ||
spawn(async move { | ||
// We would expect this connection to time out since the server | ||
// is not able to send any handshake packets | ||
assert!(server.accept().await.is_none()); | ||
}); | ||
|
||
let client = Client::builder() | ||
.with_io(handle.builder().build().unwrap())? | ||
.with_tls(certificates::CERT_PEM)? | ||
.with_event((pto_subscriber, packet_sent_subscriber))? | ||
.start()?; | ||
|
||
primary::spawn(async move { | ||
let connect = Connect::new(addr).with_server_name("localhost"); | ||
// We would expect this connection to time out since the server | ||
// is not able to send any handshake packets | ||
assert!(client.connect(connect).await.is_err()); | ||
}); | ||
|
||
Ok(addr) | ||
}) | ||
.unwrap(); | ||
|
||
let pto_events = pto_events.lock().unwrap(); | ||
let pto_count = *pto_events.iter().max().unwrap_or(&0) as usize; | ||
|
||
// Assert that the client sent some PTOs | ||
assert!(pto_count > 0); | ||
|
||
let packet_sent_events = packet_sent_events.lock().unwrap(); | ||
let initial_packets_sent = packet_sent_events | ||
.iter() | ||
.filter(|&packet_sent| matches!(packet_sent.packet_header, PacketHeader::Initial { .. })) | ||
.count(); | ||
let handshake_packets_sent = packet_sent_events | ||
.iter() | ||
.filter(|&packet_sent| matches!(packet_sent.packet_header, PacketHeader::Handshake { .. })) | ||
.count(); | ||
|
||
// Assert that only 2 initial packets were sent (the Initial[ClientHello] and the Initial[ACK]) | ||
assert_eq!(2, initial_packets_sent); | ||
|
||
// Assert that all handshake packets that were sent were due to the PTO timer firing. | ||
// The first PTO that fires will send a single packet, since there are no packets | ||
// in flight. Subsequent PTOs will send two packets. | ||
let expected_handshake_packet_count = pto_count * 2 - 1; | ||
assert_eq!(expected_handshake_packet_count, handshake_packets_sent); | ||
} | ||
|
||
/// Drops all outgoing handshake packets | ||
struct DropHandshakeTx; | ||
|
||
impl Interceptor for DropHandshakeTx { | ||
#[inline] | ||
fn intercept_tx_payload( | ||
&mut self, | ||
_subject: &Subject, | ||
packet: &Packet, | ||
payload: &mut EncoderBuffer, | ||
) { | ||
if packet.number.space().is_handshake() { | ||
payload.set_position(0); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of this feature!