mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 17:18:32 +02:00
Fix "Validate TLS Certificates" option for WS and GRPC (#218)
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user