simplify shellchat net tls probe

This commit is contained in:
nworbnhoj 2023-06-24 15:37:10 +10:00
parent 472e4407b8
commit 5feaac2bae

View file

@ -500,27 +500,24 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
let url = format!("{}:443", target); let url = format!("{}:443", target);
let mut sock = match TcpStream::connect(url) { let mut sock = match TcpStream::connect(url) {
Ok(mut sock) => { Ok(mut sock) => {
let mut tls = rustls::Stream::new(&mut conn, &mut sock); match conn.complete_io(&mut sock){
log::info!("create http headers and write to server"); Ok(_) => log::info!("handshake complete"),
let msg = format!("GET / HTTP/1.1\r\nHost: {}\r\nConnection: keep-alive\r\nAccept-Encoding: identity\r\n\r\n", target); Err(e) => {
match tls.write_all(msg.as_bytes()) { write!(ret, "{e}").ok();
Ok(()) => (), log::warn!("{e}");
Err(e) => log::warn!( }
"failed to write to tls connection {}", }
e conn.send_close_notify();
),
};
log::info!("close tls connection"); match conn.peer_certificates() {
tls.conn.send_close_notify();
match tls.conn.peer_certificates() {
Some(certificates) => tls::check_trust(certificates), Some(certificates) => tls::check_trust(certificates),
None => false, None => false,
}; };
} }
Err(e) => { Err(e) => {
log::warn!("failed to establish tls connection {}", e) write!(ret, "{e}").ok();
log::warn!("{e}")
} }
}; };