-
Notifications
You must be signed in to change notification settings - Fork 132
Adding robustness checks to the QUIC handshake #2613
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
Open
alizohaib
wants to merge
4
commits into
mozilla:main
Choose a base branch
from
alizohaib:feat-pre-initial-noise
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dfe2293
add dummy packets before Initial packets
alizohaib d4fda8c
Merge branch 'mozilla:main' into feat-pre-initial-noise
alizohaib 4b54bfe
Apply suggestions from code review
alizohaib 6660d13
replace smallvec with vec, add comments and apply other suggestions f…
alizohaib 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 hidden or 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 hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ use neqo_common::{ | |||||
use neqo_crypto::{ | ||||||
agent::CertificateInfo, Agent, AntiReplay, AuthenticationStatus, Cipher, Client, Group, | ||||||
HandshakeState, PrivateKey, PublicKey, ResumptionToken, SecretAgentInfo, SecretAgentPreInfo, | ||||||
Server, ZeroRttChecker, | ||||||
Server, ZeroRttChecker, random, randomize, | ||||||
}; | ||||||
use smallvec::SmallVec; | ||||||
use strum::IntoEnumIterator as _; | ||||||
|
@@ -88,6 +88,11 @@ pub use crate::send_stream::{RetransmissionPriority, SendStreamStats, Transmissi | |||||
/// handshake. This is a hack, but a useful one. | ||||||
const EXTRA_INITIALS: usize = 4; | ||||||
|
||||||
/// Maximum number of noise datagrams to send before Client Initial packets. | ||||||
const MAX_PRE_INIT_NOISE_PKTS: usize = 1; | ||||||
/// Payload size range (in bytes) for pre-Initial noise datagrams: to mimic real Initial packets. | ||||||
const PRE_INIT_NOISE_LEN_RANGE: RangeInclusive<usize> = RangeInclusive::new(1200, 1400); | ||||||
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||||||
pub enum ZeroRttState { | ||||||
Init, | ||||||
|
@@ -291,6 +296,7 @@ pub struct Connection { | |||||
release_resumption_token_timer: Option<Instant>, | ||||||
conn_params: ConnectionParameters, | ||||||
hrtime: hrtime::Handle, | ||||||
pre_initial_noise_pkts: usize, | ||||||
|
||||||
/// For testing purposes it is sometimes necessary to inject frames that wouldn't | ||||||
/// otherwise be sent, just to see how a connection handles them. Inserting them | ||||||
|
@@ -351,6 +357,12 @@ impl Connection { | |||||
&mut c.stats.borrow_mut(), | ||||||
); | ||||||
c.setup_handshake_path(&Rc::new(RefCell::new(path)), now); | ||||||
|
||||||
if c.conn_params.pre_init_noise_enabled() { | ||||||
// Generate a random number between 1 and the maximum number of pre-initial packets | ||||||
c.pre_initial_noise_pkts = (usize::from(random::<1>()[0]) % MAX_PRE_INIT_NOISE_PKTS) + 1; | ||||||
} | ||||||
|
||||||
Ok(c) | ||||||
} | ||||||
|
||||||
|
@@ -437,6 +449,7 @@ impl Connection { | |||||
conn_params, | ||||||
hrtime: hrtime::Time::get(Self::LOOSE_TIMER_RESOLUTION), | ||||||
quic_datagrams, | ||||||
pre_initial_noise_pkts: 0, | ||||||
#[cfg(test)] | ||||||
test_frame_writer: None, | ||||||
}; | ||||||
|
@@ -1142,6 +1155,28 @@ impl Connection { | |||||
|
||||||
match (&self.state, self.role) { | ||||||
(State::Init, Role::Client) => { | ||||||
// Before starting the client, send some noise | ||||||
if self.pre_initial_noise_pkts > 0 { | ||||||
if let Some(path) = self.paths.primary() { | ||||||
// Choose a random payload size between the noise payload length range. | ||||||
let span = PRE_INIT_NOISE_LEN_RANGE.end() - PRE_INIT_NOISE_LEN_RANGE.start() + 1; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
let v = usize::from(random::<1>()[0]); | ||||||
let len = PRE_INIT_NOISE_LEN_RANGE.start() + (v % span); | ||||||
|
||||||
let mut dummy_buf= vec![0u8; len]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
randomize(&mut dummy_buf); | ||||||
|
||||||
let dg = Datagram::new( | ||||||
path.borrow().local_address(), | ||||||
path.borrow().remote_address(), | ||||||
IpTos::default(), | ||||||
dummy_buf, | ||||||
); | ||||||
self.pre_initial_noise_pkts -= 1; | ||||||
return Output::Datagram(dg); | ||||||
} | ||||||
} | ||||||
|
||||||
let res = self.client_start(now); | ||||||
self.absorb_error(now, res); | ||||||
} | ||||||
|
This file contains hidden or 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
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.