From fab1e5a104d48360ca13c9aa8d8976c9e4b1e71c Mon Sep 17 00:00:00 2001 From: jasonwitty Date: Fri, 22 Aug 2025 22:39:06 -0700 Subject: [PATCH] client: default skip hostname verification; add --verify-hostname to enable --- socktop/src/main.rs | 17 +++++++++++++++-- socktop/src/ws.rs | 8 ++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/socktop/src/main.rs b/socktop/src/main.rs index c1f6c67..259fad8 100644 --- a/socktop/src/main.rs +++ b/socktop/src/main.rs @@ -21,6 +21,7 @@ pub(crate) struct ParsedArgs { dry_run: bool, // hidden test helper: skip connecting metrics_interval_ms: Option, processes_interval_ms: Option, + verify_hostname: bool, } pub(crate) fn parse_args>(args: I) -> Result { @@ -34,14 +35,21 @@ pub(crate) fn parse_args>(args: I) -> Result = None; let mut processes_interval_ms: Option = None; + let mut verify_hostname = false; while let Some(arg) = it.next() { match arg.as_str() { "-h" | "--help" => { - return Err(format!("Usage: {prog} [--tls-ca CERT_PEM|-t CERT_PEM] [--profile NAME|-P NAME] [--save] [--demo] [--metrics-interval-ms N] [--processes-interval-ms N] [ws://HOST:PORT/ws]\n")); + return Err(format!("Usage: {prog} [--tls-ca CERT_PEM|-t CERT_PEM] [--verify-hostname] [--profile NAME|-P NAME] [--save] [--demo] [--metrics-interval-ms N] [--processes-interval-ms N] [ws://HOST:PORT/ws]\n")); } "--tls-ca" | "-t" => { tls_ca = it.next(); } + "--verify-hostname" => { + // opt-in hostname (SAN) verification + // default behavior is to skip it for easier home network usage + // (still pins the provided certificate) + verify_hostname = true; + } "--profile" | "-P" => { profile = it.next(); } @@ -89,7 +97,7 @@ pub(crate) fn parse_args>(args: I) -> Result>(args: I) -> Result Result<(), Box> { if parsed.demo || matches!(parsed.profile.as_deref(), Some("demo")) { return run_demo_mode(parsed.tls_ca.as_deref()).await; } + if parsed.verify_hostname { + // Set env var consumed by ws::connect logic + std::env::set_var("SOCKTOP_VERIFY_NAME", "1"); + } let profiles_file = load_profiles(); let req = ProfileRequest { profile_name: parsed.profile.clone(), diff --git a/socktop/src/ws.rs b/socktop/src/ws.rs index 7f85e9a..fd3eaef 100644 --- a/socktop/src/ws.rs +++ b/socktop/src/ws.rs @@ -56,8 +56,12 @@ async fn connect_with_ca(url: &str, ca_path: &str) -> Result