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

use ring if no default crypto provider is found #2034

Merged
merged 4 commits into from
Nov 7, 2024
Merged
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
23 changes: 21 additions & 2 deletions tonic/src/transport/channel/service/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use hyper_util::rt::TokioIo;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_rustls::{
rustls::{
crypto,
pki_types::{ServerName, TrustAnchor},
ClientConfig, RootCertStore,
ClientConfig, ConfigBuilder, RootCertStore, WantsVerifier,
},
TlsConnector as RustlsConnector,
};
Expand Down Expand Up @@ -34,7 +35,25 @@ impl TlsConnector {
#[cfg(feature = "tls-native-roots")] with_native_roots: bool,
#[cfg(feature = "tls-webpki-roots")] with_webpki_roots: bool,
) -> Result<Self, crate::BoxError> {
let builder = ClientConfig::builder();
fn with_provider(
provider: Arc<crypto::CryptoProvider>,
) -> ConfigBuilder<ClientConfig, WantsVerifier> {
ClientConfig::builder_with_provider(provider)
.with_safe_default_protocol_versions()
.unwrap()
}

#[allow(unreachable_patterns)]
let builder = match crypto::CryptoProvider::get_default() {
Some(provider) => with_provider(provider.clone()),
#[cfg(feature = "tls-ring")]
None => with_provider(Arc::new(crypto::ring::default_provider())),
#[cfg(feature = "tls-aws-lc")]
None => with_provider(Arc::new(crypto::aws_lc_rs::default_provider())),
// somehow tls is enabled, but neither of the crypto features are enabled.
_ => ClientConfig::builder(),
};

let mut roots = RootCertStore::from_iter(trust_anchors);

#[cfg(feature = "tls-native-roots")]
Expand Down