Working tls handshake
This commit is contained in:
+33
-8
@@ -1,14 +1,39 @@
|
||||
use std::io::{Read, Write};
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
net::TcpStream,
|
||||
};
|
||||
|
||||
pub mod server;
|
||||
pub mod tls;
|
||||
|
||||
pub fn request(gateway: &str, addr: &str) -> String {
|
||||
let (mut conn, mut tcp) = tls::mask_tls(gateway).unwrap();
|
||||
let mut tls = rustls::Stream::new(&mut conn, &mut tcp);
|
||||
tls.write_all(format!("ROUTE {addr}\nGET / HTTP/1.1").as_bytes())
|
||||
pub struct Request {
|
||||
host: String,
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
pub fn new(url: &str) -> Self {
|
||||
Self {
|
||||
host: url.to_string(),
|
||||
path: String::from("/"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Request {
|
||||
pub fn send(&self) -> String {
|
||||
let mut tcp = TcpStream::connect((self.host.as_str(), 443)).unwrap();
|
||||
let mut conn = tls::tls13_handshake(&self.host, &mut tcp).unwrap();
|
||||
let mut tls = rustls::Stream::new(&mut conn, &mut tcp);
|
||||
write!(
|
||||
tls,
|
||||
"GET {} HTTP/1.1\r\nHost: {}\r\nConnection: close\r\nUser-Agent: rustls/0.23\r\n\r\n",
|
||||
self.path, self.host
|
||||
)
|
||||
.unwrap();
|
||||
let mut resp = Vec::new();
|
||||
tls.read_to_end(&mut resp).unwrap();
|
||||
String::from_utf8_lossy(&resp).to_string()
|
||||
tls.flush().unwrap();
|
||||
let mut resp = Vec::new();
|
||||
tls.read_to_end(&mut resp).unwrap();
|
||||
String::from_utf8(resp).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user