fix spoofing https connections
This commit is contained in:
@@ -328,10 +328,10 @@ pub(crate) fn connect_http(unit: &Unit, hostname: &str) -> Result<Stream, Error>
|
||||
connect_host(unit, hostname, port).map(|(t, r)| Stream::new(t, r, pool_returner))
|
||||
}
|
||||
|
||||
pub(crate) fn connect_https(unit: &Unit, hostname: &str) -> Result<Stream, Error> {
|
||||
pub(crate) fn connect_https(unit: &Unit, hostname: &str, spoofed_host: Option<&str>) -> Result<Stream, Error> {
|
||||
let port = unit.url.port().unwrap_or(443);
|
||||
|
||||
let (sock, remote_addr) = connect_host(unit, hostname, port)?;
|
||||
let (sock, remote_addr) = connect_host(unit, spoofed_host.unwrap_or(hostname), port)?;
|
||||
|
||||
let tls_conf = &unit.agent.config.tls_config;
|
||||
let https_stream = tls_conf.connect(hostname, Box::new(sock))?;
|
||||
|
||||
17
src/unit.rs
17
src/unit.rs
@@ -259,12 +259,10 @@ fn connect_inner(
|
||||
let url = &unit.url;
|
||||
let method = &unit.method;
|
||||
|
||||
let socket_host = unit.spoofed_host.as_ref()
|
||||
.map(|r|r.as_ref())
|
||||
.unwrap_or(host);
|
||||
let spoofed_host = unit.spoofed_host.as_ref().map(|r|r.as_ref());
|
||||
|
||||
// open socket
|
||||
let (mut stream, is_recycled) = connect_socket(unit, socket_host, use_pooled)?;
|
||||
let (mut stream, is_recycled) = connect_socket(unit, host, use_pooled, spoofed_host)?;
|
||||
|
||||
if is_recycled {
|
||||
debug!("sending request (reused connection) {} {}", method, url);
|
||||
@@ -354,7 +352,7 @@ fn extract_cookies(agent: &Agent, url: &Url) -> Option<Header> {
|
||||
}
|
||||
|
||||
/// Connect the socket, either by using the pool or grab a new one.
|
||||
fn connect_socket(unit: &Unit, hostname: &str, use_pooled: bool) -> Result<(Stream, bool), Error> {
|
||||
fn connect_socket(unit: &Unit, hostname: &str, use_pooled: bool, spoofed_host: Option<&str>) -> Result<(Stream, bool), Error> {
|
||||
match unit.url.scheme() {
|
||||
"http" | "https" | "test" => (),
|
||||
scheme => return Err(ErrorKind::UnknownScheme.msg(format!("unknown scheme '{}'", scheme))),
|
||||
@@ -378,8 +376,13 @@ fn connect_socket(unit: &Unit, hostname: &str, use_pooled: bool) -> Result<(Stre
|
||||
}
|
||||
}
|
||||
let stream = match unit.url.scheme() {
|
||||
"http" => stream::connect_http(unit, hostname),
|
||||
"https" => stream::connect_https(unit, hostname),
|
||||
|
||||
// http can just have the hostname spoofed as is
|
||||
"http" => stream::connect_http(unit, spoofed_host.unwrap_or(hostname)),
|
||||
|
||||
// https requires both the spoofed and non spoofed host names
|
||||
"https" => stream::connect_https(unit, hostname, spoofed_host),
|
||||
|
||||
"test" => connect_test(unit),
|
||||
scheme => Err(ErrorKind::UnknownScheme.msg(format!("unknown scheme {}", scheme))),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user