Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

cloud_api_client: Use the platform TLS verifier for the cloud websocket (#63686)

Joep Joosten12f79c0aeb86
diff --git a/Cargo.lock b/Cargo.lock
index 3ec313424cd..8ca061356c8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3213,10 +3213,12 @@ dependencies = [
"gpui",
"gpui_tokio",
"http_client",
+ "http_client_tls",
"parking_lot",
"serde",
"serde_json",
"thiserror 2.0.17",
+ "tokio-rustls 0.26.4",
"yawc",
]
diff --git a/Cargo.toml b/Cargo.toml
index abec5e2530a..1a61f86114d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -870,6 +870,7 @@ time = { version = "0.3", features = [
] }
tiny_http = "0.12"
tokio = { version = "1" }
+tokio-rustls = { version = "0.26", default-features = false }
toml = "0.8"
toml_edit = { version = "0.22", default-features = false, features = [
"display",
diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml
index f2892ba6114..3ae702edbe4 100644
--- a/crates/client/Cargo.toml
+++ b/crates/client/Cargo.toml
@@ -83,4 +83,4 @@ tokio-native-tls = "0.3"
[target.'cfg(not(any(target_os = "windows", target_os = "macos")))'.dependencies]
rustls-pki-types = "1.12"
-tokio-rustls = { version = "0.26", features = ["tls12", "ring"], default-features = false }
+tokio-rustls = { workspace = true, features = ["tls12", "ring"] }
diff --git a/crates/cloud_api_client/Cargo.toml b/crates/cloud_api_client/Cargo.toml
index 64f8fa80ee2..5c3fa97615e 100644
--- a/crates/cloud_api_client/Cargo.toml
+++ b/crates/cloud_api_client/Cargo.toml
@@ -34,3 +34,5 @@ async-lock.workspace = true
[target.'cfg(not(target_family = "wasm"))'.dependencies]
gpui_tokio.workspace = true
+http_client_tls.workspace = true
+tokio-rustls.workspace = true
diff --git a/crates/cloud_api_client/src/websocket/native.rs b/crates/cloud_api_client/src/websocket/native.rs
index e2d4b68aca7..a341c04c276 100644
--- a/crates/cloud_api_client/src/websocket/native.rs
+++ b/crates/cloud_api_client/src/websocket/native.rs
@@ -1,3 +1,4 @@
+use std::sync::Arc;
use std::time::Duration;
use anyhow::{Context as _, Result, anyhow};
@@ -8,6 +9,7 @@ use futures::{FutureExt as _, SinkExt as _, StreamExt as _, TryStreamExt as _};
use futures_lite::future::yield_now;
use gpui::{App, AppContext, Task};
use http_client::http::request;
+use tokio_rustls::TlsConnector;
use yawc::frame::Frame;
use yawc::{TcpWebSocket, WebSocket};
@@ -80,7 +82,12 @@ impl CloudApiClient {
let authorization_header = format!("{} {}", credentials.user_id, credentials.access_token);
Ok(gpui_tokio::Tokio::spawn_result(cx, async move {
+ // Use the same TLS configuration as the rest of Zed (the platform
+ // certificate verifier), instead of yawc's default connector which only
+ // trusts the bundled webpki roots and ignores the system trust store.
+ let tls_connector = TlsConnector::from(Arc::new(http_client_tls::tls_config()));
let websocket = WebSocket::connect(connect_url)
+ .with_connector(tls_connector)
.with_request(
request::Builder::new()
.header("Authorization", authorization_header)