mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
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:
parent
a3b869ef0f
commit
b6e5e7f2c2
5 changed files with 26 additions and 51 deletions
|
|
@ -1,15 +1,17 @@
|
||||||
use crate::Tls;
|
|
||||||
use locales::t;
|
|
||||||
use rustls::pki_types::ServerName;
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use locales::t;
|
||||||
|
use rustls::pki_types::ServerName;
|
||||||
#[cfg(feature = "rootCA")]
|
#[cfg(feature = "rootCA")]
|
||||||
use {modals::Modals, std::convert::TryInto, xous_names::XousNames};
|
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> {
|
pub fn shellchat<'a>(mut tokens: impl Iterator<Item = &'a str>) -> Result<Option<String>, xous::Error> {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use modals::Modals;
|
use modals::Modals;
|
||||||
use rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
|
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::crypto::{ring, verify_tls12_signature, verify_tls13_signature, WebPkiSupportedAlgorithms};
|
||||||
use rustls::pki_types::{CertificateDer, Der, ServerName, TrustAnchor, UnixTime};
|
use rustls::pki_types::{CertificateDer, Der, ServerName, TrustAnchor, UnixTime};
|
||||||
use rustls::{CertificateError, DigitallySignedStruct, Error, RootCertStore, SignatureScheme};
|
use rustls::{CertificateError, DigitallySignedStruct, Error, RootCertStore, SignatureScheme};
|
||||||
use std::sync::Arc;
|
|
||||||
use xous_names::XousNames;
|
use xous_names::XousNames;
|
||||||
|
|
||||||
/// The entire purpose of the StifledCertificateVerification is to gain access to
|
/// The entire purpose of the StifledCertificateVerification is to gain access to
|
||||||
/// the certificate-chain-of-trust offered by a host by stifling CertificateError::UnknownIssuer
|
/// the certificate-chain-of-trust offered by a host by stifling CertificateError::UnknownIssuer
|
||||||
/// see https://github.com/rustls/rustls/issues/1819
|
/// see https://github.com/rustls/rustls/issues/1819
|
||||||
///
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StifledCertificateVerification {
|
pub struct StifledCertificateVerification {
|
||||||
pub roots: RootCertStore,
|
pub roots: RootCertStore,
|
||||||
|
|
@ -27,7 +27,6 @@ impl StifledCertificateVerification {
|
||||||
/// The somewhat hacky work-around is to add a single bogus TrustAnchor to RootCertStore,
|
/// 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
|
/// and neither the bogus TrustAnchor or the RootCertStore exist beyond the lifetime of
|
||||||
/// this StifledCertificateVerification.
|
/// this StifledCertificateVerification.
|
||||||
///
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut root_cert_store = rustls::RootCertStore::empty();
|
let mut root_cert_store = rustls::RootCertStore::empty();
|
||||||
// rustls::ServerCertVerifierBuilder::build() returns a
|
// rustls::ServerCertVerifierBuilder::build() returns a
|
||||||
|
|
@ -123,7 +122,5 @@ impl ServerCertVerifier for StifledCertificateVerification {
|
||||||
verify_tls13_signature(message, cert, dss, &self.supported)
|
verify_tls13_signature(message, cert, dss, &self.supported)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
|
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> { self.supported.supported_schemes() }
|
||||||
self.supported.supported_schemes()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@ mod danger;
|
||||||
pub mod ota;
|
pub mod ota;
|
||||||
pub mod xtls;
|
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 locales::t;
|
||||||
use modals::Modals;
|
use modals::Modals;
|
||||||
use ota::OwnedTrustAnchor;
|
use ota::OwnedTrustAnchor;
|
||||||
|
|
@ -13,10 +18,6 @@ use rkyv::{
|
||||||
};
|
};
|
||||||
use rustls::pki_types::{CertificateDer, TrustAnchor};
|
use rustls::pki_types::{CertificateDer, TrustAnchor};
|
||||||
use rustls::{ClientConfig, ClientConnection, RootCertStore};
|
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 x509_parser::prelude::{parse_x509_certificate, FromDer, X509Certificate};
|
||||||
use xous_names::XousNames;
|
use xous_names::XousNames;
|
||||||
|
|
||||||
|
|
@ -28,9 +29,7 @@ pub struct Tls {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tls {
|
impl Tls {
|
||||||
pub fn new() -> Tls {
|
pub fn new() -> Tls { Tls { pddb: pddb::Pddb::new() } }
|
||||||
Tls { pddb: pddb::Pddb::new() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Presents a modal to the user to select trusted tls certificates
|
/// Presents a modal to the user to select trusted tls certificates
|
||||||
/// and saves the selected certificates to the pddb
|
/// and saves the selected certificates to the pddb
|
||||||
|
|
@ -42,7 +41,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// a count of trusted certificates
|
/// a count of trusted certificates
|
||||||
///
|
|
||||||
pub fn trust_modal(&self, certificates: Vec<CertificateDer>) -> usize {
|
pub fn trust_modal(&self, certificates: Vec<CertificateDer>) -> usize {
|
||||||
let xns = XousNames::new().unwrap();
|
let xns = XousNames::new().unwrap();
|
||||||
let modals = Modals::new(&xns).unwrap();
|
let modals = Modals::new(&xns).unwrap();
|
||||||
|
|
@ -94,7 +92,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// the number of trust-anchors deleted
|
/// the number of trust-anchors deleted
|
||||||
///
|
|
||||||
pub fn del_all_rota(&self) -> Result<usize, Error> {
|
pub fn del_all_rota(&self) -> Result<usize, Error> {
|
||||||
let count = match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
|
let count = match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
|
||||||
Ok(list) => list.len(),
|
Ok(list) => list.len(),
|
||||||
|
|
@ -115,7 +112,6 @@ impl Tls {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `key` - the pddb-key containing the unwanted trust-anchor
|
/// * `key` - the pddb-key containing the unwanted trust-anchor
|
||||||
///
|
|
||||||
pub fn del_rota(&self, key: &str) -> Result<(), Error> {
|
pub fn del_rota(&self, key: &str) -> Result<(), Error> {
|
||||||
match self.pddb.delete_key(TLS_TRUSTED_DICT, key, None) {
|
match self.pddb.delete_key(TLS_TRUSTED_DICT, key, None) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|
@ -132,7 +128,6 @@ impl Tls {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `ta` - a trusted trust-anchor
|
/// * `ta` - a trusted trust-anchor
|
||||||
///
|
|
||||||
pub fn save_ta(&self, ta: &OwnedTrustAnchor) -> Result<(), Error> {
|
pub fn save_ta(&self, ta: &OwnedTrustAnchor) -> Result<(), Error> {
|
||||||
match ta.pddb_key() {
|
match ta.pddb_key() {
|
||||||
Ok(key) => {
|
Ok(key) => {
|
||||||
|
|
@ -183,7 +178,6 @@ impl Tls {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `key` - pddb key holding the trust-anchor
|
/// * `key` - pddb key holding the trust-anchor
|
||||||
///
|
|
||||||
pub fn get_ota(&self, key: &str) -> Option<OwnedTrustAnchor> {
|
pub fn get_ota(&self, key: &str) -> Option<OwnedTrustAnchor> {
|
||||||
match self.pddb.get(TLS_TRUSTED_DICT, key, None, false, false, None, None::<fn()>) {
|
match self.pddb.get(TLS_TRUSTED_DICT, key, None, false, false, None, None::<fn()>) {
|
||||||
Ok(mut pddb_key) => {
|
Ok(mut pddb_key) => {
|
||||||
|
|
@ -218,7 +212,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// a Vec of OwnedTrustAnchor.
|
/// a Vec of OwnedTrustAnchor.
|
||||||
///
|
|
||||||
pub fn trusted(&self) -> Vec<OwnedTrustAnchor> {
|
pub fn trusted(&self) -> Vec<OwnedTrustAnchor> {
|
||||||
match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
|
match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
|
||||||
Ok(list) => list
|
Ok(list) => list
|
||||||
|
|
@ -242,7 +235,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// true if the certificate is saved in the TLS_TRUSTED_DICT in the pddb
|
/// true if the certificate is saved in the TLS_TRUSTED_DICT in the pddb
|
||||||
///
|
|
||||||
pub fn is_trusted_cert(&self, cert: CertificateDer) -> bool {
|
pub fn is_trusted_cert(&self, cert: CertificateDer) -> bool {
|
||||||
match parse_x509_certificate(cert.as_ref()) {
|
match parse_x509_certificate(cert.as_ref()) {
|
||||||
Ok(result) => self.is_trusted_x509(&result.1),
|
Ok(result) => self.is_trusted_x509(&result.1),
|
||||||
|
|
@ -294,7 +286,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// a RootCertStore suitable for rustls
|
/// a RootCertStore suitable for rustls
|
||||||
///
|
|
||||||
pub fn root_store(&self) -> RootCertStore {
|
pub fn root_store(&self) -> RootCertStore {
|
||||||
let mut root_store = RootCertStore::empty();
|
let mut root_store = RootCertStore::empty();
|
||||||
let trusted = match self.pddb.list_keys(TLS_TRUSTED_DICT, None) {
|
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
|
/// * A Vec<CertificateDer> containing the TLS chain of trust offered by the host
|
||||||
/// * Error if the communication with the host fails
|
/// * Error if the communication with the host fails
|
||||||
///
|
|
||||||
pub fn probe(&self, host: &str) -> Result<Vec<CertificateDer>, Error> {
|
pub fn probe(&self, host: &str) -> Result<Vec<CertificateDer>, Error> {
|
||||||
log::info!("starting TLS probe");
|
log::info!("starting TLS probe");
|
||||||
match host.to_owned().try_into() {
|
match host.to_owned().try_into() {
|
||||||
|
|
@ -387,7 +377,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// the number of trusted Certificates offered by the host
|
/// the number of trusted Certificates offered by the host
|
||||||
///
|
|
||||||
pub fn inspect(&self, host: &str) -> Result<usize, Error> {
|
pub fn inspect(&self, host: &str) -> Result<usize, Error> {
|
||||||
match self.probe(host) {
|
match self.probe(host) {
|
||||||
Ok(certs) => {
|
Ok(certs) => {
|
||||||
|
|
@ -418,7 +407,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// true if the user trusts at least one of the Certificates offered by the host.
|
/// true if the user trusts at least one of the Certificates offered by the host.
|
||||||
///
|
|
||||||
pub fn accessible(&self, host: &str, inspect: bool) -> bool {
|
pub fn accessible(&self, host: &str, inspect: bool) -> bool {
|
||||||
match self.probe(host) {
|
match self.probe(host) {
|
||||||
Ok(certs) => match certs.iter().find(|&cert| self.is_trusted_cert(cert.clone())) {
|
Ok(certs) => match certs.iter().find(|&cert| self.is_trusted_cert(cert.clone())) {
|
||||||
|
|
@ -446,7 +434,6 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// an owned rusttls stream on the tcp-stream provided
|
/// an owned rusttls stream on the tcp-stream provided
|
||||||
///
|
|
||||||
pub fn stream_owned(
|
pub fn stream_owned(
|
||||||
&self,
|
&self,
|
||||||
host: &str,
|
host: &str,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
// A rkyv serialisable intermediatory for a TrustAnchor
|
// 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::cmp::min;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::{Error, ErrorKind};
|
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::prelude::{FromDer, X509Certificate};
|
||||||
use x509_parser::x509::X509Name;
|
use x509_parser::x509::X509Name;
|
||||||
|
|
||||||
|
|
@ -44,7 +45,6 @@ impl OwnedTrustAnchor {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// An OwnedTrustAnchor based on the supplied X509Certificate
|
/// An OwnedTrustAnchor based on the supplied X509Certificate
|
||||||
///
|
|
||||||
pub fn from_x509(x509: &X509Certificate) -> Result<Self, Error> {
|
pub fn from_x509(x509: &X509Certificate) -> Result<Self, Error> {
|
||||||
match (
|
match (
|
||||||
rm_der_header(x509.subject().as_raw()),
|
rm_der_header(x509.subject().as_raw()),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use std::{convert::TryFrom, fmt::Debug, io, net::TcpStream, result::Result, sync::Arc};
|
||||||
|
|
||||||
use rustls::pki_types::ServerName;
|
use rustls::pki_types::ServerName;
|
||||||
use rustls::{ClientConnection, StreamOwned};
|
use rustls::{ClientConnection, StreamOwned};
|
||||||
use std::{convert::TryFrom, fmt::Debug, io, net::TcpStream, result::Result, sync::Arc};
|
|
||||||
use ureq::{ReadWrite, Response};
|
use ureq::{ReadWrite, Response};
|
||||||
|
|
||||||
use crate::Tls;
|
use crate::Tls;
|
||||||
|
|
@ -92,35 +93,23 @@ pub struct TlsStream(StreamOwned<ClientConnection, Box<dyn ReadWrite>>);
|
||||||
|
|
||||||
impl TlsStream {
|
impl TlsStream {
|
||||||
/// Returns a shared reference to the inner stream.
|
/// Returns a shared reference to the inner stream.
|
||||||
pub fn get_ref(&self) -> &Box<dyn ReadWrite> {
|
pub fn get_ref(&self) -> &Box<dyn ReadWrite> { self.0.get_ref() }
|
||||||
self.0.get_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a mutable reference to the inner stream.
|
/// Returns a mutable reference to the inner stream.
|
||||||
pub fn get_mut(&mut self) -> &mut Box<dyn ReadWrite> {
|
pub fn get_mut(&mut self) -> &mut Box<dyn ReadWrite> { self.0.get_mut() }
|
||||||
self.0.get_mut()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl io::Read for TlsStream {
|
impl io::Read for TlsStream {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> { Ok(self.0.read(buf)?) }
|
||||||
Ok(self.0.read(buf)?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl io::Write for TlsStream {
|
impl io::Write for TlsStream {
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
|
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> { Ok(self.0.write(buf)?) }
|
||||||
Ok(self.0.write(buf)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> Result<(), std::io::Error> {
|
fn flush(&mut self) -> Result<(), std::io::Error> { Ok(self.0.flush()?) }
|
||||||
Ok(self.0.flush()?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// required for the return type in TlsConnect::connect()
|
// required for the return type in TlsConnect::connect()
|
||||||
impl ReadWrite for TlsStream {
|
impl ReadWrite for TlsStream {
|
||||||
fn socket(&self) -> Option<&TcpStream> {
|
fn socket(&self) -> Option<&TcpStream> { self.get_ref().socket() }
|
||||||
self.get_ref().socket()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue