Skip to content

Commit

Permalink
Support external crypto implementations.
Browse files Browse the repository at this point in the history
These changes are needed for the BoringSSL crypto provider (#1488), which will reside in a separate repository. This required that a few things be made visible, such as the fields in TransportParameters.
  • Loading branch information
nmittler committed Feb 24, 2023
1 parent 390f2eb commit e7cdeb2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
3 changes: 2 additions & 1 deletion quinn-proto/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub trait Session: Send + 'static {
///
/// This should be called with the contents of `CRYPTO` frames. If it returns `Ok`, the
/// caller should call `write_handshake()` to check if the crypto protocol has anything
/// to send to the peer.
/// to send to the peer. This method will only return `true` the first time that
/// handshake data is available. Future calls will always return false.
///
/// On success, returns `true` iff `self.handshake_data()` has been populated.
fn read_handshake(&mut self, buf: &[u8]) -> Result<bool, TransportError>;
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod cid_generator;
pub use crate::cid_generator::{ConnectionIdGenerator, RandomConnectionIdGenerator};

mod token;
use token::{ResetToken, RetryToken};
pub use token::{ResetToken, RetryToken};

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
Expand Down
5 changes: 5 additions & 0 deletions quinn-proto/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ impl ResetToken {
result.copy_from_slice(&signature[..RESET_TOKEN_SIZE]);
result.into()
}

/// Returns an empty token.
pub fn none() -> Self {
Self([0; RESET_TOKEN_SIZE])
}
}

impl PartialEq for ResetToken {
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/transport_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct Code(u64);

impl Code {
/// Create QUIC error code from TLS alert code
pub(crate) fn crypto(code: u8) -> Self {
pub fn crypto(code: u8) -> Self {
Code(0x100 | u64::from(code))
}
}
Expand Down
67 changes: 66 additions & 1 deletion quinn-proto/src/transport_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,67 @@ macro_rules! make_struct {
pub(crate) preferred_address: Option<PreferredAddress>,
}

impl TransportParameters {
$($(#[$doc])*
#[inline]
pub fn $name (&self) -> u64 {
self.$name.0
})*

/// Does the endpoint support active connection migration
#[inline]
pub fn disable_active_migration(&self) -> bool {
self.disable_active_migration
}

/// Maximum size for datagram frames
#[inline]
pub fn max_datagram_frame_size(&self) -> Option<u64> {
self.max_datagram_frame_size.map_or(None, |x| Some(x.0))
}

/// The value that the endpoint included in the Source Connection ID field of the first
/// Initial packet it sends for the connection
#[inline]
pub fn initial_src_cid(&self) -> Option<ConnectionId> {
self.initial_src_cid
}

/// The endpoint is willing to receive QUIC packets containing any value for the fixed
/// bit
#[inline]
pub fn grease_quic_bit(&self) -> bool {
self.grease_quic_bit
}

// Server-only
/// The value of the Destination Connection ID field from the first Initial packet sent
/// by the client
#[inline]
pub fn original_dst_cid(&self) -> Option<ConnectionId> {
self.original_dst_cid
}

/// The value that the server included in the Source Connection ID field of a Retry
/// packet
#[inline]
pub fn retry_src_cid(&self) -> Option<ConnectionId> {
self.retry_src_cid
}

/// Token used by the client to verify a stateless reset from the server
#[inline]
pub fn stateless_reset_token(&self) -> Option<ResetToken> {
self.stateless_reset_token
}

/// The server's preferred address for communication after handshake completion
#[inline]
pub fn preferred_address(&self) -> Option<PreferredAddress> {
self.preferred_address
}
}

impl Default for TransportParameters {
/// Standard defaults, used if the peer does not supply a given parameter.
fn default() -> Self {
Expand Down Expand Up @@ -186,10 +247,14 @@ impl TransportParameters {
///
/// This is communicated as a transport parameter during TLS session establishment.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub(crate) struct PreferredAddress {
pub struct PreferredAddress {
/// The server's IPv4 address.
pub address_v4: Option<SocketAddrV4>,
/// The server's IPv6 address.
pub address_v6: Option<SocketAddrV6>,
/// The connection ID.
pub connection_id: ConnectionId,
/// The reset token.
pub stateless_reset_token: ResetToken,
}

Expand Down
3 changes: 2 additions & 1 deletion quinn/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ impl Endpoint {
Self::new_with_runtime(config, server_config, Box::new(socket), Arc::new(runtime))
}

fn new_with_runtime(
/// Construct an endpoint with arbitrary configuration and pre-constructed async socket.
pub fn new_with_runtime(
config: EndpointConfig,
server_config: Option<ServerConfig>,
socket: Box<dyn AsyncUdpSocket>,
Expand Down

0 comments on commit e7cdeb2

Please sign in to comment.