mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
implement tls Trusted iterator
This commit is contained in:
parent
65f92453a2
commit
0d1e89e560
1 changed files with 42 additions and 0 deletions
|
|
@ -51,6 +51,48 @@ impl<'a> From<&X509Certificate<'a>> for RustlsOwnedTrustAnchor {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct Trusted {
|
||||
trusted: std::fs::ReadDir,
|
||||
}
|
||||
|
||||
impl Trusted {
|
||||
pub fn new() -> Result<Trusted, Error> {
|
||||
let mut keypath = PathBuf::new();
|
||||
keypath.push(TLS_CERT_DICT);
|
||||
if !std::fs::metadata(&keypath).is_ok() {
|
||||
log::info!("dict '{}' does NOT exist.. creating it", TLS_CERT_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,
|
||||
}
|
||||
}
|
||||
}
|
||||
// presents a modal to the user to select trusted tls certificates
|
||||
// and saves the selected certificates to the pddb
|
||||
// returns false if no certificates are trusted - and true otherwise
|
||||
|
|
|
|||
Loading…
Reference in a new issue