mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
fix: improve authentication recovery and diagnostics
Recognize real GTK Wayland crash messages and keep remote authentication prompts readable. Preserve device identifiers without initializing OpenSSL, validate diagnostic executable paths, and improve release automation. Fixes #669
This commit is contained in:
15 files changed
+294
-15
No files matched your search
@@ -34,6 +34,7 @@ uzers.workspace = true
|
||||
serde_urlencoded.workspace = true
|
||||
md5.workspace = true
|
||||
sha256.workspace = true
|
||||
sha2 = "0.10"
|
||||
uuid = { workspace = true, features = ["v4", "v5", "serde"] }
|
||||
chrono.workspace = true
|
||||
humantime.workspace = true
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Neutral device-anchor transport model and deterministic derivation.
|
||||
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -68,7 +69,7 @@ impl DeviceAnchor {
|
||||
let mut input = domain.to_vec();
|
||||
input.extend_from_slice(seed.as_ref());
|
||||
Self {
|
||||
hardware_id: URL_SAFE_NO_PAD.encode(openssl::sha::sha256(&input)),
|
||||
hardware_id: URL_SAFE_NO_PAD.encode(Sha256::digest(&input)),
|
||||
source,
|
||||
}
|
||||
}
|
||||
@@ -78,11 +79,36 @@ impl DeviceAnchor {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn preserves_existing_hardware_ids_for_all_sources() {
|
||||
let cases: [(AnchorSource, &[u8], &str); 3] = [
|
||||
(
|
||||
AnchorSource::UnixMac,
|
||||
&[0, 17, 34, 51, 68, 85],
|
||||
"UWDOx4AVJEuCAYfJBaPioyGtRfAkJBhMYSi8LuFsE1A",
|
||||
),
|
||||
(
|
||||
AnchorSource::UnixRandom,
|
||||
&[0, 17, 34, 51, 68, 85],
|
||||
"fYXFpivIFuD9Z4I6qSNxUIMTljeLvw4xuqXgg0VJAu0",
|
||||
),
|
||||
(
|
||||
AnchorSource::MacosIokit,
|
||||
b"12345678-1234-5678-9abc-def012345678",
|
||||
"K1KMtAwiOiXKQvQuRmTDKPA6-ZPF5QKUWZzmvRzeP34",
|
||||
),
|
||||
];
|
||||
for (source, seed, expected) in cases {
|
||||
let anchor = DeviceAnchor::derive(source, seed);
|
||||
assert_eq!(anchor.hardware_id, expected, "{source:?}");
|
||||
assert!(anchor.validate());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hashes_original_seed_order_with_stable_domain_separation() {
|
||||
let mac = DeviceAnchor::derive(AnchorSource::UnixMac, [0, 17, 34, 51, 68, 85]);
|
||||
assert!(mac.validate());
|
||||
assert_eq!(mac.hardware_id, "UWDOx4AVJEuCAYfJBaPioyGtRfAkJBhMYSi8LuFsE1A");
|
||||
assert_ne!(
|
||||
mac.hardware_id,
|
||||
DeviceAnchor::derive(AnchorSource::UnixMac, [85, 68, 51, 34, 17, 0]).hardware_id
|
||||
|
||||
@@ -510,7 +510,7 @@ mod tests {
|
||||
let executable = directory.path().join("auth-fixture");
|
||||
std::fs::write(
|
||||
&executable,
|
||||
"#!/bin/sh\nprintf 'Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display\\n' >&2\nexit 71\n",
|
||||
"#!/bin/sh\nprintf 'Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display.\\n' >&2\nexit 1\n",
|
||||
)
|
||||
.unwrap();
|
||||
// The launcher drops root privileges in CI; its child must be able to
|
||||
|
||||
@@ -110,7 +110,7 @@ mod tests {
|
||||
let path = fixture(
|
||||
&dir,
|
||||
&credential,
|
||||
"printf '(gpgui-helper:42): Gdk-Message: 12:00:00: Error 71 (Protocol error) dispatching to Wayland display\\n' >&2; exit 71",
|
||||
"printf '(gpgui-helper:42): Gdk-Message: 12:00:00: Error 71 (Protocol error) dispatching to Wayland display.\\n' >&2; exit 1",
|
||||
);
|
||||
let mut envs = HashMap::from([("WAYLAND_DISPLAY".into(), "wayland-0".into())]);
|
||||
for override_value in [None, Some(""), Some("0"), Some("1")] {
|
||||
|
||||
@@ -97,14 +97,15 @@ impl StderrDiagnostic {
|
||||
}
|
||||
|
||||
fn check_line(&mut self) {
|
||||
let line = self.line.as_slice();
|
||||
let line = self.line.trim_ascii_end();
|
||||
let message = line.strip_suffix(b".").unwrap_or(line);
|
||||
if !self.overflow
|
||||
&& (line.starts_with(b"Gdk-Message:")
|
||||
|| line.starts_with(b"(gpgui:")
|
||||
|| line.starts_with(b"(gpauth:")
|
||||
|| line.starts_with(b"(gpgui-helper:"))
|
||||
&& line.windows(b"Gdk-Message:".len()).any(|part| part == b"Gdk-Message:")
|
||||
&& line.strip_suffix(b"\r").unwrap_or(line).ends_with(DIAGNOSTIC)
|
||||
&& message.ends_with(DIAGNOSTIC)
|
||||
{
|
||||
self.matched = true;
|
||||
}
|
||||
@@ -123,13 +124,49 @@ mod tests {
|
||||
#[test]
|
||||
fn recognizes_split_diagnostic_without_matching_quoted_warning() {
|
||||
let mut observer = StderrDiagnostic::default();
|
||||
observer.push(b"warning: Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display\n");
|
||||
observer.push(b"warning: Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display.\n");
|
||||
assert!(!observer.matched());
|
||||
observer.push(b"Gdk-Message: 12:00:00: Error 71 (Protocol error) dispat");
|
||||
observer.push(b"ching to Wayland display\n");
|
||||
observer.push(b"ching to Wayland display.\n");
|
||||
assert!(observer.matched());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recognizes_real_gtk_diagnostic_with_prefix_and_line_endings() {
|
||||
for prefix in [
|
||||
"Gdk-Message:",
|
||||
"(gpauth:42): Gdk-Message:",
|
||||
"(gpgui:42): Gdk-Message:",
|
||||
"(gpgui-helper:42): Gdk-Message:",
|
||||
] {
|
||||
for punctuation in ["", "."] {
|
||||
for ending in ["\n", "\r\n", "", " \t\n"] {
|
||||
let line = format!(
|
||||
"{prefix} 10:49:22.617: Error 71 (Protocol error) dispatching to Wayland display{punctuation}{ending}"
|
||||
);
|
||||
let mut observer = StderrDiagnostic::default();
|
||||
for chunk in line.as_bytes().chunks(7) {
|
||||
observer.push(chunk);
|
||||
}
|
||||
assert!(observer.matched(), "unrecognized GTK diagnostic: {line:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_quoted_or_extended_gtk_diagnostic() {
|
||||
for line in [
|
||||
"warning: Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display.\n",
|
||||
"Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display. Retry suggested\n",
|
||||
"Gdk-Message: Error 70 (Communication error) dispatching to Wayland display.\n",
|
||||
] {
|
||||
let mut observer = StderrDiagnostic::default();
|
||||
observer.push(line.as_bytes());
|
||||
assert!(!observer.matched(), "incorrectly recognized: {line:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized_lines_do_not_grow_or_match() {
|
||||
let mut observer = StderrDiagnostic::default();
|
||||
|
||||
Reference in new issue
Block a user