From 67dbc945ba554ddf8bb3003af38d66a0fe6d3f67 Mon Sep 17 00:00:00 2001 From: edward sharp Date: Thu, 25 Jul 2024 22:25:58 -0400 Subject: [PATCH 1/3] ...stub out some stuff (not able to compile yet :feelsgood:) --- .gitignore | 1 + Cargo.lock | 336 ++++++++++++++++++++++++++++++++-- client/src/pages/Landing.css | 1 + client/src/pages/Room.css | 1 + server/Cargo.toml | 3 + server/src/main.rs | 23 +++ server/src/websocket_proxy.rs | 107 +++++++++++ 7 files changed, 454 insertions(+), 18 deletions(-) create mode 100644 server/src/websocket_proxy.rs diff --git a/.gitignore b/.gitignore index 4e213c6..d47e0bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +server/certs/ client-iced/ .env node_modules diff --git a/Cargo.lock b/Cargo.lock index 60d777d..5f1fecd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.4.3" @@ -61,6 +67,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" +[[package]] +name = "cc" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" + [[package]] name = "cfg-if" version = "1.0.0" @@ -190,13 +202,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -254,11 +266,26 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +[[package]] +name = "js-sys" +version = "0.3.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" -version = "0.2.132" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "lock_api" @@ -299,8 +326,8 @@ checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "wasi", + "windows-sys 0.36.1", ] [[package]] @@ -339,7 +366,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -450,6 +477,70 @@ version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +dependencies = [ + "base64", + "log", + "ring 0.16.20", + "sct 0.6.1", + "webpki 0.21.4", +] + +[[package]] +name = "rustls" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +dependencies = [ + "log", + "ring 0.16.20", + "sct 0.7.1", + "webpki 0.22.4", +] + +[[package]] +name = "rustls-pemfile" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" +dependencies = [ + "base64", +] + [[package]] name = "ryu" version = "1.0.5" @@ -462,6 +553,26 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +dependencies = [ + "ring 0.16.20", + "untrusted 0.7.1", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + [[package]] name = "serde" version = "1.0.126" @@ -535,6 +646,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "syn" version = "1.0.72" @@ -622,6 +745,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-rustls" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" +dependencies = [ + "rustls 0.19.1", + "tokio", + "webpki 0.21.4", +] + [[package]] name = "tokio-tungstenite" version = "0.17.2" @@ -683,6 +817,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.2.2" @@ -709,15 +855,93 @@ checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +name = "wasm-bindgen" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" + +[[package]] +name = "web-sys" +version = "0.3.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +dependencies = [ + "ring 0.16.20", + "untrusted 0.7.1", +] + +[[package]] +name = "webpki" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] [[package]] name = "winapi" @@ -756,43 +980,116 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "youoke-server" version = "0.1.0" @@ -802,9 +1099,12 @@ dependencies = [ "futures-util", "glob", "log", + "rustls 0.20.9", + "rustls-pemfile", "serde", "serde_json", "tokio", + "tokio-rustls", "tokio-tungstenite", "tungstenite", "url", diff --git a/client/src/pages/Landing.css b/client/src/pages/Landing.css index 10faf52..18520c2 100644 --- a/client/src/pages/Landing.css +++ b/client/src/pages/Landing.css @@ -1,6 +1,7 @@ .youoke { font-size: 12em; text-decoration: underline; + text-decoration-thickness: 0.25em; /* text-shadow: 2px 2px 15px #fff, 0px 0px 10px #fff; */ } diff --git a/client/src/pages/Room.css b/client/src/pages/Room.css index d15bda4..c0c2fc1 100644 --- a/client/src/pages/Room.css +++ b/client/src/pages/Room.css @@ -1,5 +1,6 @@ .room-heading { text-decoration: underline; + text-decoration-thickness: 0.25em; } input { background-color: white; diff --git a/server/Cargo.toml b/server/Cargo.toml index 090bab0..83caedd 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -12,8 +12,11 @@ tokio-tungstenite = "0.17.2" futures-channel = "0.3.23" futures-util = "0.3.23" tokio = { version = "1.20.1", features = ["full"] } +tokio-rustls = "0.22" +rustls-pemfile = "0.2" log = "0.4.17" env_logger = "0.9.0" +rustls = "0.20" url = "2.2.2" serde_json = "1.0" serde = {version = "1.0", features = ["derive"]} diff --git a/server/src/main.rs b/server/src/main.rs index 22afa79..404803d 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,3 +1,5 @@ +mod websocket_proxy; + use std::{ collections::HashMap, env, @@ -145,6 +147,27 @@ async fn main() -> Result<(), IoError> { Some(val) => val.into_string().unwrap(), None => "127.0.0.1:9001".to_string(), }; + + // websocket ssl proxy stuff + let cert_path: String = match env::var_os("CERT") { + Some(val) => val.into_string().unwrap(), + None => "certs/config/live/folk.youoke.party/fullchain.pem".to_string(), + }; + let key_path = match env::var_os("KEY") { + Some(val) => val.into_string().unwrap(), + None => "certs/config/live/folk.youoke.party/privkey.pem".to_string(), + }; + let listen_addr = "0.0.0.0:443"; + // let target_addr = "ws://127.0.0.1:8080"; // Replace with your target WebSocket server address + + websocket_proxy::start_proxy_server( + &cert_path, + &key_path, + listen_addr, + &format!("ws://{}", addr), + ) + .await; + let peer_map = PeerMap::new(Mutex::new(HashMap::new())); let queue: Vec = vec![]; diff --git a/server/src/websocket_proxy.rs b/server/src/websocket_proxy.rs new file mode 100644 index 0000000..efdec04 --- /dev/null +++ b/server/src/websocket_proxy.rs @@ -0,0 +1,107 @@ +use futures_util::stream::StreamExt; +use futures_util::SinkExt; +use rustls_pemfile::{certs, pkcs8_private_keys}; +use std::fs::File; +use std::io::{self, BufReader}; +use std::sync::Arc; +use tokio::net::{TcpListener, TcpStream}; +use tokio_rustls::rustls::{Certificate, PrivateKey, ServerConfig}; +use tokio_rustls::TlsAcceptor; +use tokio_tungstenite::accept_async; +use tokio_tungstenite::connect_async; +// use tokio_tungstenite::tungstenite::protocol::Message; +// use tokio_rustls::rustls::server::AllowAnyAuthenticatedClient; +// use rustls::server::AllowAnyAuthenticatedClient; + +pub async fn handle_connection( + stream: tokio_rustls::server::TlsStream, + target_addr: &str, +) -> Result<(), Box> { + let ws_stream = accept_async(stream).await?; + let (mut ws_sender, mut ws_receiver) = ws_stream.split(); + + let (target_ws_stream, _) = connect_async(target_addr).await?; + let (mut target_ws_sender, mut target_ws_receiver) = target_ws_stream.split(); + + let ws_to_target = async { + while let Some(message) = ws_receiver.next().await { + let message = message?; + target_ws_sender.send(message).await?; + } + Ok::<(), Box>(()) + }; + + let target_to_ws = async { + while let Some(message) = target_ws_receiver.next().await { + let message = message?; + ws_sender.send(message).await?; + } + Ok::<(), Box>(()) + }; + + tokio::select! { + res = ws_to_target => res?, + res = target_to_ws => res?, + } + + Ok(()) +} + +fn load_certs(path: &str) -> io::Result> { + let certfile = File::open(path)?; + let mut reader = BufReader::new(certfile); + let certs = certs(&mut reader) + .map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "Failed to load certificates"))? + .into_iter() + .map(Certificate) + .collect(); + Ok(certs) +} + +fn load_private_key(path: &str) -> io::Result { + let keyfile = File::open(path)?; + let mut reader = BufReader::new(keyfile); + let keys = pkcs8_private_keys(&mut reader) + .map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "Failed to load private key"))?; + if keys.is_empty() { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "No private keys found", + )); + } + Ok(PrivateKey(keys[0].clone())) +} + +pub async fn start_proxy_server( + cert_path: &str, + key_path: &str, + listen_addr: &str, + target_addr: &str, +) -> io::Result<()> { + let certs = load_certs(cert_path)?; + let key = load_private_key(key_path)?; + + // use tokio_rustls::rustls::server::AllowAnyAuthenticatedClient; + let mut config = ServerConfig::new(rustls::server::NoClientAuth::new()); + config + .set_single_cert(certs, key) + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + + let acceptor = TlsAcceptor::from(Arc::new(config)); + + let listener = TcpListener::bind(listen_addr).await?; + println!("Listening on {}", listen_addr); + + loop { + let (stream, _) = listener.accept().await?; + let acceptor = acceptor.clone(); + let target_addr = target_addr.to_string(); + + tokio::spawn(async move { + let tls_stream = acceptor.accept(stream).await.unwrap(); + if let Err(e) = handle_connection(tls_stream, &target_addr).await { + eprintln!("Error handling connection: {}", e); + } + }); + } +} From 45da3861cd0b5610ad801e150757e83d9b335c3a Mon Sep 17 00:00:00 2001 From: edward sharp Date: Thu, 25 Jul 2024 23:22:56 -0400 Subject: [PATCH 2/3] ...okay, this seemz to be working! :feelsgood: --- Cargo.lock | 69 ++++++++++++++++++++--------------- client/src/pages/Landing.tsx | 6 +-- client/src/pages/Room.tsx | 2 +- server/Cargo.toml | 2 +- server/src/main.rs | 36 +++++++++--------- server/src/websocket_proxy.rs | 2 +- 6 files changed, 65 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f1fecd..72c2c10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -516,20 +516,22 @@ dependencies = [ "base64", "log", "ring 0.16.20", - "sct 0.6.1", - "webpki 0.21.4", + "sct", + "webpki", ] [[package]] name = "rustls" -version = "0.20.9" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ "log", - "ring 0.16.20", - "sct 0.7.1", - "webpki 0.22.4", + "ring 0.17.8", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", ] [[package]] @@ -541,6 +543,23 @@ dependencies = [ "base64", ] +[[package]] +name = "rustls-pki-types" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" + +[[package]] +name = "rustls-webpki" +version = "0.102.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" +dependencies = [ + "ring 0.17.8", + "rustls-pki-types", + "untrusted 0.9.0", +] + [[package]] name = "ryu" version = "1.0.5" @@ -563,16 +582,6 @@ dependencies = [ "untrusted 0.7.1", ] -[[package]] -name = "sct" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" -dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", -] - [[package]] name = "serde" version = "1.0.126" @@ -658,6 +667,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "1.0.72" @@ -753,7 +768,7 @@ checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ "rustls 0.19.1", "tokio", - "webpki 0.21.4", + "webpki", ] [[package]] @@ -933,16 +948,6 @@ dependencies = [ "untrusted 0.7.1", ] -[[package]] -name = "webpki" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" -dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", -] - [[package]] name = "winapi" version = "0.3.9" @@ -1099,7 +1104,7 @@ dependencies = [ "futures-util", "glob", "log", - "rustls 0.20.9", + "rustls 0.22.4", "rustls-pemfile", "serde", "serde_json", @@ -1109,3 +1114,9 @@ dependencies = [ "tungstenite", "url", ] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/client/src/pages/Landing.tsx b/client/src/pages/Landing.tsx index b17891e..ac20378 100644 --- a/client/src/pages/Landing.tsx +++ b/client/src/pages/Landing.tsx @@ -11,12 +11,12 @@ export interface LandingProps { type RoomList = IRoom[] const KNOWN_ROOMS: RoomList = [ - { name: 'LOCALHOST', href: 'localhost:9001' }, - { name: 'FOLK', href: '10.246.17.194:9001' }, + { name: 'LOCALHOST', href: 'ws://localhost:9001' }, + { name: 'FOLK', href: 'wss://folk.youoke.party' }, ] function testWS(href: string): Promise { - const ws = new WebSocket(`ws://${href}`) + const ws = new WebSocket(href) return new Promise((resolve, reject) => { ws.onerror = () => reject(false) diff --git a/client/src/pages/Room.tsx b/client/src/pages/Room.tsx index 7842fe2..9a4938b 100644 --- a/client/src/pages/Room.tsx +++ b/client/src/pages/Room.tsx @@ -171,7 +171,7 @@ export default function Room(props: RoomProps) { } useEffect(() => { - ws.current = new WebSocket(`ws://${room.href}`) + ws.current = new WebSocket(room.href) ws.current.onopen = () => { setWsStatus('open') sendWsMessage('GetLibrary') diff --git a/server/Cargo.toml b/server/Cargo.toml index 83caedd..c40ceca 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -16,7 +16,7 @@ tokio-rustls = "0.22" rustls-pemfile = "0.2" log = "0.4.17" env_logger = "0.9.0" -rustls = "0.20" +rustls = "0.22" url = "2.2.2" serde_json = "1.0" serde = {version = "1.0", features = ["derive"]} diff --git a/server/src/main.rs b/server/src/main.rs index 404803d..96471ed 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -149,24 +149,26 @@ async fn main() -> Result<(), IoError> { }; // websocket ssl proxy stuff - let cert_path: String = match env::var_os("CERT") { - Some(val) => val.into_string().unwrap(), - None => "certs/config/live/folk.youoke.party/fullchain.pem".to_string(), - }; - let key_path = match env::var_os("KEY") { - Some(val) => val.into_string().unwrap(), - None => "certs/config/live/folk.youoke.party/privkey.pem".to_string(), - }; - let listen_addr = "0.0.0.0:443"; - // let target_addr = "ws://127.0.0.1:8080"; // Replace with your target WebSocket server address - - websocket_proxy::start_proxy_server( - &cert_path, - &key_path, + // let cert_path: String = match env::var_os("CERT") { + // Some(val) => val.into_string().unwrap(), + // None => "certs/config/live/folk.youoke.party/fullchain.pem".to_string(), + // }; + // let key_path = match env::var_os("KEY") { + // Some(val) => val.into_string().unwrap(), + // None => "certs/config/live/folk.youoke.party/privkey.pem".to_string(), + // }; + + let cert_path = "certs/config/live/folk.youoke.party/fullchain.pem"; + let key_path = "certs/config/live/folk.youoke.party/privkey.pem"; + let listen_addr = "0.0.0.0:443"; // note: should use 0.0.0.0 + let target_addr = "ws://127.0.0.1:9001"; // Replace with your target WebSocket server address + + tokio::task::spawn(websocket_proxy::start_proxy_server( + cert_path, + key_path, listen_addr, - &format!("ws://{}", addr), - ) - .await; + target_addr, // &format!("ws://{}", addr), + )); let peer_map = PeerMap::new(Mutex::new(HashMap::new())); let queue: Vec = vec![]; diff --git a/server/src/websocket_proxy.rs b/server/src/websocket_proxy.rs index efdec04..6fcaadc 100644 --- a/server/src/websocket_proxy.rs +++ b/server/src/websocket_proxy.rs @@ -82,7 +82,7 @@ pub async fn start_proxy_server( let key = load_private_key(key_path)?; // use tokio_rustls::rustls::server::AllowAnyAuthenticatedClient; - let mut config = ServerConfig::new(rustls::server::NoClientAuth::new()); + let mut config = ServerConfig::new(tokio_rustls::rustls::NoClientAuth::new()); config .set_single_cert(certs, key) .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; From 8dfe42e02739426016bf10eb0ebfb2e0d981ead5 Mon Sep 17 00:00:00 2001 From: edward sharp Date: Mon, 23 Dec 2024 18:02:35 -0500 Subject: [PATCH 3/3] setup USE_WSS_PROXY env var config --- server/src/main.rs | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 96471ed..397d985 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -148,27 +148,23 @@ async fn main() -> Result<(), IoError> { None => "127.0.0.1:9001".to_string(), }; - // websocket ssl proxy stuff - // let cert_path: String = match env::var_os("CERT") { - // Some(val) => val.into_string().unwrap(), - // None => "certs/config/live/folk.youoke.party/fullchain.pem".to_string(), - // }; - // let key_path = match env::var_os("KEY") { - // Some(val) => val.into_string().unwrap(), - // None => "certs/config/live/folk.youoke.party/privkey.pem".to_string(), - // }; - - let cert_path = "certs/config/live/folk.youoke.party/fullchain.pem"; - let key_path = "certs/config/live/folk.youoke.party/privkey.pem"; - let listen_addr = "0.0.0.0:443"; // note: should use 0.0.0.0 - let target_addr = "ws://127.0.0.1:9001"; // Replace with your target WebSocket server address - - tokio::task::spawn(websocket_proxy::start_proxy_server( - cert_path, - key_path, - listen_addr, - target_addr, // &format!("ws://{}", addr), - )); + // -start- websocket ssl proxy stuff + if env::var_os("USE_WSS_PROXY").is_some() { + println!("gonna start wss proxy!"); + // #TODO: make ssl proxy stuff --flag(s) for cert pathz & addrz? + let cert_path = "certs/config/live/folk.youoke.party/fullchain.pem"; + let key_path = "certs/config/live/folk.youoke.party/privkey.pem"; + let listen_addr = "0.0.0.0:443"; // note: should use 0.0.0.0 + let target_addr = "ws://127.0.0.1:9001"; // Replace with your target WebSocket server address + + tokio::task::spawn(websocket_proxy::start_proxy_server( + cert_path, + key_path, + listen_addr, + target_addr, // &format!("ws://{}", addr), + )); + } + // -end- wss proxy stuff. let peer_map = PeerMap::new(Mutex::new(HashMap::new())); let queue: Vec = vec![]; @@ -567,7 +563,7 @@ async fn download_handler( .arg(&id) // note: this handles video IDz that start with a dash (-) .output() // note: sleep for debuggin. - // let response: Request = match Command::new("sleep").arg("1").output() + // let response: Request = match Command::new("sleep").arg("1").output() { Ok(output) => { info!("download_handler yt-dlp output: {:#?}", output); @@ -582,7 +578,7 @@ async fn download_handler( "download_handler reading info json file: {}", info_filepath ); - // #TODO handle erros, here. cuz might not be a valid file (like) + // #TODO handle errors, here. cuz might not be a valid json file ;( let contents = read_to_string(info_filepath).expect( "PANIC! ...something went wrong reading info.json file!", );