mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
refactor: align GP profile and packaging flow
Main changes: - Refactor connect/auth flows around a single OS profile and host identity model, including gateway fallback and cookie-on-stdin handling. - Align request parameters, HIP host-id propagation, SAML webview user-agent behavior, and portal default-browser handling with observed official client behavior. - Add opt-in cookie cache support and Microsoft Defender HIP reporting while keeping host-id validation explicit. - Add BSD build, packaging, release artifact, and provenance support with FreeBSD/OpenBSD path and dependency cleanup. - Update NixOS install documentation and dependency compatibility fixes.
This commit is contained in:
92 files changed
+9847
-2868
No files matched your search
@@ -1,108 +0,0 @@
|
||||
use std::sync::OnceLock;
|
||||
|
||||
const DEFAULT_MACOS_VERSION: &str = "13.4.0";
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
const DEFAULT_LINUX_DISTRO: &str = "Ubuntu 24.04.3 LTS";
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
const DEFAULT_WINDOWS_DISTRO: &str = "Windows 11 Pro";
|
||||
const DEFAULT_WINDOWS_VERSION: &str = "10.0.22631.0";
|
||||
const DEFAULT_MACHINE_ID: &str = "DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF";
|
||||
|
||||
static MACHINE_ID: OnceLock<&'static str> = OnceLock::new();
|
||||
static MACOS_VERSION: OnceLock<&'static str> = OnceLock::new();
|
||||
static MACOS_OS_STRING: OnceLock<String> = OnceLock::new();
|
||||
static LINUX_OS_STRING: OnceLock<String> = OnceLock::new();
|
||||
static WINDOWS_VERSION: OnceLock<&'static str> = OnceLock::new();
|
||||
static WINDOWS_OS_STRING: OnceLock<String> = OnceLock::new();
|
||||
|
||||
/// On macOS, get the OS version, or fallback to default
|
||||
/// On other OSes, always return default
|
||||
pub fn get_macos_version() -> &'static str {
|
||||
MACOS_VERSION.get_or_init(|| {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
match os_info::get().version() {
|
||||
os_info::Version::Unknown => DEFAULT_MACOS_VERSION,
|
||||
v => v.to_string().leak(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
DEFAULT_MACOS_VERSION
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_macos_os_string() -> &'static str {
|
||||
MACOS_OS_STRING.get_or_init(|| format!("Apple Mac OS X {}", get_macos_version()))
|
||||
}
|
||||
|
||||
/// On Linux, use the real distro name if possible
|
||||
/// On other OSes, fallback to default
|
||||
pub fn get_linux_os_string() -> &'static str {
|
||||
LINUX_OS_STRING.get_or_init(|| {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
format!("Linux {}", whoami::distro())
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
format!("Linux {}", DEFAULT_LINUX_DISTRO)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// On Windows, get the OS version, or fallback to default
|
||||
/// On other OSes, always return default
|
||||
pub fn get_windows_version() -> &'static str {
|
||||
WINDOWS_VERSION.get_or_init(|| {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
match os_info::get().version() {
|
||||
os_info::Version::Unknown => DEFAULT_WINDOWS_VERSION,
|
||||
v => format!("{}.0", v).leak(),
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
DEFAULT_WINDOWS_VERSION
|
||||
})
|
||||
}
|
||||
|
||||
/// On Windows, use the real edition if possible
|
||||
/// On other OSes, fallback to default
|
||||
/// The trailing space is intentional
|
||||
pub fn get_windows_os_string() -> &'static str {
|
||||
WINDOWS_OS_STRING.get_or_init(|| {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let edition = os_info::get()
|
||||
.edition()
|
||||
.map(|e| e.to_string())
|
||||
.unwrap_or_else(|| whoami::distro());
|
||||
format!("Microsoft {} , 64-bit", edition)
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
format!("Microsoft {} , 64-bit", DEFAULT_WINDOWS_DISTRO)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Get machine ID or fallback to default
|
||||
pub fn get_machine_id() -> &'static str {
|
||||
MACHINE_ID.get_or_init(|| {
|
||||
machine_uid::get()
|
||||
.map(|id| id.to_string().leak() as &'static str)
|
||||
.unwrap_or(DEFAULT_MACHINE_ID)
|
||||
})
|
||||
}
|
||||
|
||||
/// Generate a UUID v5 based on machine ID and provided seeds
|
||||
pub fn derive_uuid(seeds: &[&str]) -> String {
|
||||
use uuid::Uuid;
|
||||
|
||||
let namespace = Uuid::NAMESPACE_DNS;
|
||||
let name = format!("{}-{}", get_machine_id(), seeds.join("-"));
|
||||
|
||||
let uuid = Uuid::new_v5(&namespace, name.as_bytes());
|
||||
uuid.hyphenated().to_string()
|
||||
}
|
||||
@@ -5,7 +5,6 @@ pub mod checksum;
|
||||
pub mod crypto;
|
||||
pub mod endpoint;
|
||||
pub mod env_utils;
|
||||
pub mod host_utils;
|
||||
pub mod lock_file;
|
||||
pub mod openssl;
|
||||
pub mod redact;
|
||||
|
||||
@@ -123,6 +123,46 @@ pub fn redact_uri(uri: &str) -> String {
|
||||
url.to_string()
|
||||
}
|
||||
|
||||
pub fn redact_form_params(params: &[(&str, &str)]) -> String {
|
||||
let mut pairs = params
|
||||
.iter()
|
||||
.map(|(key, value)| (*key, redact_form_value(key, value)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
pairs.sort_by(|(left, _), (right, _)| left.cmp(right));
|
||||
|
||||
form_urlencoded::Serializer::new(String::new())
|
||||
.extend_pairs(pairs)
|
||||
.finish()
|
||||
}
|
||||
|
||||
fn redact_form_value(key: &str, value: &str) -> String {
|
||||
if value.is_empty() || is_safe_form_param(key) {
|
||||
return value.to_string();
|
||||
}
|
||||
|
||||
format!("redacted-{}", value.len())
|
||||
}
|
||||
|
||||
fn is_safe_form_param(key: &str) -> bool {
|
||||
matches!(
|
||||
key,
|
||||
"clientVer"
|
||||
| "clientos"
|
||||
| "config-digest"
|
||||
| "csc-digest"
|
||||
| "csc-support"
|
||||
| "direct"
|
||||
| "ipv6-support"
|
||||
| "jnlpReady"
|
||||
| "ok"
|
||||
| "os-version"
|
||||
| "prot"
|
||||
| "swg-auth-token"
|
||||
| "swg-nonce"
|
||||
)
|
||||
}
|
||||
|
||||
fn redact_query(query: Option<&str>) -> Option<String> {
|
||||
let query = query?;
|
||||
|
||||
@@ -190,6 +230,20 @@ mod tests {
|
||||
assert_eq!(redact_uri(uri), "https://f**********r/baz?qux=q**********x");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_should_redact_form_params() {
|
||||
let params = [
|
||||
("portal-userauthcookie", "secret-cookie"),
|
||||
("csc-support", "yes"),
|
||||
("prelogin-cookie", ""),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
redact_form_params(¶ms),
|
||||
"csc-support=yes&portal-userauthcookie=redacted-13&prelogin-cookie="
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_should_redact_data_uri() {
|
||||
let uri = "data:text/plain;a";
|
||||
|
||||
@@ -24,26 +24,49 @@ mod unix {
|
||||
use anyhow::bail;
|
||||
use gtk::{
|
||||
EventBox,
|
||||
glib::Cast,
|
||||
glib::{self, Cast},
|
||||
traits::{EventBoxExt, GtkWindowExt, WidgetExt},
|
||||
};
|
||||
use log::info;
|
||||
use tauri::WebviewWindow;
|
||||
use tokio::process::Command;
|
||||
|
||||
/// Wrapper to mark a non-Send closure as Send for dispatch to the GTK main thread.
|
||||
///
|
||||
/// SAFETY: The caller must ensure the closure is only executed on the GTK main
|
||||
/// thread. This is guaranteed by `glib::MainContext::default().invoke()`.
|
||||
struct SendFn(Box<dyn FnOnce()>);
|
||||
unsafe impl Send for SendFn {}
|
||||
|
||||
impl SendFn {
|
||||
fn invoke(self) {
|
||||
(self.0)();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn raise_window(win: &WebviewWindow) -> anyhow::Result<()> {
|
||||
let is_wayland = std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland";
|
||||
|
||||
if is_wayland {
|
||||
let gtk_win = win.gtk_window()?;
|
||||
if let Some(header) = gtk_win.titlebar() {
|
||||
let _ = header.downcast::<EventBox>().map(|event_box| {
|
||||
event_box.set_above_child(false);
|
||||
});
|
||||
}
|
||||
|
||||
gtk_win.hide();
|
||||
gtk_win.show_all();
|
||||
// GTK operations must run on the main thread. When this function is called
|
||||
// from a background thread (e.g., rspc handler on a tokio worker), calling
|
||||
// GTK widget methods directly causes crashes in GTK's CSS subsystem
|
||||
// (gtk_css_value_inherit_free assertion failure). Dispatch to the main
|
||||
// thread via glib::MainContext to ensure thread safety.
|
||||
let send_fn = SendFn(Box::new(move || {
|
||||
if let Some(header) = gtk_win.titlebar() {
|
||||
let _ = header.downcast::<EventBox>().map(|event_box| {
|
||||
event_box.set_above_child(false);
|
||||
});
|
||||
}
|
||||
|
||||
gtk_win.hide();
|
||||
gtk_win.show_all();
|
||||
}));
|
||||
|
||||
glib::MainContext::default().invoke(move || send_fn.invoke());
|
||||
} else {
|
||||
if !win.is_visible()? {
|
||||
win.show()?;
|
||||
|
||||
@@ -46,10 +46,10 @@ impl ElementExt for Element {
|
||||
}
|
||||
|
||||
for child in &self.children {
|
||||
if let Some(element) = child.as_element() {
|
||||
if let Some(found) = element.descendant(name) {
|
||||
return Some(found);
|
||||
}
|
||||
if let Some(element) = child.as_element()
|
||||
&& let Some(found) = element.descendant(name)
|
||||
{
|
||||
return Some(found);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user