mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
implement tls.stream_owned()
This commit is contained in:
parent
b094402bf3
commit
bcb6a8c3bf
2 changed files with 13 additions and 3 deletions
|
|
@ -74,9 +74,9 @@ impl SignalWS {
|
|||
let host = url.host_str().expect("failed to extract host from url");
|
||||
match TcpStream::connect((host, 443)) {
|
||||
Ok(sock) => {
|
||||
log::info!("tcp connected");
|
||||
log::info!("tcp connected to {host}");
|
||||
let xtls = Tls::new();
|
||||
match xtls.stream(host, sock) {
|
||||
match xtls.stream_owned(host, sock) {
|
||||
Ok(tls_stream) => {
|
||||
log::info!("tls configured");
|
||||
log::info!("WEBSOCKET NOT IMPLEMENTED YET");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use rkyv::{
|
|||
ser::{serializers::WriteSerializer, Serializer},
|
||||
Deserialize,
|
||||
};
|
||||
use rustls::{Certificate, ClientConfig, RootCertStore};
|
||||
use rustls::{Certificate, ClientConfig, ClientConnection, RootCertStore};
|
||||
use sha2::Digest;
|
||||
use std::convert::{Into, TryFrom, TryInto};
|
||||
use std::io::{Error, ErrorKind, Read, Write};
|
||||
|
|
@ -342,6 +342,16 @@ impl Tls {
|
|||
.with_root_certificates(self.root_store())
|
||||
.with_no_client_auth()
|
||||
}
|
||||
|
||||
pub fn stream_owned(&self, host: &str, sock: TcpStream) -> Result<rustls::StreamOwned<ClientConnection, TcpStream>, Error> {
|
||||
match rustls::ClientConnection::new(
|
||||
Arc::new(self.client_config()),
|
||||
host.try_into().expect("failed url host_str"),
|
||||
) {
|
||||
Ok(conn) => Ok(rustls::StreamOwned::new(conn, sock)),
|
||||
Err(_) => Err(Error::new(ErrorKind::Other, "failed to configure client connection"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/57029974/how-to-split-string-into-chunks-in-rust-to-insert-spaces
|
||||
|
|
|
|||
Loading…
Reference in a new issue