Skip to content

Commit a88c6f9

Browse files
djcrami3l
authored andcommitted
Upgrade to rustls-platform-verifier 0.6
1 parent c170a67 commit a88c6f9

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

Cargo.lock

Lines changed: 3 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ reqwest = { version = "0.12", default-features = false, features = ["blocking",
7171
retry = { version = "2", default-features = false, features = ["random"] }
7272
rs_tracing = { version = "1.1", features = ["rs_tracing"] }
7373
rustls = { version = "0.23", optional = true, default-features = false, features = ["logging", "aws_lc_rs", "tls12"] }
74-
rustls-platform-verifier = { version = "0.5", optional = true }
74+
rustls-platform-verifier = { version = "0.6", optional = true }
7575
same-file = "1"
7676
semver = "1.0"
7777
serde = { version = "1.0", features = ["derive"] }

src/download/mod.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl TlsBackend {
386386
) -> anyhow::Result<()> {
387387
let client = match self {
388388
#[cfg(feature = "reqwest-rustls-tls")]
389-
Self::Rustls => &reqwest_be::CLIENT_RUSTLS_TLS,
389+
Self::Rustls => reqwest_be::rustls_client()?,
390390
#[cfg(feature = "reqwest-native-tls")]
391391
Self::NativeTls => &reqwest_be::CLIENT_NATIVE_TLS,
392392
};
@@ -523,10 +523,10 @@ mod curl {
523523
#[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))]
524524
mod reqwest_be {
525525
use std::io;
526-
#[cfg(feature = "reqwest-rustls-tls")]
527-
use std::sync::Arc;
528-
#[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))]
526+
#[cfg(feature = "reqwest-native-tls")]
529527
use std::sync::LazyLock;
528+
#[cfg(feature = "reqwest-rustls-tls")]
529+
use std::sync::{Arc, OnceLock};
530530
use std::time::Duration;
531531

532532
use anyhow::{Context, anyhow};
@@ -587,30 +587,36 @@ mod reqwest_be {
587587
}
588588

589589
#[cfg(feature = "reqwest-rustls-tls")]
590-
pub(super) static CLIENT_RUSTLS_TLS: LazyLock<Client> = LazyLock::new(|| {
590+
pub(super) fn rustls_client() -> Result<&'static Client, DownloadError> {
591+
if let Some(client) = CLIENT_RUSTLS_TLS.get() {
592+
return Ok(client);
593+
}
594+
591595
let mut tls_config =
592596
rustls::ClientConfig::builder_with_provider(Arc::new(aws_lc_rs::default_provider()))
593597
.with_safe_default_protocol_versions()
594598
.unwrap()
595599
.with_platform_verifier()
600+
.map_err(|err| {
601+
DownloadError::Message(format!("failed to initialize platform verifier: {err}"))
602+
})?
596603
.with_no_client_auth();
597604
tls_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
598605

599-
let catcher = || {
600-
client_generic()
601-
.use_preconfigured_tls(tls_config)
602-
.user_agent(super::REQWEST_RUSTLS_TLS_USER_AGENT)
603-
.build()
604-
};
606+
let client = client_generic()
607+
.use_preconfigured_tls(tls_config)
608+
.user_agent(super::REQWEST_RUSTLS_TLS_USER_AGENT)
609+
.build()
610+
.map_err(DownloadError::Reqwest)?;
605611

606-
// woah, an unwrap?!
607-
// It's OK. This is the same as what is happening in curl.
608-
//
609-
// The curl::Easy::new() internally assert!s that the initialized
610-
// Easy is not null. Inside reqwest, the errors here would be from
611-
// the TLS library returning a null pointer as well.
612-
catcher().unwrap()
613-
});
612+
let _ = CLIENT_RUSTLS_TLS.set(client);
613+
// "The cell is guaranteed to contain a value when `set` returns, though not necessarily
614+
// the one provided."
615+
Ok(CLIENT_RUSTLS_TLS.get().unwrap())
616+
}
617+
618+
#[cfg(feature = "reqwest-rustls-tls")]
619+
static CLIENT_RUSTLS_TLS: OnceLock<Client> = OnceLock::new();
614620

615621
#[cfg(feature = "reqwest-native-tls")]
616622
pub(super) static CLIENT_NATIVE_TLS: LazyLock<Client> = LazyLock::new(|| {

0 commit comments

Comments
 (0)