Skip to content
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

config/server: add token_key to avoid randomization of handshake token #201

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading