apply formatting patch

@nworbnhoj, i saw you had explicitly done a formatting pass.
However, I think maybe the +nightly flag was missing, it looks
like the formatting ignored our custom rule set, which requires
nightly?
This commit is contained in:
bunnie 2024-03-02 01:26:51 +08:00
parent a3b869ef0f
commit b6e5e7f2c2
5 changed files with 26 additions and 51 deletions

View file

@ -1,15 +1,17 @@
use crate::Tls;
use locales::t;
use rustls::pki_types::ServerName;
use std::convert::TryFrom;
use std::io::Read;
use std::io::Write;
use std::net::TcpStream;
use std::str::from_utf8;
use std::sync::Arc;
use locales::t;
use rustls::pki_types::ServerName;
#[cfg(feature = "rootCA")]
use {modals::Modals, std::convert::TryInto, xous_names::XousNames};
use crate::Tls;
pub fn shellchat<'a>(mut tokens: impl Iterator<Item = &'a str>) -> Result<Option<String>, xous::Error> {
use core::fmt::Write;
let mut ret = String::new();

View file

@ -1,3 +1,5 @@
use std::sync::Arc;
use locales::t;
use modals::Modals;
use rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
@ -5,13 +7,11 @@ use rustls::client::WebPkiServerVerifier;
use rustls::crypto::{ring, verify_tls12_signature, verify_tls13_signature, WebPkiSupportedAlgorithms};
use rustls::pki_types::{CertificateDer, Der, ServerName, TrustAnchor, UnixTime};
use rustls::{CertificateError, DigitallySignedStruct, Error, RootCertStore, SignatureScheme};
use std::sync::Arc;
use xous_names::XousNames;
/// The entire purpose of the StifledCertificateVerification is to gain access to
/// the certificate-chain-of-trust offered by a host by stifling CertificateError::UnknownIssuer
/// see https://github.com/rustls/rustls/issues/1819
///
#[derive(Debug)]
pub struct StifledCertificateVerification {
pub roots: RootCertStore,
@ -27,7 +27,6 @@ impl StifledCertificateVerification {
/// The somewhat hacky work-around is to add a single bogus TrustAnchor to RootCertStore,
/// and neither the bogus TrustAnchor or the RootCertStore exist beyond the lifetime of
/// this StifledCertificateVerification.
///
pub fn new() -> Self {
let mut root_cert_store = rustls::RootCertStore::empty();
// rustls::ServerCertVerifierBuilder::build() returns a
@ -123,7 +122,5 @@ impl ServerCertVerifier for StifledCertificateVerification {
verify_tls13_signature(message, cert, dss, &self.supported)
}
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
self.supported.supported_schemes()
}
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> { self.supported.supported_schemes() }
}

View file

@ -3,6 +3,11 @@ mod danger;
pub mod ota;
pub mod xtls;
use std::convert::{Into, TryFrom, TryInto};
use std::io::{Error, ErrorKind, Read, Write};
use std::net::TcpStream;
use std::sync::Arc;
use locales::t;
use modals::Modals;
use ota::OwnedTrustAnchor;
@ -13,10 +18,6 @@ use rkyv::{
};
use rustls::pki_types::{CertificateDer, TrustAnchor};
use rustls::{ClientConfig, ClientConnection, RootCertStore};
use std::convert::{Into, TryFrom, TryInto};
use std::io::{Error, ErrorKind, Read, Write};
use std::net::TcpStream;
use std::sync::Arc;
use x509_parser::prelude::{parse_x509_certificate, FromDer, X509Certificate};
use xous_names::XousNames;
@ -28,9 +29,7 @@ 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
@ -42,7 +41,6 @@ impl Tls {
/// # Returns
///
/// a count of trusted certificates
///
pub fn trust_modal(&self, certificates: Vec<CertificateDer>) -> usize {
let xns = XousNames::new().unwrap();
let modals = Modals::new(&xns).unwrap();
@ -94,7 +92,6 @@ impl Tls {
/// # Returns
///
/// the number of trust-anchors deleted
///
pub fn del_all_rota(&self) -> Result<usize, Error> {
let count = match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
Ok(list) => list.len(),
@ -115,7 +112,6 @@ impl Tls {
/// # Arguments
///
/// * `key` - the pddb-key containing the unwanted trust-anchor
///
pub fn del_rota(&self, key: &str) -> Result<(), Error> {
match self.pddb.delete_key(TLS_TRUSTED_DICT, key, None) {
Ok(_) => {
@ -132,7 +128,6 @@ impl Tls {
/// # Arguments
///
/// * `ta` - a trusted trust-anchor
///
pub fn save_ta(&self, ta: &OwnedTrustAnchor) -> Result<(), Error> {
match ta.pddb_key() {
Ok(key) => {
@ -183,7 +178,6 @@ impl Tls {
/// # Arguments
///
/// * `key` - pddb key holding the trust-anchor
///
pub fn get_ota(&self, key: &str) -> Option<OwnedTrustAnchor> {
match self.pddb.get(TLS_TRUSTED_DICT, key, None, false, false, None, None::<fn()>) {
Ok(mut pddb_key) => {
@ -218,7 +212,6 @@ impl Tls {
/// # Returns
///
/// a Vec of OwnedTrustAnchor.
///
pub fn trusted(&self) -> Vec<OwnedTrustAnchor> {
match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
Ok(list) => list
@ -242,7 +235,6 @@ impl Tls {
/// # Returns
///
/// true if the certificate is saved in the TLS_TRUSTED_DICT in the pddb
///
pub fn is_trusted_cert(&self, cert: CertificateDer) -> bool {
match parse_x509_certificate(cert.as_ref()) {
Ok(result) => self.is_trusted_x509(&result.1),
@ -294,7 +286,6 @@ impl Tls {
/// # Returns
///
/// a RootCertStore suitable for rustls
///
pub fn root_store(&self) -> RootCertStore {
let mut root_store = RootCertStore::empty();
let trusted = match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
@ -331,7 +322,6 @@ impl Tls {
///
/// * A Vec<CertificateDer> containing the TLS chain of trust offered by the host
/// * Error if the communication with the host fails
///
pub fn probe(&self, host: &str) -> Result<Vec<CertificateDer>, Error> {
log::info!("starting TLS probe");
match host.to_owned().try_into() {
@ -387,7 +377,6 @@ impl Tls {
/// # Returns
///
/// the number of trusted Certificates offered by the host
///
pub fn inspect(&self, host: &str) -> Result<usize, Error> {
match self.probe(host) {
Ok(certs) => {
@ -418,7 +407,6 @@ impl Tls {
/// # Returns
///
/// 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())) {
@ -446,7 +434,6 @@ impl Tls {
/// # Returns
///
/// an owned rusttls stream on the tcp-stream provided
///
pub fn stream_owned(
&self,
host: &str,

View file

@ -1,11 +1,12 @@
// A rkyv serialisable intermediatory for a TrustAnchor
use der::{Encode, Header, Reader, Tag};
use rkyv::{Archive, Deserialize, Serialize};
use rustls::pki_types::{Der, TrustAnchor};
use std::cmp::min;
use std::convert::TryInto;
use std::fmt;
use std::io::{Error, ErrorKind};
use der::{Encode, Header, Reader, Tag};
use rkyv::{Archive, Deserialize, Serialize};
use rustls::pki_types::{Der, TrustAnchor};
use x509_parser::prelude::{FromDer, X509Certificate};
use x509_parser::x509::X509Name;
@ -44,7 +45,6 @@ impl OwnedTrustAnchor {
/// # Returns
///
/// An OwnedTrustAnchor based on the supplied X509Certificate
///
pub fn from_x509(x509: &X509Certificate) -> Result<Self, Error> {
match (
rm_der_header(x509.subject().as_raw()),

View file

@ -1,6 +1,7 @@
use std::{convert::TryFrom, 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;
@ -92,35 +93,23 @@ 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() }
}