Merge branch 'main' of github.com:betrusted-io/xous-core into main

This commit is contained in:
bunnie 2023-07-05 15:19:13 +08:00
commit ecb42c6a0e
6 changed files with 8 additions and 63 deletions

View file

@ -43,6 +43,10 @@
"en": "failed to create sever name from",
"en-tts": "failed to create sever name from"
},
"tls.probe_done": {
"en": "trusted CA's",
"en-tts": "trusted CA's"
},
"tls.test_cmd": {
"en": "make tls connection to host",
"en-tts": "make tls connection to host"

View file

@ -118,7 +118,7 @@ pub fn shellchat<'a>(
Some(certificates) => {
let tls = Tls::new();
let count = tls.check_trust(certificates);
write!(ret, "trusted {count} certificates").ok();
write!(ret, "{} {}", count, t!("tls.probe_done", locales::LANG)).ok();
}
None => (),
};

View file

@ -19,8 +19,6 @@ use xous_names::XousNames;
/// PDDB Dict for tls trusted certificates keys
const TLS_TRUSTED_DICT: &str = "tls.trusted";
#[allow(dead_code)]
const CURRENT_VERSION_KEY: &str = "__version";
pub struct Tls {
pddb: pddb::Pddb,

View file

@ -4,8 +4,6 @@ use der::{Encode, Header, Reader, Tag};
use rkyv::{Archive, Deserialize, Serialize};
use std::cmp::min;
use std::convert::TryInto;
#[allow(unused_imports)]
use std::fmt;
use std::io::{Error, ErrorKind};
use x509_parser::prelude::{FromDer, X509Certificate};

View file

@ -1,57 +0,0 @@
use crate::get_cert;
use crate::{rota::RustlsOwnedTrustAnchor, TLS_TRUSTED_DICT};
use rustls::RootCertStore;
use std::io::Error;
use std::path::PathBuf;
pub struct Trusted {
trusted: std::fs::ReadDir,
}
impl Trusted {
pub fn new() -> Result<Trusted, Error> {
let mut keypath = PathBuf::new();
keypath.push(TLS_TRUSTED_DICT);
if !std::fs::metadata(&keypath).is_ok() {
log::info!("dict '{}' does NOT exist.. creating it", TLS_TRUSTED_DICT);
std::fs::create_dir_all(&keypath)?;
}
Ok(Self {
trusted: std::fs::read_dir(keypath)?,
})
}
}
impl Iterator for Trusted {
type Item = RustlsOwnedTrustAnchor;
fn next(&mut self) -> Option<Self::Item> {
match self.trusted.next() {
Some(Ok(dir_entry)) => match dir_entry.file_name().into_string() {
Ok(key) => {
log::info!("path: {}", key);
get_cert(&key).unwrap_or(None)
}
Err(e) => {
log::warn!("failed to read cert: {:?}", e);
None
}
},
Some(Err(e)) => {
log::warn!("failed to list trusted certs: {}", e);
None
}
None => None,
}
}
}
impl Into<RootCertStore> for Trusted {
fn into(self) -> RootCertStore {
let mut root_store = rustls::RootCertStore::empty();
let trusted = Trusted::new().unwrap();
root_store
.add_server_trust_anchors(trusted.map(|t| Into::<rustls::OwnedTrustAnchor>::into(t)));
root_store
}
}

View file

@ -453,10 +453,12 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
}
}
// net tls <sub-command>
// deleteall deleteall trusted CA certificates
// help
// list list all trusted CA certificates
// mozilla trust all Root CA's in webpki-roots
// probe <host> save host CA'a if trusted
// test <host> make tls connection to host
// trusted list trusted CA certificates
#[cfg(feature = "tls")]
"tls" => {
if let Ok(Some(r)) = tls::cmd::shellchat(&mut tokens) {