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

feat: use webpki as rustls roots on non-desktop platforms #1402

Merged
merged 2 commits into from
Dec 5, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- [core] Fix "no native root CA certificates found" on platforms unsupported
by `rustls-native-certs`.

### Removed

## [0.6.0] - 2024-10-30
Expand Down
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ http = "1.0"
hyper = { version = "1.3", features = ["http1", "http2"] }
hyper-util = { version = "0.1", features = ["client"] }
http-body-util = "0.1.1"
hyper-proxy2 = { version = "0.1", default-features = false, features = ["rustls"] }
hyper-rustls = { version = "0.27.2", features = ["http2"] }
log = "0.4"
nonzero_ext = "0.3"
num-bigint = { version = "0.4", features = ["rand"] }
Expand All @@ -58,12 +56,23 @@ thiserror = "1.0"
time = { version = "0.3", features = ["formatting", "parsing"] }
tokio = { version = "1", features = ["io-util", "macros", "net", "parking_lot", "rt", "sync", "time"] }
tokio-stream = "0.1"
tokio-tungstenite = { version = "0.24", default-features = false, features = ["rustls-tls-native-roots"] }
tokio-util = { version = "0.7", features = ["codec"] }
url = "2"
uuid = { version = "1", default-features = false, features = ["fast-rng", "v4"] }
data-encoding = "2.5"

# Eventually, this should use rustls-platform-verifier to unify the platform-specific dependencies
# but currently, hyper-proxy2 and tokio-tungstenite do not support it.
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
hyper-proxy2 = { version = "0.1", default-features = false, features = ["rustls"] }
hyper-rustls = { version = "0.27.2", default-features = false, features = ["aws-lc-rs", "http1", "logging", "tls12", "native-tokio", "http2"] }
tokio-tungstenite = { version = "0.24", default-features = false, features = ["rustls-tls-native-roots"] }

[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))'.dependencies]
hyper-proxy2 = { version = "0.1", default-features = false, features = ["rustls-webpki"] }
hyper-rustls = { version = "0.27.2", default-features = false, features = ["aws-lc-rs", "http1", "logging", "tls12", "webpki-tokio", "http2"] }
tokio-tungstenite = { version = "0.24", default-features = false, features = ["rustls-tls-webpki-roots"] }

[build-dependencies]
rand = "0.8"
vergen-gitcl = { version = "1.0.0", default-features = false, features = ["build"] }
Expand Down
16 changes: 10 additions & 6 deletions core/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ impl HttpClient {

fn try_create_hyper_client(proxy_url: Option<&Url>) -> Result<HyperClient, Error> {
// configuring TLS is expensive and should be done once per process
let https_connector = HttpsConnectorBuilder::new()
.with_native_roots()?
.https_or_http()
.enable_http1()
.enable_http2()
.build();

// On supported platforms, use native roots
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
let tls = HttpsConnectorBuilder::new().with_native_roots()?;

// Otherwise, use webpki roots
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
let tls = HttpsConnectorBuilder::new().with_webpki_roots();

let https_connector = tls.https_or_http().enable_http1().enable_http2().build();

// When not using a proxy a dummy proxy is configured that will not intercept any traffic.
// This prevents needing to carry the Client Connector generics through the whole project
Expand Down
Loading