Skip to content

Commit

Permalink
rtls: default_tls_config() explicit *ring* choice
Browse files Browse the repository at this point in the history
As mentioned in the comment, `ureq` wants to use `*ring*` by default for
`default_tls_config()`. We can avoid a risk of a panic here and make
that intention even more specific by using
`rustls::ClientConfig::builder_with_provider()` instead of
`rustls::ClientConfig::builder()` (which requires a clear process wide
default is available, or panics).
  • Loading branch information
cpu authored and algesten committed Jul 17, 2024
1 parent 7f6705b commit eae34f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Unreleased
* default `ureq` Rustls tls config updated to avoid panic for applications
that activate the default Rustls `aws-lc-rs` feature without setting
a process-wide crypto provider. `ureq` will now use `*ring*` in this
circumstance instead of panicing.

# 2.10.0
* Bump MSRV 1.61 -> 1.63 due to rustls (#764)
Expand Down
15 changes: 12 additions & 3 deletions src/rtls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,18 @@ impl TlsConnector for Arc<rustls::ClientConfig> {

pub fn default_tls_config() -> Arc<dyn TlsConnector> {
static TLS_CONF: Lazy<Arc<dyn TlsConnector>> = Lazy::new(|| {
let config = rustls::ClientConfig::builder()
.with_root_certificates(root_certs())
.with_no_client_auth();
// `ureq` prefers to use `*ring*` by default. It unconditionally activates the Rustls
// feature for this backend, so we know `rustls::crypto::ring::default_provider()` is
// available. We use `builder_with_provider()` instead of `builder()` here to avoid the
// risk that the rustls features are ambiguous and no process wide default crypto provider
// has been set yet.
let config = rustls::ClientConfig::builder_with_provider(
rustls::crypto::ring::default_provider().into(),
)
.with_protocol_versions(&[&rustls::version::TLS12, &rustls::version::TLS13])
.unwrap() // Safety: the *ring* default provider always configures ciphersuites compatible w/ both TLS 1.2 & TLS 1.3
.with_root_certificates(root_certs())
.with_no_client_auth();
Arc::new(Arc::new(config))
});
TLS_CONF.clone()
Expand Down

0 comments on commit eae34f6

Please sign in to comment.