-
-
Notifications
You must be signed in to change notification settings - Fork 796
Send flights of handshake messages in single message #2120
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,14 @@ use pki_types::CertificateDer; | |
| use crate::crypto::SupportedKxGroup; | ||
| use crate::enums::{AlertDescription, ContentType, HandshakeType, ProtocolVersion}; | ||
| use crate::error::{Error, InvalidMessage, PeerMisbehaved}; | ||
| use crate::hash_hs::HandshakeHash; | ||
| use crate::log::{debug, error, warn}; | ||
| use crate::msgs::alert::AlertMessagePayload; | ||
| use crate::msgs::base::Payload; | ||
| use crate::msgs::codec::Codec; | ||
| use crate::msgs::enums::{AlertLevel, KeyUpdateRequest}; | ||
| use crate::msgs::fragmenter::MessageFragmenter; | ||
| use crate::msgs::handshake::CertificateChain; | ||
| use crate::msgs::handshake::{CertificateChain, HandshakeMessagePayload}; | ||
| use crate::msgs::message::{ | ||
| Message, MessagePayload, OutboundChunks, OutboundOpaqueMessage, OutboundPlainMessage, | ||
| PlainMessage, | ||
|
|
@@ -432,7 +434,10 @@ impl CommonState { | |
| self.quic.alert = Some(alert.description); | ||
| } else { | ||
| debug_assert!( | ||
| matches!(m.payload, MessagePayload::Handshake { .. }), | ||
| matches!( | ||
| m.payload, | ||
| MessagePayload::Handshake { .. } | MessagePayload::HandshakeFlight(_) | ||
| ), | ||
| "QUIC uses TLS for the cryptographic handshake only" | ||
| ); | ||
| let mut bytes = Vec::new(); | ||
|
|
@@ -974,5 +979,42 @@ impl KxState { | |
| } | ||
| } | ||
|
|
||
| pub(crate) struct HandshakeFlight<'a, const TLS13: bool> { | ||
| pub(crate) transcript: &'a mut HandshakeHash, | ||
| body: Vec<u8>, | ||
| } | ||
|
|
||
| impl<'a, const TLS13: bool> HandshakeFlight<'a, TLS13> { | ||
| pub(crate) fn new(transcript: &'a mut HandshakeHash) -> Self { | ||
| Self { | ||
| transcript, | ||
| body: Vec::new(), | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn add(&mut self, hs: HandshakeMessagePayload<'_>) { | ||
| let start_len = self.body.len(); | ||
| hs.encode(&mut self.body); | ||
| self.transcript | ||
| .add(&self.body[start_len..]); | ||
| } | ||
|
|
||
| pub(crate) fn finish(self, common: &mut CommonState) { | ||
| common.send_msg( | ||
| Message { | ||
| version: match TLS13 { | ||
| true => ProtocolVersion::TLSv1_3, | ||
| false => ProtocolVersion::TLSv1_2, | ||
| }, | ||
| payload: MessagePayload::HandshakeFlight(Payload::new(self.body)), | ||
| }, | ||
| TLS13, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| pub(crate) type HandshakeFlightTls12<'a> = HandshakeFlight<'a, false>; | ||
|
Member
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. Is the TLS 1.2 use-case landed alongside the new types to avoid dead code warnings? I think this diff would be easier to digest if it were separated out like the TLS 1.3 case but I wager that might produce warnings and I don't feel very strongly.
Member
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. In general, not sure I'm convinced of the benefit of this type alias.
Member
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. I think the type alias is mildly useful in so much as
Member
Author
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. Yes I would like to avoid the true/false thing leaking out of this file, as far as possible. My second choice would be to stop this type being generic like this, and just have two different constructors (eg, |
||
| pub(crate) type HandshakeFlightTls13<'a> = HandshakeFlight<'a, true>; | ||
|
|
||
| const DEFAULT_RECEIVED_PLAINTEXT_LIMIT: usize = 16 * 1024; | ||
| pub(crate) const DEFAULT_BUFFER_LIMIT: usize = 64 * 1024; | ||
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.
I briefly considered the restrictiveness of the const generic bool here vs something more expressive but decided it was premature optimization and this seems quite reasonable after all.