Skip to content

Commit

Permalink
config/server: add token_key to avoid randomization of handshake token
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear authored and BiagioFesta committed Aug 21, 2024
1 parent bd82e3b commit 3fdbfc3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions wtransport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ allowed_external_types = [
"quinn_proto::config::ServerConfig",
"quinn_proto::config::TransportConfig",
"quinn_proto::connection::ConnectionError",
"quinn_proto::crypto::HandshakeTokenKey",
"rustls",
"rustls::webpki::anchors::RootCertStore",
"rustls::client::client_conn::ClientConfig",
Expand Down
17 changes: 16 additions & 1 deletion wtransport/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ impl ServerConfigBuilder<states::WantsIdentity> {
bind_address: self.0.bind_address,
dual_stack_config: self.0.dual_stack_config,
tls_config,
token_key: None,
transport_config,
migration: true,
})
Expand All @@ -499,7 +500,11 @@ impl ServerConfigBuilder<states::WantsTransportConfigServer> {
quinn::crypto::rustls::QuicServerConfig::try_from(self.0.tls_config)
.expect("CipherSuite::TLS13_AES_128_GCM_SHA256 missing"),
);
let mut quic_config = QuicServerConfig::with_crypto(crypto);
let mut quic_config = if let Some(token_key) = self.0.token_key {
QuicServerConfig::new(crypto, token_key)
} else {
QuicServerConfig::with_crypto(crypto)
};

quic_config.transport_config(Arc::new(self.0.transport_config));
quic_config.migration(self.0.migration);
Expand Down Expand Up @@ -553,6 +558,15 @@ impl ServerConfigBuilder<states::WantsTransportConfigServer> {
self
}

/// Use `Some` to use specific handshake token key instead of a random one.
///
/// Allows reloading the configuration without invalidating in-flight retry tokens.
#[cfg(feature = "quinn")]
pub fn token_key(mut self, value: Option<Arc<dyn quinn::crypto::HandshakeTokenKey>>) -> Self {
self.0.token_key = value;
self
}

/// Writes key material for debugging into file provided by `SSLKEYLOGFILE` environment variable.
///
/// Disabled by default.
Expand Down Expand Up @@ -1071,6 +1085,7 @@ pub mod states {
pub(super) bind_address: SocketAddr,
pub(super) dual_stack_config: Ipv6DualStackConfig,
pub(super) tls_config: TlsServerConfig,
pub(super) token_key: Option<Arc<dyn quinn::crypto::HandshakeTokenKey>>,
pub(super) transport_config: quinn::TransportConfig,
pub(super) migration: bool,
}
Expand Down

0 comments on commit 3fdbfc3

Please sign in to comment.