mirror of
https://github.com/rustdesk/hbb_common.git
synced 2026-10-25 21:50:07 +00:00
fix: bracket IPv6 targets in HTTP CONNECT requests
This commit is contained in:
1 parent
3aade011c0
commit
9ee2f3ef9a
2 files changed
+11
-1
No files matched your search
@@ -663,6 +663,10 @@ impl Proxy {
|
|||||||
|
|
||||||
fn get_domain_and_port<'a>(target_addr: &TargetAddr<'a>) -> Result<(String, u16), ProxyError> {
|
fn get_domain_and_port<'a>(target_addr: &TargetAddr<'a>) -> Result<(String, u16), ProxyError> {
|
||||||
match target_addr {
|
match target_addr {
|
||||||
|
// CONNECT requires brackets around IPv6 literals in both the target and Host header.
|
||||||
|
tokio_socks::TargetAddr::Ip(SocketAddr::V6(addr)) => {
|
||||||
|
Ok((format!("[{}]", addr.ip()), addr.port()))
|
||||||
|
}
|
||||||
tokio_socks::TargetAddr::Ip(addr) => Ok((addr.ip().to_string(), addr.port())),
|
tokio_socks::TargetAddr::Ip(addr) => Ok((addr.ip().to_string(), addr.port())),
|
||||||
tokio_socks::TargetAddr::Domain(name, port) => Ok((name.to_string(), *port)),
|
tokio_socks::TargetAddr::Domain(name, port) => Ok((name.to_string(), *port)),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ async fn proxy_round_trip(
|
|||||||
upsert_tls_cache(url, tls_type, true);
|
upsert_tls_cache(url, tls_type, true);
|
||||||
let target = url::Url::parse(url).unwrap();
|
let target = url::Url::parse(url).unwrap();
|
||||||
let host = target.host_str().unwrap().to_owned();
|
let host = target.host_str().unwrap().to_owned();
|
||||||
|
let domain = target.domain().map(str::to_owned);
|
||||||
let port = target.port_or_known_default().unwrap();
|
let port = target.port_or_known_default().unwrap();
|
||||||
let authority = match target.port() {
|
let authority = match target.port() {
|
||||||
Some(port) => format!("{host}:{port}"),
|
Some(port) => format!("{host}:{port}"),
|
||||||
@@ -148,7 +149,7 @@ async fn proxy_round_trip(
|
|||||||
stream.flush().await.unwrap();
|
stream.flush().await.unwrap();
|
||||||
if wss {
|
if wss {
|
||||||
let tls = tls_acceptor().accept(stream).await.unwrap();
|
let tls = tls_acceptor().accept(stream).await.unwrap();
|
||||||
assert_eq!(tls.get_ref().1.server_name(), Some(host.as_str()));
|
assert_eq!(tls.get_ref().1.server_name(), domain.as_deref());
|
||||||
stream = DynTcpStream(Box::new(tls));
|
stream = DynTcpStream(Box::new(tls));
|
||||||
}
|
}
|
||||||
echo(stream, &path, &authority).await;
|
echo(stream, &path, &authority).await;
|
||||||
@@ -310,6 +311,11 @@ async fn websocket_proxy_connections() {
|
|||||||
// Keep configuration changes inside this integration test process.
|
// Keep configuration changes inside this integration test process.
|
||||||
*APP_NAME.write().unwrap() = format!("RustDesk WebSocket Test {}", std::process::id());
|
*APP_NAME.write().unwrap() = format!("RustDesk WebSocket Test {}", std::process::id());
|
||||||
option(keys::OPTION_ALLOW_INSECURE_TLS_FALLBACK, "Y");
|
option(keys::OPTION_ALLOW_INSECURE_TLS_FALLBACK, "Y");
|
||||||
|
for scheme in ["http", "https"] {
|
||||||
|
for url in ["ws://[::1]:21119", "wss://[::1]:21119"] {
|
||||||
|
proxy_round_trip(scheme, url, TlsType::Rustls, false, false).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (scheme, url, tls_type, auth, configured) in [
|
for (scheme, url, tls_type, auth, configured) in [
|
||||||
(
|
(
|
||||||
"http",
|
"http",
|
||||||
|
|||||||
Reference in new issue
Block a user