mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
tidy-up after update to rustls v22.2
This commit is contained in:
parent
2d744f1267
commit
bda9bc94e2
4 changed files with 39 additions and 17 deletions
|
|
@ -35,8 +35,8 @@ pub fn shellchat<'a>(mut tokens: impl Iterator<Item = &'a str>) -> Result<Option
|
|||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::info!("starting TLS trusted listing");
|
||||
let tls = Tls::new();
|
||||
for rota in tls.trusted() {
|
||||
write!(ret, "🏛 {}\n", rota.subject()).ok();
|
||||
for ota in tls.trusted() {
|
||||
write!(ret, "🏛 {}\n", ota).ok();
|
||||
}
|
||||
log::info!("finished TLS trusted listing");
|
||||
}
|
||||
|
|
@ -94,7 +94,6 @@ pub fn shellchat<'a>(mut tokens: impl Iterator<Item = &'a str>) -> Result<Option
|
|||
log::info!("build TLS client config");
|
||||
let tls = Tls::new();
|
||||
let config = rustls::ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(tls.root_store())
|
||||
.with_no_client_auth();
|
||||
let target = match tokens.next() {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ pub struct Tls {
|
|||
}
|
||||
|
||||
impl Tls {
|
||||
pub fn new() -> Tls { Tls { pddb: pddb::Pddb::new() } }
|
||||
pub fn new() -> Tls {
|
||||
Tls { pddb: pddb::Pddb::new() }
|
||||
}
|
||||
|
||||
/// Presents a modal to the user to select trusted tls certificates
|
||||
/// and saves the selected certificates to the pddb
|
||||
|
|
@ -360,7 +362,10 @@ impl Tls {
|
|||
/// the number of trusted Certificates offered by the host
|
||||
pub fn inspect(&self, host: &str) -> Result<usize, Error> {
|
||||
match self.probe(host) {
|
||||
Ok(certs) => Ok(self.trust_modal(certs)),
|
||||
Ok(certs) => match certs {
|
||||
Some(certs) => Ok(self.trust_modal(certs.to_vec())),
|
||||
None => Ok(0),
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!("failed to probe {host}: {e}");
|
||||
Ok(0)
|
||||
|
|
@ -384,9 +389,12 @@ impl Tls {
|
|||
/// true if the user trusts at least one of the Certificates offered by the host.
|
||||
pub fn accessible(&self, host: &str, inspect: bool) -> bool {
|
||||
match self.probe(host) {
|
||||
Ok(certs) => match certs.iter().find(|&cert| self.is_trusted_cert(cert.clone())) {
|
||||
Some(_) => true,
|
||||
None => inspect && (self.trust_modal(certs) > 0),
|
||||
Ok(certs) => match certs {
|
||||
Some(certs) => match certs.iter().find(|&cert| self.is_trusted_cert(cert.clone())) {
|
||||
Some(_) => true,
|
||||
None => inspect && (self.trust_modal(certs.to_vec()) > 0),
|
||||
},
|
||||
None => false,
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!("failed to probe {host}: {e}");
|
||||
|
|
|
|||
|
|
@ -30,7 +30,10 @@ impl OwnedTrustAnchor {
|
|||
pub fn pddb_key(&self) -> String {
|
||||
let subject = match std::str::from_utf8(&self.subject) {
|
||||
Ok(subject) => subject,
|
||||
Err(e) => "",
|
||||
Err(e) => {
|
||||
log::warn!("failed to extract ota.subject: {e}");
|
||||
""
|
||||
}
|
||||
};
|
||||
let begin = match subject.find("CN=") {
|
||||
Some(begin) => Some(begin),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::{convert::TryInto, fmt::Debug, io, net::TcpStream, result::Result, sync::Arc};
|
||||
|
||||
use rustls::pki_types::ServerName;
|
||||
use rustls::{ClientConnection, StreamOwned};
|
||||
use std::{convert::TryFrom, fmt::Debug, io, net::TcpStream, result::Result, sync::Arc};
|
||||
use ureq::{ReadWrite, Response};
|
||||
|
||||
use crate::Tls;
|
||||
|
|
@ -96,23 +96,35 @@ pub struct TlsStream(StreamOwned<ClientConnection, Box<dyn ReadWrite>>);
|
|||
|
||||
impl TlsStream {
|
||||
/// Returns a shared reference to the inner stream.
|
||||
pub fn get_ref(&self) -> &Box<dyn ReadWrite> { self.0.get_ref() }
|
||||
pub fn get_ref(&self) -> &Box<dyn ReadWrite> {
|
||||
self.0.get_ref()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the inner stream.
|
||||
pub fn get_mut(&mut self) -> &mut Box<dyn ReadWrite> { self.0.get_mut() }
|
||||
pub fn get_mut(&mut self) -> &mut Box<dyn ReadWrite> {
|
||||
self.0.get_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Read for TlsStream {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> { Ok(self.0.read(buf)?) }
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
||||
Ok(self.0.read(buf)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Write for TlsStream {
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> { Ok(self.0.write(buf)?) }
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
|
||||
Ok(self.0.write(buf)?)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> Result<(), std::io::Error> { Ok(self.0.flush()?) }
|
||||
fn flush(&mut self) -> Result<(), std::io::Error> {
|
||||
Ok(self.0.flush()?)
|
||||
}
|
||||
}
|
||||
|
||||
// required for the return type in TlsConnect::connect()
|
||||
impl ReadWrite for TlsStream {
|
||||
fn socket(&self) -> Option<&TcpStream> { self.get_ref().socket() }
|
||||
fn socket(&self) -> Option<&TcpStream> {
|
||||
self.get_ref().socket()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue