TLS
https and wss URLs use the compiled-in TLS backend (see Cargo features):
| Setup | Trusts |
|---|---|
rustls (default) | Mozilla roots from webpki-roots |
rustls + platform-verifier | the operating system's trust store (enterprise and user-installed CAs); bundled roots on Android |
native-tls | the platform library's trust store |
| neither | nothing: https / wss fail with TlsNotEnabled |
A private CA
use socketio_next::{ClientBuilder, TlsConfig};
let pem = std::fs::read("ca.pem")?;
let client = ClientBuilder::new("https://internal.example.com")
.tls_config(TlsConfig::with_root_certificates_pem(&pem)?)
.connect()
.await?;
TlsConfig::with_root_certificates_pem trusts only the PEM certificates given (a private or self-signed CA). It uses rustls when compiled in, native-tls otherwise.
Your own configuration
tls_config takes anything Into<TlsConfig>:
- a
rustls::ClientConfigorArc<rustls::ClientConfig>(client certificates, custom verifiers, ALPN); - a
native_tls::TlsConnector(featurenative-tls). With both backends compiled in, this selects native-tls.
let connector = native_tls::TlsConnector::builder()
.add_root_certificate(native_tls::Certificate::from_pem(&pem)?)
.build()?;
let client = ClientBuilder::new(url).tls_config(connector).connect().await?;
There is no switch to turn certificate checks off.
reqwest and rustls-no-provider
If another crate in your build turns on reqwest 0.13's rustls-no-provider (for example tauri-plugin-updater), reqwest needs a rustls provider even for plain http: connecting then fails with TlsProviderMissing. Enable rustls here; it hands reqwest a ring-based configuration, no global provider needed.
Mobile
rustls with the bundled roots builds and works on Android and iOS without setup. platform-verifier is not used on Android (it needs JVM setup there).