Skip to content

Commit

Permalink
Provider-based crypto tests
Browse files Browse the repository at this point in the history
This allows the provider integration tests to be run against any crypto provider. For now, only rustls is supported. This will be updated in the future once the boringssl provider has landed.

Requires quinn-rs#1496.
  • Loading branch information
nmittler committed Mar 5, 2023
1 parent dfc1f33 commit 78b29b8
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 8 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/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
91 changes: 86 additions & 5 deletions 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,14 +247,34 @@ impl TransportParameters {
///
/// This is communicated as a transport parameter during TLS session establishment.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub(crate) struct PreferredAddress {
pub address_v4: Option<SocketAddrV4>,
pub address_v6: Option<SocketAddrV6>,
pub connection_id: ConnectionId,
pub stateless_reset_token: ResetToken,
pub struct PreferredAddress {
pub(crate) address_v4: Option<SocketAddrV4>,
pub(crate) address_v6: Option<SocketAddrV6>,
pub(crate) connection_id: ConnectionId,
pub(crate) stateless_reset_token: ResetToken,
}

impl PreferredAddress {
/// Returns the server's IPv4 address, if available.
pub fn address_v4(&self) -> Option<SocketAddrV4> {
self.address_v4.map_or(None, |addr| Some(addr))
}

/// Returns the server's IPv6 address, if available.
pub fn address_v6(&self) -> Option<SocketAddrV6> {
self.address_v6.map_or(None, |addr| Some(addr))
}

/// Returns the connection ID.
pub fn connection_id(&self) -> ConnectionId {
self.connection_id
}

/// Returns the reset token.
pub fn stateless_reset_token(&self) -> ResetToken {
self.stateless_reset_token
}

fn wire_size(&self) -> u16 {
4 + 2 + 16 + 2 + 1 + self.connection_id.len() as u16 + 16
}
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 78b29b8

Please sign in to comment.