From 53b002ad9c996d41bce0ad544c1da50b4d539b5c Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Thu, 29 Jun 2023 13:10:28 +1000 Subject: [PATCH] return count of trusted certificates from shellchat net tls probe & shellchat net tls mozilla --- libs/tls/src/cmd.rs | 14 +++++++++----- libs/tls/src/lib.rs | 8 ++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libs/tls/src/cmd.rs b/libs/tls/src/cmd.rs index 143a80510..5446ff7ef 100644 --- a/libs/tls/src/cmd.rs +++ b/libs/tls/src/cmd.rs @@ -30,11 +30,12 @@ pub fn shellchat<'a>( ) }) .collect(); - let mut i = 0; + let mut count = 0; for rota in rotas { - crate::save_cert(format!("webpki-root-{i}").as_str(), &rota).unwrap(); - i += 1; + crate::save_cert(format!("webpki-root-{count}").as_str(), &rota).unwrap(); + count += 1; } + write!(ret, "trusted {count} certificates").ok(); } // probe establishes a tls connection to the supplied host, extracts the // certificates offered and immediately closes the connection. @@ -77,8 +78,11 @@ pub fn shellchat<'a>( conn.send_close_notify(); match conn.peer_certificates() { - Some(certificates) => check_trust(certificates), - None => false, + Some(certificates) => { + let count = check_trust(certificates); + write!(ret, "trusted {count} certificates").ok(); + } + None => (), }; } Err(e) => { diff --git a/libs/tls/src/lib.rs b/libs/tls/src/lib.rs index 30b617eaf..c5f99976c 100644 --- a/libs/tls/src/lib.rs +++ b/libs/tls/src/lib.rs @@ -25,8 +25,8 @@ const CURRENT_VERSION_KEY: &str = "__version"; // 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 -pub fn check_trust(certificates: &[Certificate]) -> bool { +// returns a count of trusted certificates +pub fn check_trust(certificates: &[Certificate]) -> usize { let xns = XousNames::new().unwrap(); let modals = Modals::new(&xns).unwrap(); @@ -82,11 +82,11 @@ pub fn check_trust(certificates: &[Certificate]) -> bool { .expect("modal failed"); }); }); - trusted.len() > 0 + trusted.len() } _ => { log::error!("get_checkbox failed"); - false + 0 } } }