fix: redact tunnel keys, preserve cached login and correct HIP handling

This commit is contained in:
Kevin Yue committed 2026-11-18 18:08:01 +08:00
1 parent 65fce7bcf0
commit 9a43880c4d
18 files changed
+412 -196

No files matched your search

+46
View File
@@ -153,6 +153,14 @@ extern "C" fn on_vpn_connected(pipe_fd: CommandHandle, session_info: *const VpnS
extern "C" fn vpn_log(level: i32, message: *const c_char) {
let message = unsafe { std::ffi::CStr::from_ptr(message) };
let message = message.to_str().unwrap_or("Invalid log message");
// This dump comes from the native GlobalProtect protocol handler.
if let Some(body) = message.strip_prefix("GlobalProtect getconfig.esp response:\n") {
debug!(
"GlobalProtect getconfig.esp response:\n{}",
gp_xml::redact_xml(body.as_bytes())
);
return;
}
// Strip the trailing newline
let message = message.trim_end_matches('\n');
@@ -172,3 +180,41 @@ extern "C" fn vpn_log(level: i32, message: *const c_char) {
debug!("{}", message);
}
}
#[cfg(test)]
mod log_tests {
use super::vpn_log;
use std::sync::Mutex;
struct Capture(Mutex<String>);
impl log::Log for Capture {
fn enabled(&self, _: &log::Metadata<'_>) -> bool {
true
}
fn flush(&self) {}
fn log(&self, record: &log::Record<'_>) {
if record.target() == module_path!().trim_end_matches("::log_tests") {
self.0.lock().unwrap().push_str(&record.args().to_string());
}
}
}
#[test]
fn native_config_dump_keeps_settings_and_redacts_keys_before_logging() {
static CAPTURE: Capture = Capture(Mutex::new(String::new()));
log::set_logger(&CAPTURE).unwrap();
log::set_max_level(log::LevelFilter::Debug);
let message = c"GlobalProtect getconfig.esp response:\n<response><mtu>1400</mtu><akey-c2s><val>fixture-secret</val></akey-c2s><hs-key><bits>128</bits><val>fixture-handshake-key</val></hs-key></response>\n";
vpn_log(2, message.as_ptr());
vpn_log(
2,
c"GlobalProtect getconfig.esp response:\n<malformed>fixture-secret".as_ptr(),
);
let output = CAPTURE.0.lock().unwrap();
assert!(output.contains("<mtu>1400</mtu>"));
assert!(output.contains("[redacted]"));
assert!(output.contains("[XML omitted:"));
assert!(!output.contains("fixture-secret"));
assert!(!output.contains("fixture-handshake-key"));
}
}