Fix "Validate TLS Certificates" option for WS and GRPC (#218)

This commit is contained in:
Andy Bao
2025-05-29 10:02:27 -04:00
committed by GitHub
parent 085b640b3c
commit bd1986f31f
17 changed files with 124 additions and 66 deletions

View File

@@ -1,7 +1,4 @@
use log::info;
use rustls::crypto::ring;
use rustls::ClientConfig;
use rustls_platform_verifier::BuilderVerifierExt;
use std::sync::Arc;
use tauri::http::HeaderMap;
use tokio::net::TcpStream;
@@ -16,14 +13,10 @@ use tokio_tungstenite::{
pub(crate) async fn ws_connect(
url: &str,
headers: HeaderMap<HeaderValue>,
validate_certificates: bool,
) -> crate::error::Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response)> {
info!("Connecting to WS {url}");
let arc_crypto_provider = Arc::new(ring::default_provider());
let config = ClientConfig::builder_with_provider(arc_crypto_provider)
.with_safe_default_protocol_versions()
.unwrap()
.with_platform_verifier()
.with_no_client_auth();
let tls_config = yaak_http::tls::get_config(validate_certificates);
let mut req = url.into_client_request()?;
let req_headers = req.headers_mut();
@@ -37,7 +30,7 @@ pub(crate) async fn ws_connect(
req,
Some(WebSocketConfig::default()),
false,
Some(Connector::Rustls(Arc::new(config))),
Some(Connector::Rustls(Arc::new(tls_config))),
)
.await?;
Ok((stream, response))