snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

Rustls: no process-level CryptoProvider available -- call CryptoProvider::install_default() before this point #339

Closed maxpowel closed 4 months ago

maxpowel commented 4 months ago

Hello

When using rutls on versions > 0.22.0 this error is raised:

[2024-07-05][12:21:59][tokio_tungstenite::tls::encryption::rustls][DEBUG] Added 129/129 native root certificates (ignored 0)
thread 'tokio-runtime-worker' panicked at /home/maxpowel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.23.10/src/crypto/mod.rs:259:14:
no process-level CryptoProvider available -- call CryptoProvider::install_default() before this point

I investigated a bit about CryptoProvider::install_default() and it looks something related with latest changes rustls made in crypto part.

This line in my Cargo.toml works fine:

tokio-tungstenite = { version = "0.22.0", features = ["rustls-tls-native-roots"] }

but this raises the error

tokio-tungstenite = { version = "0.23.1", features = ["rustls-tls-native-roots"] }

The error appears as soon as you call tokio_tungstenite::connect_async

Thank you

agalakhov commented 4 months ago

See https://github.com/snapview/tokio-tungstenite/issues/336.

maxpowel commented 4 months ago

Ah sorry, I tried to find any reference to this problem and I did not find it. Thank you

malongshuai commented 3 months ago

i changed my Cargo.toml and solved:

ring = { version = "0.17" }
rustls = { version = "0.23", features = ["ring","logging","tls12"], default-features = false }
tokio-tungstenite = { version = "0.23", features = ["rustls-tls-webpki-roots"] }
jiangxiaoqiang commented 1 month ago

add this code to fixed:

rustls::crypto::ring::default_provider().install_default().expect("Failed to install rustls crypto provider");