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

proto: avoid panicking on rustls server config errors #1977

Merged
merged 1 commit into from
Sep 2, 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
2 changes: 1 addition & 1 deletion quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ impl ServerConfig {
) -> Result<Self, rustls::Error> {
Ok(Self::with_crypto(Arc::new(QuicServerConfig::new(
cert_chain, key,
))))
)?)))
}
}

Expand Down
15 changes: 7 additions & 8 deletions quinn-proto/src/crypto/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ impl QuicServerConfig {
pub(crate) fn new(
cert_chain: Vec<CertificateDer<'static>>,
key: PrivateKeyDer<'static>,
) -> Self {
let inner = Self::inner(cert_chain, key);
Self {
) -> Result<Self, rustls::Error> {
let inner = Self::inner(cert_chain, key)?;
Ok(Self {
// We're confident that the *ring* default provider contains TLS13_AES_128_GCM_SHA256
initial: initial_suite_from_provider(inner.crypto_provider())
.expect("no initial cipher suite found"),
inner: Arc::new(inner),
}
})
}

/// Initialize a QUIC-compatible TLS client configuration with a separate initial cipher suite
Expand All @@ -445,18 +445,17 @@ impl QuicServerConfig {
pub(crate) fn inner(
cert_chain: Vec<CertificateDer<'static>>,
key: PrivateKeyDer<'static>,
) -> rustls::ServerConfig {
) -> Result<rustls::ServerConfig, rustls::Error> {
let mut inner = rustls::ServerConfig::builder_with_provider(
rustls::crypto::ring::default_provider().into(),
)
.with_protocol_versions(&[&rustls::version::TLS13])
.unwrap() // The *ring* default provider supports TLS 1.3
.with_no_client_auth()
.with_single_cert(cert_chain, key)
.unwrap();
.with_single_cert(cert_chain, key)?;

inner.max_early_data_size = u32::MAX;
inner
Ok(inner)
}
}

Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ fn server_crypto_inner(
)
});

let mut config = QuicServerConfig::inner(vec![cert], key);
let mut config = QuicServerConfig::inner(vec![cert], key).unwrap();
if let Some(alpn) = alpn {
config.alpn_protocols = alpn;
}
Expand Down