Managed to update rustls to version 0.21

This commit is contained in:
2024-01-17 19:52:28 +01:00
parent 5609708848
commit e534deefae
5 changed files with 41 additions and 48 deletions

View File

@ -1,7 +1,6 @@
use std::sync::Arc;
use futures::{SinkExt, StreamExt};
use hyper_rustls::ConfigBuilderExt;
use rustls::RootCertStore;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
@ -42,7 +41,17 @@ async fn relay_connection(ws_url: String, socket: TcpStream, conf: Arc<ClientCon
let config = rustls::ClientConfig::builder().with_safe_defaults();
let config = match conf.get_root_certificate() {
None => config.with_native_roots(),
None => {
// Perform a connection over TLS
let mut roots = RootCertStore::empty();
for cert in rustls_native_certs::load_native_certs()
.expect("Failed to load native certificates")
{
roots.add(&rustls::Certificate(cert.0)).unwrap();
}
config.with_root_certificates(roots)
}
Some(cert) => {
log::debug!("Using custom root certificates");
let mut store = RootCertStore::empty();
@ -72,7 +81,7 @@ async fn relay_connection(ws_url: String, socket: TcpStream, conf: Arc<ClientCon
let connector = tokio_tungstenite::Connector::Rustls(Arc::new(config));
let (ws_stream, _) =
tokio_tungstenite::connect_async_tls_with_config(ws_url, None, Some(connector))
tokio_tungstenite::connect_async_tls_with_config(ws_url, None, false, Some(connector))
.await
.expect("Failed to connect to server relay!");