mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
show help when: shellchat net tls <no sub-command>
This commit is contained in:
parent
33169f9df9
commit
6ef1e8d67c
1 changed files with 90 additions and 85 deletions
|
|
@ -461,73 +461,79 @@ 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
|
Some("mozilla") => {
|
||||||
"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()
|
.map(|ta| tls::RustlsOwnedTrustAnchor::from_subject_spki_name_constraints(
|
||||||
.map(|ta| tls::RustlsOwnedTrustAnchor::from_subject_spki_name_constraints(
|
ta.subject,
|
||||||
ta.subject,
|
ta.spki,
|
||||||
ta.spki,
|
ta.name_constraints,
|
||||||
ta.name_constraints,
|
))
|
||||||
))
|
.collect();
|
||||||
.collect();
|
let mut i = 0;
|
||||||
let mut i = 0;
|
for rota in rotas {
|
||||||
for rota in rotas {
|
tls::save_cert(format!("webpki-root-{i}").as_str(), &rota).unwrap();
|
||||||
tls::save_cert(format!("webpki-root-{i}").as_str(), &rota).unwrap();
|
i += 1;
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"probe" => {
|
}
|
||||||
log::set_max_level(log::LevelFilter::Info);
|
// probe establishes a tls connection to the supplied host, extracts the
|
||||||
log::info!("starting TLS probe");
|
// certificates offered and immediately closes the connection.
|
||||||
// Attempt to open the tls connection with an empty root_store
|
// The certificates are presented by modal to the user, and saved to the
|
||||||
let mut root_store = rustls::RootCertStore::empty();
|
// pddb if trusted.
|
||||||
// Stifle the default rustls certificate verification's complaint about an
|
Some("probe") => {
|
||||||
// unknown/untrusted CA root certificate so that we get to see the certificate chain
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
let stifled_verifier = Arc::new(danger::StifledCertificateVerification{ roots: root_store });
|
log::info!("starting TLS probe");
|
||||||
let config = rustls::ClientConfig::builder()
|
// Attempt to open the tls connection with an empty root_store
|
||||||
.with_safe_defaults()
|
let mut root_store = rustls::RootCertStore::empty();
|
||||||
.with_custom_certificate_verifier(stifled_verifier)
|
// Stifle the default rustls certificate verification's complaint about an
|
||||||
.with_no_client_auth();
|
// unknown/untrusted CA root certificate so that we get to see the certificate chain
|
||||||
let target = match tokens.next() {
|
let stifled_verifier =
|
||||||
Some(target) => target,
|
Arc::new(danger::StifledCertificateVerification {
|
||||||
None => "bunnyfoo.com",
|
roots: root_store,
|
||||||
};
|
});
|
||||||
let server_name = target.try_into().unwrap();
|
let config = rustls::ClientConfig::builder()
|
||||||
let mut conn =
|
.with_safe_defaults()
|
||||||
rustls::ClientConnection::new(Arc::new(config), server_name)
|
.with_custom_certificate_verifier(stifled_verifier)
|
||||||
.unwrap();
|
.with_no_client_auth();
|
||||||
log::info!("connect TCPstream to {}", target);
|
let target = match tokens.next() {
|
||||||
let url = format!("{}:443", target);
|
Some(target) => target,
|
||||||
let mut sock = match TcpStream::connect(url) {
|
None => "bunnyfoo.com",
|
||||||
Ok(mut sock) => {
|
};
|
||||||
match conn.complete_io(&mut sock){
|
let server_name = target.try_into().unwrap();
|
||||||
Ok(_) => log::info!("handshake complete"),
|
let mut conn =
|
||||||
Err(e) => {
|
rustls::ClientConnection::new(Arc::new(config), server_name)
|
||||||
write!(ret, "{e}").ok();
|
.unwrap();
|
||||||
log::warn!("{e}");
|
log::info!("connect TCPstream to {}", target);
|
||||||
}
|
let url = format!("{}:443", target);
|
||||||
|
let mut sock = match TcpStream::connect(url) {
|
||||||
|
Ok(mut sock) => {
|
||||||
|
match conn.complete_io(&mut sock) {
|
||||||
|
Ok(_) => log::info!("handshake complete"),
|
||||||
|
Err(e) => {
|
||||||
|
write!(ret, "{e}").ok();
|
||||||
|
log::warn!("{e}");
|
||||||
}
|
}
|
||||||
conn.send_close_notify();
|
|
||||||
|
|
||||||
match conn.peer_certificates() {
|
|
||||||
Some(certificates) => tls::check_trust(certificates),
|
|
||||||
None => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
conn.send_close_notify();
|
||||||
write!(ret, "{e}").ok();
|
|
||||||
log::warn!("{e}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
log::set_max_level(log::LevelFilter::Info);
|
match conn.peer_certificates() {
|
||||||
}
|
Some(certificates) => tls::check_trust(certificates),
|
||||||
"test" => {
|
None => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
write!(ret, "{e}").ok();
|
||||||
|
log::warn!("{e}")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
@ -583,30 +589,29 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
|
||||||
std::str::from_utf8(&plaintext).unwrap_or("utf-error")
|
std::str::from_utf8(&plaintext).unwrap_or("utf-error")
|
||||||
);
|
);
|
||||||
log::set_max_level(log::LevelFilter::Info);
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
|
}
|
||||||
|
// list trusted Certificate Authority certificates
|
||||||
|
Some("trusted") => {
|
||||||
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
|
log::info!("starting TLS trusted listing");
|
||||||
|
let trusted =
|
||||||
|
Trusted::new().expect("failed to initiate trusted iterator");
|
||||||
|
for rota in trusted {
|
||||||
|
write!(ret, "🏛 {}\n", rota.subject()).ok();
|
||||||
}
|
}
|
||||||
// list trusted Certificate Authority certificates
|
log::info!("finished TLS trusted listing");
|
||||||
"trusted" => {
|
}
|
||||||
log::set_max_level(log::LevelFilter::Info);
|
_ | None => {
|
||||||
log::info!("starting TLS trusted listing");
|
write!(ret, "net tls <sub-command>\n").ok();
|
||||||
let trusted =
|
write!(
|
||||||
Trusted::new().expect("failed to initiate trusted iterator");
|
ret,
|
||||||
for rota in trusted {
|
"\tmozilla\ttrust all Root CA's in webpki-roots\n"
|
||||||
write!(ret, "🏛 {}\n", rota.subject()).ok();
|
)
|
||||||
}
|
.ok();
|
||||||
log::info!("finished TLS trusted listing");
|
write!(ret, "\tprobe <host>\tsave host CA'a if trusted\n").ok();
|
||||||
}
|
write!(ret, "\ttest <host>\tmake tls connection to host\n")
|
||||||
_ => {
|
|
||||||
write!(ret, "net tls <sub-command>\n").ok();
|
|
||||||
write!(
|
|
||||||
ret,
|
|
||||||
"\tmozilla\ttrust all Root CA's in webpki-roots\n"
|
|
||||||
)
|
|
||||||
.ok();
|
.ok();
|
||||||
write!(ret, "\tprobe <host>\tsave host CA'a if trusted\n").ok();
|
write!(ret, "\ttrusted\tlist trusted CA certificates\n").ok();
|
||||||
write!(ret, "\ttest <host>\tmake tls connection to host\n")
|
|
||||||
.ok();
|
|
||||||
write!(ret, "\ttrusted\tlist trusted CA certificates\n").ok();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue