show help when: shellchat net tls <no sub-command>

This commit is contained in:
nworbnhoj 2023-06-26 15:25:46 +10:00
parent 33169f9df9
commit 6ef1e8d67c

View file

@ -461,10 +461,9 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
} }
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
"tls" => { "tls" => {
if let Some(tls_cmd) = tokens.next() { match tokens.next() {
match tls_cmd {
// save/trust all Root CA's in webpki-roots en-masse // save/trust all Root CA's in webpki-roots en-masse
"mozilla" => { Some("mozilla") => {
let mut rotas: Vec<tls::RustlsOwnedTrustAnchor> = webpki_roots::TLS_SERVER_ROOTS let mut rotas: Vec<tls::RustlsOwnedTrustAnchor> = webpki_roots::TLS_SERVER_ROOTS
.0 .0
.iter() .iter()
@ -480,14 +479,21 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
i += 1; i += 1;
} }
} }
"probe" => { // probe establishes a tls connection to the supplied host, extracts the
// certificates offered and immediately closes the connection.
// The certificates are presented by modal to the user, and saved to the
// pddb if trusted.
Some("probe") => {
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Info);
log::info!("starting TLS probe"); log::info!("starting TLS probe");
// Attempt to open the tls connection with an empty root_store // Attempt to open the tls connection with an empty root_store
let mut root_store = rustls::RootCertStore::empty(); let mut root_store = rustls::RootCertStore::empty();
// Stifle the default rustls certificate verification's complaint about an // Stifle the default rustls certificate verification's complaint about an
// unknown/untrusted CA root certificate so that we get to see the certificate chain // unknown/untrusted CA root certificate so that we get to see the certificate chain
let stifled_verifier = Arc::new(danger::StifledCertificateVerification{ roots: root_store }); let stifled_verifier =
Arc::new(danger::StifledCertificateVerification {
roots: root_store,
});
let config = rustls::ClientConfig::builder() let config = rustls::ClientConfig::builder()
.with_safe_defaults() .with_safe_defaults()
.with_custom_certificate_verifier(stifled_verifier) .with_custom_certificate_verifier(stifled_verifier)
@ -517,7 +523,6 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
Some(certificates) => tls::check_trust(certificates), Some(certificates) => tls::check_trust(certificates),
None => false, None => false,
}; };
} }
Err(e) => { Err(e) => {
write!(ret, "{e}").ok(); write!(ret, "{e}").ok();
@ -527,7 +532,8 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Info);
} }
"test" => {
Some("test") => {
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Info);
log::info!("starting TLS run"); log::info!("starting TLS run");
let mut root_store = rustls::RootCertStore::empty(); let mut root_store = rustls::RootCertStore::empty();
@ -585,7 +591,7 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Info);
} }
// list trusted Certificate Authority certificates // list trusted Certificate Authority certificates
"trusted" => { Some("trusted") => {
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Info);
log::info!("starting TLS trusted listing"); log::info!("starting TLS trusted listing");
let trusted = let trusted =
@ -595,7 +601,7 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
} }
log::info!("finished TLS trusted listing"); log::info!("finished TLS trusted listing");
} }
_ => { _ | None => {
write!(ret, "net tls <sub-command>\n").ok(); write!(ret, "net tls <sub-command>\n").ok();
write!( write!(
ret, ret,
@ -609,7 +615,6 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
} }
} }
} }
}
// note: to use the `shellperf` option, you need to load a version of the SOC that has the performance counters built in. // note: to use the `shellperf` option, you need to load a version of the SOC that has the performance counters built in.
// this can be generated using the command `python3 .\betrusted_soc.py -e .\dummy.nky --perfcounter` in the betrusted-soc repo. // this can be generated using the command `python3 .\betrusted_soc.py -e .\dummy.nky --perfcounter` in the betrusted-soc repo.
// //