From 15555561f018fea7b2d37436ebe1aae958732c9b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 03:12:18 -0800 Subject: [PATCH 1/4] chore(quest): claim quest/a1/rind/qmux.md Quest-Claim: 65a4b92ae94c6918 From 8e1f41eac0137ee2d63cd87d4bc49b48c2bd945b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 03:48:50 -0800 Subject: [PATCH 2/4] feat(qmux)!: use rind for default WSS TLS Disable implicit rustls providers, preserve caller connectors, and build default WSS configs from the installed provider or rind with native roots. Cover TLS and WSS handshakes, provider selection, and fallible CPU refusal. --- quest/a1/rind/README.md | 1 - quest/a1/rind/qmux.md | 11 -- rs/qmux/Cargo.toml | 17 ++- rs/qmux/README.md | 20 +++ rs/qmux/src/error.rs | 5 + rs/qmux/src/ws.rs | 153 +++++++++++++++++++-- rs/qmux/tests/tls.rs | 298 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 482 insertions(+), 23 deletions(-) delete mode 100644 quest/a1/rind/qmux.md create mode 100644 rs/qmux/tests/tls.rs diff --git a/quest/a1/rind/README.md b/quest/a1/rind/README.md index 5c4e7a52..586bd847 100644 --- a/quest/a1/rind/README.md +++ b/quest/a1/rind/README.md @@ -36,7 +36,6 @@ Decision prompts (✅ chosen): - [Quinn on rind](/quest/a1/rind/quinn.md) - provider-neutral QUIC crypto adapter; Quinn, FFI, Node and router on rind - [Noq on rind](/quest/a1/rind/noq.md) - Noq's rustls without ring, with rind keys - [iroh on rind](/quest/a1/rind/iroh.md) - iroh endpoint built with rind's provider -- [QMux on rind](/quest/a1/rind/qmux.md) - TLS and WSS paths with no aws-lc-rs ## Related diff --git a/quest/a1/rind/qmux.md b/quest/a1/rind/qmux.md deleted file mode 100644 index fc4c8737..00000000 --- a/quest/a1/rind/qmux.md +++ /dev/null @@ -1,11 +0,0 @@ -# [S] Run QMux's TLS and WSS paths on rind - -## Goal - -qmux's `tls` and `wss` features compile no aws-lc-rs or ring. A connection the caller doesn't configure runs on rind-rustls, and one the caller configures keeps their `rustls` config. - -## Plan - -Today aws-lc-rs comes in through qmux's own `rustls` and `tokio-rustls` dependencies (both with default features) and through `tokio-tungstenite/rustls-tls-native-roots`, which enables rustls's default provider. Depend on rustls and tokio-rustls with `default-features = false`, and pick tokio-tungstenite features that bring no provider. Where qmux or tungstenite would build a default `ClientConfig` (a WSS connect with no connector), build it on the installed process provider, else rind, with native roots. A CPU rind refuses returns an error. - -Check every qmux feature combination with `cargo tree -e normal,build -i aws-lc-sys` and `-i ring`. `tls::Client`/`tls::Server` always take a caller config, so they get no default. Test a TLS handshake with a caller config built on rind, and a WSS handshake with no caller config. Whether to also change the `qmux-v0.5.x` line is a separate decision, not part of this quest. diff --git a/rs/qmux/Cargo.toml b/rs/qmux/Cargo.toml index c45e0b89..0f88e161 100644 --- a/rs/qmux/Cargo.toml +++ b/rs/qmux/Cargo.toml @@ -20,17 +20,25 @@ tcp = ["tokio/net", "tokio/io-util"] uds = ["tokio/net", "tokio/io-util"] tls = ["tcp", "dep:tokio-rustls", "dep:rustls"] ws = ["dep:tokio-tungstenite", "dep:futures"] -wss = ["ws", "dep:rustls", "tokio-tungstenite/rustls-tls-native-roots"] +wss = [ + "ws", + "dep:rind-rustls", + "dep:rustls", + "dep:rustls-native-certs", + "tokio-tungstenite/rustls-tls-native-roots", +] [dependencies] bytes = "1" futures = { version = "0.3", optional = true } -rustls = { version = "0.23", optional = true } +rind-rustls = { version = "0.23", optional = true } +rustls = { version = "0.23", default-features = false, features = ["logging", "std", "tls12"], optional = true } +rustls-native-certs = { version = "0.8", optional = true } thiserror = "2" tokio = { version = "1.27", features = ["sync", "time", "macros", "rt"] } # Optional: TLS -tokio-rustls = { version = "0.26", optional = true } +tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "tls12"], optional = true } # Optional: WebSocket tokio-tungstenite = { version = "0.30", optional = true } @@ -44,7 +52,10 @@ libc = "0.2" [dev-dependencies] anyhow = "1" +rcgen = "0.14" +rind-rustls = "0.23" tokio = { version = "1.27", features = ["full", "test-util"] } +tokio-rustls = { version = "0.26", default-features = false, features = ["tls12"] } url = "2" web-transport-proto = { workspace = true } web-transport-trait = { workspace = true } diff --git a/rs/qmux/README.md b/rs/qmux/README.md index 57baf91f..3f1ade27 100644 --- a/rs/qmux/README.md +++ b/rs/qmux/README.md @@ -23,6 +23,26 @@ qmux = "0.6" Default features: `tls`, `wss` +### TLS crypto + +TLS and WSS dependencies enable no ring or aws-lc-rs provider. `tls::Client` +and `tls::Server` require caller-built rustls configs; their provider, trust +store, and client authentication settings are preserved. The TLS client clones +its config to set QMux ALPNs, leaving the caller's original unchanged. + +For WSS without an explicit `ws::Client::with_connector`, QMux uses native +certificate roots and the process's installed rustls provider, otherwise rind +through rind-rustls. It does not install a process-wide provider. Root-loading +or configuration errors fail the connection. Plain WebSockets do not load roots +or select a TLS provider. + +The `wss` feature builds on x86_64, aarch64, and 32-bit ARM and requires Rust +1.90 or newer. `ws::Client::new()` stays infallible; `connect()` returns +`Error::UnsupportedCpu` when rind refuses the CPU. An installed provider or an +explicit connector bypasses the fallback and its runtime CPU check. Code that +previously relied on QMux enabling a rustls provider feature must build its +configs with `rustls::ClientConfig::builder_with_provider` or install a provider. + ## Usage The crate root holds the transport-independent session API — `Session`, diff --git a/rs/qmux/src/error.rs b/rs/qmux/src/error.rs index 1d10aa77..abed2009 100644 --- a/rs/qmux/src/error.rs +++ b/rs/qmux/src/error.rs @@ -88,6 +88,11 @@ pub enum Error { #[error("invalid server name")] InvalidServerName, + /// A CPU feature required by the default WSS crypto provider is unavailable. + #[cfg(feature = "wss")] + #[error("unsupported CPU: {0}")] + UnsupportedCpu(String), + /// The server rejected the handshake with a non-success HTTP status. /// /// Surfaced from the WebSocket upgrade response so callers can distinguish diff --git a/rs/qmux/src/ws.rs b/rs/qmux/src/ws.rs index 7223458f..9d5b4a3d 100644 --- a/rs/qmux/src/ws.rs +++ b/rs/qmux/src/ws.rs @@ -21,6 +21,27 @@ pub use tokio_tungstenite; /// [`Error::WebSocket`] wraps a `tungstenite::Error`. pub use tokio_tungstenite::tungstenite; +#[cfg(feature = "wss")] +fn default_provider() -> Result, Error> { + if let Some(provider) = rustls::crypto::CryptoProvider::get_default() { + return Ok(provider.clone()); + } + #[cfg(test)] + if REFUSE_CPU.get() { + return Err(Error::UnsupportedCpu( + "simulated missing CPU feature".into(), + )); + } + rind_rustls::default_provider() + .map(std::sync::Arc::new) + .map_err(|err| Error::UnsupportedCpu(err.to_string())) +} + +#[cfg(all(test, feature = "wss"))] +thread_local! { + static REFUSE_CPU: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + /// Keep-alive configuration for WebSocket transports. /// /// WebSocket has no built-in idle timeout: when the peer's host crashes @@ -246,12 +267,51 @@ impl Client { } /// Set the TLS connector for secure WebSocket connections. + /// + /// The connector and its TLS config are used unchanged. Without one, WSS + /// uses native roots and the installed rustls provider, otherwise rind. #[cfg(feature = "wss")] pub fn with_connector(mut self, connector: tokio_tungstenite::Connector) -> Self { self.connector = Some(connector); self } + #[cfg(feature = "wss")] + fn connector( + &self, + uri: &tungstenite::http::Uri, + ) -> Result, Error> { + if self.connector.is_some() || uri.scheme_str() != Some("wss") { + return Ok(self.connector.clone()); + } + + use std::{io, sync::Arc}; + let provider = default_provider()?; + let loaded = rustls_native_certs::load_native_certs(); + if let Some(err) = loaded.errors.into_iter().next() { + return Err(io::Error::new(io::ErrorKind::InvalidData, err).into()); + } + let mut roots = rustls::RootCertStore::empty(); + for cert in loaded.certs { + roots + .add(cert) + .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; + } + if roots.is_empty() { + return Err(io::Error::new( + io::ErrorKind::NotFound, + "no native root CA certificates found", + ) + .into()); + } + let config = rustls::ClientConfig::builder_with_provider(provider) + .with_safe_default_protocol_versions() + .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))? + .with_root_certificates(roots) + .with_no_client_auth(); + Ok(Some(tokio_tungstenite::Connector::Rustls(Arc::new(config)))) + } + /// Connect to a WebSocket server, negotiating an advertised `(alpn, version)`. pub async fn connect(&self, url: &str) -> Result { use tungstenite::{client::IntoClientRequest, http}; @@ -276,14 +336,10 @@ impl Client { #[cfg(feature = "wss")] let (ws_stream, response) = { - tokio_tungstenite::connect_async_tls_with_config( - request, - self.config, - false, - self.connector.clone(), - ) - .await - .map_err(Error::from)? + let connector = self.connector(request.uri())?; + tokio_tungstenite::connect_async_tls_with_config(request, self.config, false, connector) + .await + .map_err(Error::from)? }; #[cfg(not(feature = "wss"))] @@ -487,3 +543,84 @@ impl Server { Ok(Session::new(transport, true, config)) } } + +#[cfg(all(test, feature = "wss"))] +mod crypto_tests { + use super::*; + use std::sync::Arc; + use web_transport_trait::Session as _; + + #[tokio::test] + async fn installed_provider_and_cpu_refusal() { + const CHILD: &str = "QMUX_PROVIDER_TEST_CHILD"; + if std::env::var_os(CHILD).is_none() { + let output = std::process::Command::new(std::env::current_exe().unwrap()) + .args([ + "--exact", + "ws::crypto_tests::installed_provider_and_cpu_refusal", + ]) + .env(CHILD, "1") + .output() + .unwrap(); + assert!(output.status.success(), "{output:?}"); + return; + } + assert!(rustls::crypto::CryptoProvider::get_default().is_none()); + let provider = default_provider().unwrap(); + let config = Arc::new( + rustls::ClientConfig::builder_with_provider(provider.clone()) + .with_safe_default_protocol_versions() + .unwrap() + .with_root_certificates(rustls::RootCertStore::empty()) + .with_no_client_auth(), + ); + struct Reset; + impl Drop for Reset { + fn drop(&mut self) { + REFUSE_CPU.set(false); + } + } + let _reset = Reset; + REFUSE_CPU.set(true); + assert!(matches!( + Client::new().connect("wss://localhost:1/").await, + Err(Error::UnsupportedCpu(_)) + )); + let uri = "wss://localhost/".parse().unwrap(); + let client = + Client::new().with_connector(tokio_tungstenite::Connector::Rustls(config.clone())); + let Some(tokio_tungstenite::Connector::Rustls(preserved)) = client.connector(&uri).unwrap() + else { + panic!("caller connector was replaced"); + }; + assert!(Arc::ptr_eq(&preserved, &config)); + let client = Client::new().with_connector(tokio_tungstenite::Connector::Plain); + assert!(matches!( + client.connector(&uri).unwrap(), + Some(tokio_tungstenite::Connector::Plain) + )); + + // Plain WS must still connect without consulting the refused fallback. + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let addr = listener.local_addr().unwrap(); + let accept = tokio::spawn(async move { + let (socket, _) = listener.accept().await.unwrap(); + Server::new().accept(socket).await.unwrap() + }); + let session = Client::new() + .connect(&format!("ws://{addr}/")) + .await + .unwrap(); + let server = accept.await.unwrap(); + session.close(0, "done"); + server.close(0, "done"); + + (*provider).clone().install_default().unwrap(); + let installed = rustls::crypto::CryptoProvider::get_default().unwrap(); + assert!(Arc::ptr_eq(&default_provider().unwrap(), installed)); + assert!( + REFUSE_CPU.get(), + "installed provider bypasses the rind CPU check" + ); + } +} diff --git a/rs/qmux/tests/tls.rs b/rs/qmux/tests/tls.rs new file mode 100644 index 00000000..2d1a9cb9 --- /dev/null +++ b/rs/qmux/tests/tls.rs @@ -0,0 +1,298 @@ +//! TLS and WSS establish authenticated QMux sessions without a process provider. + +#![cfg(any(feature = "tls", feature = "wss"))] + +use std::{sync::Arc, time::Duration}; + +use qmux::{Session, Version}; +use rustls::pki_types::{CertificateDer, PrivatePkcs8KeyDer}; +use tokio::net::TcpListener; +use web_transport_trait::{RecvStream as _, SendStream as _, Session as _}; + +fn certificate() -> (CertificateDer<'static>, PrivatePkcs8KeyDer<'static>, String) { + let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap(); + ( + cert.cert.der().clone(), + PrivatePkcs8KeyDer::from(cert.signing_key.serialize_der()), + cert.cert.pem(), + ) +} + +async fn exchange(client: Session, server: Session) { + assert_eq!(client.protocol(), Some("test")); + assert_eq!(server.protocol(), Some("test")); + for (sender, receiver) in [(&client, &server), (&server, &client)] { + let mut stream = sender.open_uni().await.unwrap(); + stream.write(b"authenticated payload").await.unwrap(); + stream.finish().unwrap(); + let mut stream = receiver.accept_uni().await.unwrap(); + assert_eq!( + stream.read_all().await.unwrap(), + b"authenticated payload"[..] + ); + } + client.close(0, "done"); + server.close(0, "done"); +} + +#[cfg(feature = "tls")] +#[tokio::test] +async fn tls_preserves_caller_configs() { + tokio::time::timeout(Duration::from_secs(10), async { + assert!(rustls::crypto::CryptoProvider::get_default().is_none()); + for version in [&rustls::version::TLS12, &rustls::version::TLS13] { + let (cert, key, _) = certificate(); + let provider = Arc::new(rind_rustls::default_provider().unwrap()); + let mut roots = rustls::RootCertStore::empty(); + roots.add(cert.clone()).unwrap(); + let verifier = rustls::server::WebPkiClientVerifier::builder_with_provider( + Arc::new(roots.clone()), + provider.clone(), + ) + .build() + .unwrap(); + let mut server = rustls::ServerConfig::builder_with_provider(provider.clone()) + .with_protocol_versions(&[version]) + .unwrap() + .with_client_cert_verifier(verifier) + .with_single_cert(vec![cert.clone()], key.clone_key().into()) + .unwrap(); + server.alpn_protocols = vec![b"qmux-02.test".to_vec()]; + let mut client = rustls::ClientConfig::builder_with_provider(provider) + .with_protocol_versions(&[version]) + .unwrap() + .with_root_certificates(roots) + .with_client_auth_cert(vec![cert], key.into()) + .unwrap(); + client.alpn_protocols = vec![b"caller-owned".to_vec()]; + let client = Arc::new(client); + let server = Arc::new(server); + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let addr = listener.local_addr().unwrap(); + let acceptor = qmux::tls::Server::new(server.clone()); + let accept = tokio::spawn(async move { + let (socket, _) = listener.accept().await.unwrap(); + acceptor.accept(socket).await.unwrap() + }); + let session = qmux::tls::Client::new(client.clone()) + .with_protocol("test", &[Version::QMux02]) + .require_protocol() + .connect(addr, "localhost") + .await + .unwrap(); + exchange(session, accept.await.unwrap()).await; + assert_eq!(client.alpn_protocols, [b"caller-owned".to_vec()]); + assert_eq!(server.alpn_protocols, [b"qmux-02.test".to_vec()]); + } + assert!(rustls::crypto::CryptoProvider::get_default().is_none()); + }) + .await + .unwrap(); +} + +#[cfg(feature = "wss")] +#[test] +fn wss_native_roots_and_caller_config() { + // Root overrides are process-wide, so each case gets a fresh process. + const CHILD: &str = "QMUX_WSS_TEST_CHILD"; + if std::env::var_os(CHILD).is_none() { + let (_, key, pem) = certificate(); + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.tmp") + .join(format!("qmux-wss-{}", std::process::id())); + std::fs::create_dir_all(dir.join("empty")).unwrap(); + std::fs::write(dir.join("root.pem"), pem).unwrap(); + std::fs::write(dir.join("key.der"), key.secret_pkcs8_der()).unwrap(); + std::fs::write(dir.join("empty.pem"), "").unwrap(); + std::fs::write( + dir.join("malformed.pem"), + "-----BEGIN CERTIFICATE-----\nAAAA\n-----END CERTIFICATE-----\n", + ) + .unwrap(); + for case in [ + "default", + "installed", + "invalid-provider", + "untrusted", + "wrong-name", + "custom", + "empty", + "missing", + "malformed", + ] { + let output = std::process::Command::new(std::env::current_exe().unwrap()) + .args([ + "--exact", + "wss_native_roots_and_caller_config", + "--nocapture", + ]) + .env(CHILD, case) + .env("QMUX_WSS_TEST_DIR", &dir) + .env( + "SSL_CERT_FILE", + dir.join(match case { + "custom" | "empty" => "empty.pem", + "missing" => "missing.pem", + "malformed" => "malformed.pem", + _ => "root.pem", + }), + ) + .env("SSL_CERT_DIR", dir.join("empty")) + .output() + .unwrap(); + assert!(output.status.success(), "{case}: {output:?}"); + } + std::fs::remove_dir_all(dir).unwrap(); + return; + } + tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap() + .block_on(async { + tokio::time::timeout(Duration::from_secs(10), wss_handshake()) + .await + .unwrap(); + }); +} + +#[cfg(feature = "wss")] +async fn wss_handshake() { + use qmux::ws::{self, tokio_tungstenite::Connector}; + use rustls::pki_types::pem::PemObject as _; + + assert!(rustls::crypto::CryptoProvider::get_default().is_none()); + let case = std::env::var("QMUX_WSS_TEST_CHILD").unwrap(); + if case == "invalid-provider" { + let mut provider = rind_rustls::default_provider().unwrap(); + provider.cipher_suites.clear(); + provider.install_default().unwrap(); + let err = ws::Client::new() + .connect("wss://localhost:1/") + .await + .err() + .unwrap(); + let qmux::Error::Io(err) = err else { + panic!("{err:?}") + }; + assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput); + return; + } + if matches!(case.as_str(), "empty" | "missing" | "malformed") { + let err = ws::Client::new() + .connect("wss://localhost:1/") + .await + .err() + .unwrap(); + let qmux::Error::Io(err) = err else { + panic!("{case}: {err:?}") + }; + assert_eq!( + err.kind(), + if case == "empty" { + std::io::ErrorKind::NotFound + } else { + std::io::ErrorKind::InvalidData + } + ); + return; + } + let dir = std::path::PathBuf::from(std::env::var_os("QMUX_WSS_TEST_DIR").unwrap()); + let cert = CertificateDer::from_pem_file(dir.join("root.pem")).unwrap(); + let key = PrivatePkcs8KeyDer::from(std::fs::read(dir.join("key.der")).unwrap()); + if case == "installed" { + let mut provider = rind_rustls::default_provider().unwrap(); + provider + .cipher_suites + .retain(|suite| suite.suite() == rustls::CipherSuite::TLS13_CHACHA20_POLY1305_SHA256); + provider.install_default().unwrap(); + } + let provider = Arc::new(rind_rustls::default_provider().unwrap()); + let mut roots = rustls::RootCertStore::empty(); + roots.add(cert.clone()).unwrap(); + let server = rustls::ServerConfig::builder_with_provider(provider.clone()) + .with_safe_default_protocol_versions() + .unwrap(); + let server = if case == "custom" { + let verifier = rustls::server::WebPkiClientVerifier::builder_with_provider( + Arc::new(roots.clone()), + provider.clone(), + ) + .build() + .unwrap(); + server.with_client_cert_verifier(verifier) + } else { + server.with_no_client_auth() + }; + let (server_cert, server_key) = if case == "untrusted" { + let (cert, key, _) = certificate(); + (cert, key) + } else { + (cert.clone(), key.clone_key()) + }; + let server = server + .with_single_cert(vec![server_cert], server_key.into()) + .unwrap(); + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let addr = listener.local_addr().unwrap(); + let installed = case == "installed"; + let accept = tokio::spawn(async move { + let (socket, _) = listener.accept().await.unwrap(); + let socket = tokio_rustls::TlsAcceptor::from(Arc::new(server)) + .accept(socket) + .await?; + if installed { + assert_eq!( + socket + .get_ref() + .1 + .negotiated_cipher_suite() + .unwrap() + .suite(), + rustls::CipherSuite::TLS13_CHACHA20_POLY1305_SHA256 + ); + } + ws::Server::new() + .with_protocol("test", &[Version::QMux02]) + .require_protocol() + .accept(socket) + .await + }); + let mut client = ws::Client::new() + .with_protocol("test", &[Version::QMux02]) + .require_protocol(); + let mut caller_config = None; + if case == "custom" { + let mut config = rustls::ClientConfig::builder_with_provider(provider) + .with_safe_default_protocol_versions() + .unwrap() + .with_root_certificates(roots) + .with_client_auth_cert(vec![cert], key.into()) + .unwrap(); + config.alpn_protocols = vec![b"caller-owned".to_vec()]; + let config = Arc::new(config); + client = client.with_connector(Connector::Rustls(config.clone())); + caller_config = Some(config); + } + let host = if case == "wrong-name" { + "127.0.0.1" + } else { + "localhost" + }; + let result = client + .connect(&format!("wss://{host}:{}/", addr.port())) + .await; + if case == "untrusted" || case == "wrong-name" { + assert!(result.is_err(), "{case} certificate was accepted"); + assert!(accept.await.unwrap().is_err()); + } else { + exchange(result.unwrap(), accept.await.unwrap().unwrap()).await; + } + if let Some(config) = caller_config { + assert_eq!(config.alpn_protocols, [b"caller-owned".to_vec()]); + } + assert_eq!( + rustls::crypto::CryptoProvider::get_default().is_some(), + case == "installed" + ); +} From 3d094f32893a31b25af0c9df5370c44237cc47fc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 04:01:54 -0800 Subject: [PATCH 3/4] fix(qmux): preserve usable native trust anchors Retain native-root best-effort loading, cover partial stores, declare the rind MSRV, and clean handshake fixtures before reporting child failures. --- rs/qmux/Cargo.toml | 1 + rs/qmux/README.md | 7 ++++--- rs/qmux/src/ws.rs | 17 +++++++++------- rs/qmux/tests/tls.rs | 46 +++++++++++++++++++++++++++++--------------- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/rs/qmux/Cargo.toml b/rs/qmux/Cargo.toml index 0f88e161..6cfbbe18 100644 --- a/rs/qmux/Cargo.toml +++ b/rs/qmux/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT OR Apache-2.0" version = "0.6.6" edition = "2021" +rust-version = "1.90" keywords = ["quic", "qmux", "webtransport", "multiplexing"] categories = ["network-programming"] diff --git a/rs/qmux/README.md b/rs/qmux/README.md index 3f1ade27..73478722 100644 --- a/rs/qmux/README.md +++ b/rs/qmux/README.md @@ -32,9 +32,10 @@ its config to set QMux ALPNs, leaving the caller's original unchanged. For WSS without an explicit `ws::Client::with_connector`, QMux uses native certificate roots and the process's installed rustls provider, otherwise rind -through rind-rustls. It does not install a process-wide provider. Root-loading -or configuration errors fail the connection. Plain WebSockets do not load roots -or select a TLS provider. +through rind-rustls. It does not install a process-wide provider. Native roots +load on a best-effort basis: loading errors and unusable certificates are logged, +and the connection fails if no usable root remains or the provider configuration +is invalid. Plain WebSockets do not load roots or select a TLS provider. The `wss` feature builds on x86_64, aarch64, and 32-bit ARM and requires Rust 1.90 or newer. `ws::Client::new()` stays infallible; `connect()` returns diff --git a/rs/qmux/src/ws.rs b/rs/qmux/src/ws.rs index 9d5b4a3d..0c6504e7 100644 --- a/rs/qmux/src/ws.rs +++ b/rs/qmux/src/ws.rs @@ -288,19 +288,22 @@ impl Client { use std::{io, sync::Arc}; let provider = default_provider()?; let loaded = rustls_native_certs::load_native_certs(); - if let Some(err) = loaded.errors.into_iter().next() { - return Err(io::Error::new(io::ErrorKind::InvalidData, err).into()); + if !loaded.errors.is_empty() { + tracing::warn!(errors = ?loaded.errors, "native root CA certificate loading errors"); } let mut roots = rustls::RootCertStore::empty(); - for cert in loaded.certs { - roots - .add(cert) - .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; + // OS stores can contain unusable entries; retain every valid trust anchor. + let (_, ignored) = roots.add_parsable_certificates(loaded.certs); + if ignored != 0 { + tracing::warn!(ignored, "ignored malformed native root CA certificates"); } if roots.is_empty() { return Err(io::Error::new( io::ErrorKind::NotFound, - "no native root CA certificates found", + format!( + "no native root CA certificates found (errors: {:?})", + loaded.errors + ), ) .into()); } diff --git a/rs/qmux/tests/tls.rs b/rs/qmux/tests/tls.rs index 2d1a9cb9..a38eb053 100644 --- a/rs/qmux/tests/tls.rs +++ b/rs/qmux/tests/tls.rs @@ -101,6 +101,13 @@ fn wss_native_roots_and_caller_config() { .join("../../.tmp") .join(format!("qmux-wss-{}", std::process::id())); std::fs::create_dir_all(dir.join("empty")).unwrap(); + std::fs::create_dir_all(dir.join("roots")).unwrap(); + std::fs::write(dir.join("roots/root.pem"), &pem).unwrap(); + std::fs::write( + dir.join("partial.pem"), + format!("{pem}-----BEGIN CERTIFICATE-----\nAAAA\n-----END CERTIFICATE-----\n"), + ) + .unwrap(); std::fs::write(dir.join("root.pem"), pem).unwrap(); std::fs::write(dir.join("key.der"), key.secret_pkcs8_der()).unwrap(); std::fs::write(dir.join("empty.pem"), "").unwrap(); @@ -109,7 +116,7 @@ fn wss_native_roots_and_caller_config() { "-----BEGIN CERTIFICATE-----\nAAAA\n-----END CERTIFICATE-----\n", ) .unwrap(); - for case in [ + let results = [ "default", "installed", "invalid-provider", @@ -119,7 +126,11 @@ fn wss_native_roots_and_caller_config() { "empty", "missing", "malformed", - ] { + "partial-load", + "partial-parse", + ] + .into_iter() + .map(|case| { let output = std::process::Command::new(std::env::current_exe().unwrap()) .args([ "--exact", @@ -132,17 +143,29 @@ fn wss_native_roots_and_caller_config() { "SSL_CERT_FILE", dir.join(match case { "custom" | "empty" => "empty.pem", - "missing" => "missing.pem", + "missing" | "partial-load" => "missing.pem", + "partial-parse" => "partial.pem", "malformed" => "malformed.pem", _ => "root.pem", }), ) - .env("SSL_CERT_DIR", dir.join("empty")) - .output() - .unwrap(); + .env( + "SSL_CERT_DIR", + dir.join(if case == "partial-load" { + "roots" + } else { + "empty" + }), + ) + .output(); + (case, output) + }) + .collect::>(); + std::fs::remove_dir_all(dir).unwrap(); + for (case, output) in results { + let output = output.unwrap(); assert!(output.status.success(), "{case}: {output:?}"); } - std::fs::remove_dir_all(dir).unwrap(); return; } tokio::runtime::Builder::new_current_thread() @@ -187,14 +210,7 @@ async fn wss_handshake() { let qmux::Error::Io(err) = err else { panic!("{case}: {err:?}") }; - assert_eq!( - err.kind(), - if case == "empty" { - std::io::ErrorKind::NotFound - } else { - std::io::ErrorKind::InvalidData - } - ); + assert_eq!(err.kind(), std::io::ErrorKind::NotFound); return; } let dir = std::path::PathBuf::from(std::env::var_os("QMUX_WSS_TEST_DIR").unwrap()); From e0e905688f7d00dc01589e7115a145c6a9482fd2 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 09:15:11 -0800 Subject: [PATCH 4/4] chore(quest): scope the rind epic's crypto claims to non-exempt crates Co-Authored-By: Claude Opus 5.5 --- quest/a1/rind/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quest/a1/rind/README.md b/quest/a1/rind/README.md index e646eaaa..4bb791ab 100644 --- a/quest/a1/rind/README.md +++ b/quest/a1/rind/README.md @@ -2,7 +2,7 @@ ## Goal -Every Rust crate here except Quiche and QMux takes its TLS crypto only from [rind](https://github.com/moq-dev/rind) through `rind-rustls`, so no build compiles C crypto. On every release target, `cargo tree -e normal,build -i` finds no aws-lc-sys, ring, or `cc` reached through a crypto crate. The crates' `aws-lc-rs` and `ring` features are removed. +Every Rust crate here except Quiche and QMux takes its TLS crypto only from [rind](https://github.com/moq-dev/rind) through `rind-rustls`, so their builds compile no C crypto. For those crates on every release target, `cargo tree -e normal,build -i` finds no aws-lc-sys, ring, or `cc` reached through a crypto crate. Their `aws-lc-rs` and `ring` features are removed. Non-goals: web-transport-quiche, which is BoringSSL (rind doesn't apply); qmux, which is being retired in favour of [moq-dev/moq's qmux](https://github.com/moq-dev/moq/blob/main/rs/qmux/MIGRATE.md), already on rind; and WASM, which uses the browser's TLS. @@ -19,7 +19,7 @@ Decided with the maintainer on 2026-11-06 (planning interview, following moq's [ The epic's own work, once every child has merged: - A CI guard that no release target's normal or build graph holds aws-lc-sys, ring, or `cc` through a crypto crate. Quiche's and QMux's graphs are exempt. -- Remove leftover aws-lc-rs and ring from the workspace, except dev-dependencies that only tests use. +- Remove leftover aws-lc-rs and ring from the workspace, except QMux's and dev-dependencies that only tests use. Decision prompts (✅ chosen):