mirror of
https://github.com/rustdesk/hbb_common.git
synced 2026-12-01 18:24:29 +00:00
Merge branch 'main' into fix/trusted-device-v2
This commit is contained in:
commit
f15eb3d40d
3 files changed
+85
-4
No files matched your search
@@ -2966,6 +2966,7 @@ pub mod keys {
|
|||||||
pub const OPTION_ALLOW_NUMERNIC_ONE_TIME_PASSWORD: &str = "allow-numeric-one-time-password";
|
pub const OPTION_ALLOW_NUMERNIC_ONE_TIME_PASSWORD: &str = "allow-numeric-one-time-password";
|
||||||
pub const OPTION_DIRECT_SERVER: &str = "direct-server";
|
pub const OPTION_DIRECT_SERVER: &str = "direct-server";
|
||||||
pub const OPTION_ALLOW_WEBSOCKET: &str = "allow-websocket";
|
pub const OPTION_ALLOW_WEBSOCKET: &str = "allow-websocket";
|
||||||
|
pub const OPTION_WEBSOCKET_PORT: &str = "websocket-port";
|
||||||
pub const OPTION_TRACKPAD_SPEED: &str = "trackpad-speed";
|
pub const OPTION_TRACKPAD_SPEED: &str = "trackpad-speed";
|
||||||
pub const OPTION_REGISTER_DEVICE: &str = "register-device";
|
pub const OPTION_REGISTER_DEVICE: &str = "register-device";
|
||||||
pub const OPTION_RELAY_SERVER: &str = "relay-server";
|
pub const OPTION_RELAY_SERVER: &str = "relay-server";
|
||||||
|
|||||||
+2
-2
@@ -437,7 +437,7 @@ pub fn init_log(_is_async: bool, _name: &str) -> Option<flexi_logger::LoggerHand
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
use env_logger::*;
|
use env_logger::*;
|
||||||
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info,reqwest=warn,hyper_util=warn,rustls=warn,webrtc-sctp=warn,webrtc=warn,webrtc_ice::agent::agent_internal=error,webrtc::peer_connection=error"));
|
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info,reqwest=warn,hyper_util=warn,rustls=warn,webrtc-sctp=warn,webrtc=warn,webrtc_ice::agent::agent_internal=error,webrtc::peer_connection=error,smithay_client_toolkit=warn"));
|
||||||
}
|
}
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
{
|
{
|
||||||
@@ -452,7 +452,7 @@ pub fn init_log(_is_async: bool, _name: &str) -> Option<flexi_logger::LoggerHand
|
|||||||
path.push(_name);
|
path.push(_name);
|
||||||
}
|
}
|
||||||
use flexi_logger::*;
|
use flexi_logger::*;
|
||||||
if let Ok(x) = Logger::try_with_env_or_str("debug,reqwest=warn,hyper_util=warn,rustls=warn,webrtc-sctp=warn,webrtc=warn,webrtc_ice::agent::agent_internal=error,webrtc::peer_connection=error") {
|
if let Ok(x) = Logger::try_with_env_or_str("debug,reqwest=warn,hyper_util=warn,rustls=warn,webrtc-sctp=warn,webrtc=warn,webrtc_ice::agent::agent_internal=error,webrtc::peer_connection=error,smithay_client_toolkit=warn") {
|
||||||
logger_holder = x
|
logger_holder = x
|
||||||
.log_to_file(FileSpec::default().directory(path))
|
.log_to_file(FileSpec::default().directory(path))
|
||||||
.write_mode(if _is_async {
|
.write_mode(if _is_async {
|
||||||
|
|||||||
+82
-2
@@ -1,6 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::{
|
config::{
|
||||||
keys::OPTION_RELAY_SERVER, use_ws, Config, Socks5Server, RELAY_PORT, RENDEZVOUS_PORT,
|
keys::{OPTION_RELAY_SERVER, OPTION_WEBSOCKET_PORT},
|
||||||
|
use_ws, Config, Socks5Server, EXE_RENDEZVOUS_SERVER, PROD_RENDEZVOUS_SERVER, RELAY_PORT,
|
||||||
|
RENDEZVOUS_PORT,
|
||||||
},
|
},
|
||||||
protobuf::Message,
|
protobuf::Message,
|
||||||
socket_client::split_host_port,
|
socket_client::split_host_port,
|
||||||
@@ -513,7 +515,10 @@ pub fn check_ws(endpoint: &str) -> String {
|
|||||||
(format!("{}:{}", endpoint_host, dst_port), false)
|
(format!("{}:{}", endpoint_host, dst_port), false)
|
||||||
} else {
|
} else {
|
||||||
let domain_path = if relay { "/ws/relay" } else { "/ws/id" };
|
let domain_path = if relay { "/ws/relay" } else { "/ws/id" };
|
||||||
(format!("{}{}", endpoint_host, domain_path), true)
|
let port = websocket_port(&endpoint_host, &relay_server)
|
||||||
|
.map(|port| format!(":{}", port))
|
||||||
|
.unwrap_or_default();
|
||||||
|
(format!("{}{}{}", endpoint_host, port, domain_path), true)
|
||||||
};
|
};
|
||||||
let protocol = if is_domain {
|
let protocol = if is_domain {
|
||||||
let api_server = Config::get_option("api-server");
|
let api_server = Config::get_option("api-server");
|
||||||
@@ -528,6 +533,45 @@ pub fn check_ws(endpoint: &str) -> String {
|
|||||||
format!("{}://{}", protocol, address)
|
format!("{}://{}", protocol, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Port of the reverse proxy serving `/ws/id` and `/ws/relay` on this client's own servers, for
|
||||||
|
/// when it cannot listen on the scheme's default port. Any other host, such as a peer's server or
|
||||||
|
/// a relay on another machine, keeps the default port. IP endpoints never get here.
|
||||||
|
fn websocket_port(host: &str, relay_server: &str) -> Option<u16> {
|
||||||
|
let port = Config::get_option(OPTION_WEBSOCKET_PORT);
|
||||||
|
if port.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
// Only servers this client is set up with, not the public fallback of get_rendezvous_server().
|
||||||
|
let own_servers = [
|
||||||
|
EXE_RENDEZVOUS_SERVER.read().unwrap().clone(),
|
||||||
|
Config::get_option("custom-rendezvous-server"),
|
||||||
|
PROD_RENDEZVOUS_SERVER.read().unwrap().clone(),
|
||||||
|
relay_server.to_owned(),
|
||||||
|
];
|
||||||
|
let is_own = own_servers.iter().any(|server| {
|
||||||
|
split_host_port(server)
|
||||||
|
.map(|(h, _)| h)
|
||||||
|
.unwrap_or_else(|| server.to_string())
|
||||||
|
.eq_ignore_ascii_case(host)
|
||||||
|
});
|
||||||
|
if !is_own {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
match port.parse::<u16>() {
|
||||||
|
Ok(port) if port > 0 => Some(port),
|
||||||
|
_ => {
|
||||||
|
crate::throttled_log!(
|
||||||
|
Duration::from_secs(60),
|
||||||
|
warn,
|
||||||
|
"Ignoring invalid {}: {}",
|
||||||
|
OPTION_WEBSOCKET_PORT,
|
||||||
|
port
|
||||||
|
);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod proxy_tests;
|
mod proxy_tests;
|
||||||
|
|
||||||
@@ -709,6 +753,42 @@ mod tests {
|
|||||||
assert_eq!(check_ws("127.0.0.1:23455"), "ws://127.0.0.1:23458");
|
assert_eq!(check_ws("127.0.0.1:23455"), "ws://127.0.0.1:23458");
|
||||||
assert_eq!(check_ws("127.0.0.1:23456"), "ws://127.0.0.1:23458");
|
assert_eq!(check_ws("127.0.0.1:23456"), "ws://127.0.0.1:23458");
|
||||||
assert_eq!(check_ws("127.0.0.1:34567"), "ws://127.0.0.1:34569");
|
assert_eq!(check_ws("127.0.0.1:34567"), "ws://127.0.0.1:34569");
|
||||||
|
|
||||||
|
// set websocket-port, a reverse proxy off the default port on our own servers
|
||||||
|
Config::set_option(
|
||||||
|
"custom-rendezvous-server".to_string(),
|
||||||
|
"rustdesk.com".to_string(),
|
||||||
|
);
|
||||||
|
Config::set_option("relay-server".to_string(), "relay.rustdesk.com".to_string());
|
||||||
|
Config::set_option(
|
||||||
|
"api-server".to_string(),
|
||||||
|
"https://rustdesk.com:8443".to_string(),
|
||||||
|
);
|
||||||
|
Config::set_option(keys::OPTION_WEBSOCKET_PORT.to_string(), "8443".to_string());
|
||||||
|
assert_eq!(
|
||||||
|
check_ws("rustdesk.com:21116"),
|
||||||
|
"wss://rustdesk.com:8443/ws/id"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
check_ws("rustdesk.com:21117"),
|
||||||
|
"wss://rustdesk.com:8443/ws/relay"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
check_ws("relay.rustdesk.com:21117"),
|
||||||
|
"wss://relay.rustdesk.com:8443/ws/relay"
|
||||||
|
);
|
||||||
|
// a peer's server or a relay on another host keeps the default port
|
||||||
|
assert_eq!(check_ws("example.com:21116"), "wss://example.com/ws/id");
|
||||||
|
assert_eq!(check_ws("example.com:21117"), "wss://example.com/ws/relay");
|
||||||
|
assert_eq!(check_ws("127.0.0.1:21116"), "ws://127.0.0.1:21118");
|
||||||
|
// with no rendezvous server set, the public fallback is not one of ours
|
||||||
|
Config::set_option("custom-rendezvous-server".to_string(), "".to_string());
|
||||||
|
let fallback = Config::get_rendezvous_server();
|
||||||
|
let (fallback_host, _) = split_host_port(&fallback).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
check_ws(&fallback),
|
||||||
|
format!("wss://{}/ws/id", fallback_host)
|
||||||
|
);
|
||||||
Config::set_options(options);
|
Config::set_options(options);
|
||||||
}
|
}
|
||||||
// A server-to-client frame is unmasked, so it can be put on the wire by hand: the header alone,
|
// A server-to-client frame is unmasked, so it can be put on the wire by hand: the header alone,
|
||||||
|
|||||||
Reference in new issue
Block a user