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

Replace rustls-native-certs with rustls-platform-verifier #24656

Merged
merged 4 commits into from
Feb 12, 2025
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
46 changes: 41 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ rustc-demangle = "0.1.23"
rust-embed = { version = "8.4", features = ["include-exclude"] }
rustc-hash = "2.1.0"
rustls = { version = "0.23.22" }
rustls-native-certs = "0.8.0"
rustls-platform-verifier = "0.5.0"
schemars = { version = "0.8", features = ["impl_json_schema", "indexmap2"] }
semver = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
Expand Down
2 changes: 0 additions & 2 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ postage.workspace = true
rand.workspace = true
release_channel.workspace = true
rpc = { workspace = true, features = ["gpui"] }
rustls-native-certs.workspace = true
rustls.workspace = true
schemars.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
17 changes: 1 addition & 16 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ pub fn init_settings(cx: &mut App) {
}

pub fn init(client: &Arc<Client>, cx: &mut App) {
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();

let client = Arc::downgrade(client);
cx.on_action({
let client = client.clone();
Expand Down Expand Up @@ -1126,24 +1124,11 @@ impl Client {

match url_scheme {
Https => {
let client_config = {
let mut root_store = rustls::RootCertStore::empty();

let root_certs = rustls_native_certs::load_native_certs();
for error in root_certs.errors {
log::warn!("error loading native certs: {:?}", error);
}
root_store.add_parsable_certificates(root_certs.certs);
rustls::ClientConfig::builder()
.with_root_certificates(root_store)
.with_no_client_auth()
};

let (stream, _) =
async_tungstenite::async_tls::client_async_tls_with_connector(
request,
stream,
Some(client_config.into()),
Some(http_client::tls_config().into()),
)
.await?;
Ok(Connection::new(
Expand Down
2 changes: 2 additions & 0 deletions crates/http_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ log.workspace = true
serde.workspace = true
serde_json.workspace = true
url.workspace = true
rustls.workspace = true
rustls-platform-verifier.workspace = true
21 changes: 20 additions & 1 deletion crates/http_client/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,33 @@ pub use http::{self, Method, Request, Response, StatusCode, Uri};

use futures::future::BoxFuture;
use http::request::Builder;
use rustls::ClientConfig;
use rustls_platform_verifier::ConfigVerifierExt;
#[cfg(feature = "test-support")]
use std::fmt;
use std::{
any::type_name,
sync::{Arc, Mutex},
sync::{Arc, Mutex, OnceLock},
};
pub use url::Url;

static TLS_CONFIG: OnceLock<rustls::ClientConfig> = OnceLock::new();

pub fn tls_config() -> ClientConfig {
TLS_CONFIG
.get_or_init(|| {
// rustls uses the `aws_lc_rs` provider by default
// This only errors if the default provider has already
// been installed. We can ignore this `Result`.
rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.ok();

ClientConfig::with_platform_verifier()
})
.clone()
}

#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
pub enum RedirectPolicy {
#[default]
Expand Down
5 changes: 4 additions & 1 deletion crates/reqwest_client/src/reqwest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ impl ReqwestClient {
}) {
client = client.proxy(proxy);
}
let client = client.build()?;

let client = client
.use_preconfigured_tls(http_client::tls_config())
.build()?;
let mut client: ReqwestClient = client.into();
client.proxy = proxy;
Ok(client)
Expand Down
Loading