Skip to content

Commit c31a4aa

Browse files
authored
feat: websocket support self-signed TLS (#504)
* feat: websocket support self-signed TLS * chore: update release notes * chore: remove unused comments
1 parent 73ac29e commit c31a4aa

File tree

4 files changed

+35
-68
lines changed

4 files changed

+35
-68
lines changed

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Information about release notes of Coco Server is provided here.
2222
- feat: add `~/Applications` to the search path #493
2323
- feat: the chat content has added a button to return to the bottom #495
2424
- feat: the search input box supports multi-line input #501
25+
- feat: websocket support self-signed TLS #504
2526

2627
### 🐛 Bug fix
2728
- fix: several issues around search #502

src-tauri/Cargo.lock

Lines changed: 14 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ tauri-plugin-macos-permissions = "2"
6363
tauri-plugin-fs-pro = "2"
6464
tauri-plugin-screenshots = "2"
6565
applications = { git = "https://github.com/infinilabs/applications-rs", rev = "7bb507e6b12f73c96f3a52f0578d0246a689f381" }
66-
6766
tokio-native-tls = "0.3" # For wss connections
6867
tokio = { version = "1", features = ["full"] }
69-
tokio-tungstenite = { version = "0.20", features = ["rustls-tls-webpki-roots"] }
68+
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
7069
hyper = { version = "0.14", features = ["client"] }
7170
reqwest = { version = "0.12", features = ["json", "multipart"] }
7271
futures = "0.3.31"

src-tauri/src/server/websocket.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use std::sync::Arc;
55
use tauri::{AppHandle, Emitter};
66
use tokio::net::TcpStream;
77
use tokio::sync::{mpsc, Mutex};
8+
use tokio_tungstenite::tungstenite::client::IntoClientRequest;
89
use tokio_tungstenite::tungstenite::handshake::client::generate_key;
910
use tokio_tungstenite::tungstenite::Message;
11+
use tokio_tungstenite::MaybeTlsStream;
1012
use tokio_tungstenite::WebSocketStream;
11-
use tokio_tungstenite::{connect_async, MaybeTlsStream};
12-
13+
use tokio_tungstenite::{connect_async_tls_with_config, Connector};
1314
#[derive(Default)]
1415
pub struct WebSocketManager {
1516
connections: Arc<Mutex<HashMap<String, Arc<WebSocketInstance>>>>,
@@ -63,7 +64,22 @@ pub async fn connect_to_server(
6364
request.headers_mut().insert("X-API-TOKEN", token.parse().unwrap());
6465
}
6566

66-
let (ws_stream, _) = connect_async(request).await.map_err(|e| format!("WebSocket error: {:?}", e))?;
67+
let tls_connector = tokio_native_tls::native_tls::TlsConnector::builder()
68+
.danger_accept_invalid_certs(true) // 🔥 THIS IGNORES CERT VALIDATION
69+
.build()
70+
.map_err(|e| format!("TLS build error: {:?}", e))?;
71+
72+
let connector = Connector::NativeTls(tls_connector.into());
73+
74+
let (ws_stream, _) = connect_async_tls_with_config(
75+
request,
76+
None, // WebSocketConfig
77+
true, // disable_nagle
78+
Some(connector), // Connector
79+
)
80+
.await
81+
.map_err(|e| format!("WebSocket TLS error: {:?}", e))?;
82+
6783
let (cancel_tx, mut cancel_rx) = mpsc::channel(1);
6884

6985
let instance = Arc::new(WebSocketInstance {

0 commit comments

Comments
 (0)