Compare commits

...
Author SHA1 Message Date
Kevin Yue 861997395e nlb improvment 2026-06-27 13:13:00 +08:00
Kevin Yue ea0270780a fix: improve nlb handling 2026-06-26 21:23:42 +08:00
Kevin Yue 0283f0147c fix: esp gcm algo [codex] 2026-06-26 16:06:27 +08:00
Kevin Yue d637542ddd fix: esp gcm algo 2026-06-26 09:26:44 +08:00
Kevin Yue b5ea3c9c22 Bump openconnect: fix ESP-GCM nonce for GlobalProtect gateways
Use IV||seq GCM nonce matching official PanGPS instead of RFC4106
salt||IV, which caused ESP probes to be silently dropped on
aes-256-gcm gateways.
2026-06-26 08:46:07 +08:00
Kevin Yue bdaea1b247 Bump openconnect submodule for ESP-GCM wire header fix
Updates to a669448a: GCM packets now use the RFC4106 8-byte IV on the
wire instead of the 16-byte CBC layout, which was preventing probe
replies and ESP session establishment on GCM gateways.
2026-06-26 07:30:09 +08:00
Kevin Yue 5274fd6282 Bump openconnect submodule for RFC4106 GCM ESP fix
Updates the fork to ae767195, which builds the GCM nonce as salt||IV
per RFC4106 and uses only the cipher key bytes for AES-GCM init. This
fixes ESP session establishment on existing gateways that negotiate
aes-256-gcm after the NLB branch started advertising GCM in getconfig.
2026-06-25 23:50:16 +08:00
Kevin Yue 2b916ef9a0 Migrate OpenConnect patches into GitHub submodule fork
Point openconnect at yuezk/openconnect globalprotect (d5c1925f) with GP
patches 0001-0019 baked in. Point libxml2 at github.com/GNOME/libxml2
keeping the v2.9.9 pin. Remove compile-time patch application from
build.rs and delete deps/patches/.
2026-06-25 22:59:33 +08:00
Kevin Yue 2e0320de5a Fix malformed NLB patch 0012 for CI patch application
Regenerate patch 0012 as a proper git diff against the post-0011 tree.
The previous version used zeroed index headers and a truncated
fake-gp-server.py context line, causing patch(1) to fail in LIBXML2_STATIC
builds.
2026-06-25 22:34:53 +08:00
Kevin Yue 6c31d2fbe7 Fix NLB prepare opaque-key wipe after tunnel-opaque decrypt
gp_nlb_clear_decrypted_opaque zeroed opaque_key after enc-hs-key
decipherment, causing gpst_nlb_prepare to fail when both blobs were
present. Clear opaque_key only at prepare start and replace unused
decrypted_opaque storage with an opaque_body_ready flag.
2026-06-25 21:02:45 +08:00
Kevin Yue 73d900f9b3 Cleanup NLB dead auth fields and tighten error handling
Remove unused hdr_auth/opaque_auth_ready state left after hs-key-only
envelope auth, trigger ESP/SSL reconnect on opaque refresh failure,
and log outbound NLB encap failures at ERR level.
2026-06-25 20:57:49 +08:00
Kevin Yue c93c9ec67f Harden NLB crypto and envelope authentication
Fail prepare when opaque decrypt or hs-key setup is incomplete, require
hs-key for all envelope sign/verify, reject TLS 1.3 for blob decrypt,
fix GnuTLS AES-192 CBC selection, and replace the opaque-auth test with
real HMAC-SHA1 vector checks.
2026-06-25 20:53:55 +08:00
Kevin Yue ebd5e69260 Add NLB troubleshooting logs for gateway testing
Log opaque crypto readiness, envelope sign/verify details with hex
dumps, and richer invalid-packet diagnostics to help debug NLB ESP
envelope auth against live gateways.
2026-06-25 20:43:36 +08:00
Kevin Yue 085d812db5 Wire NLB tunnel-opaque auth into ESP envelope (Phase 6)
Extract 6-byte auth material from decrypted tunnel-opaque, populate
wire sequence and HMAC-SHA1 header tags using hs-key, and verify on
inbound NLB ESP envelopes.
2026-06-25 20:34:15 +08:00
Kevin Yue fe26d2f338 Implement exact PanGPS do_ssl_decrypt NLB blob decipherment
Reverse-engineer PanGPS 6.3.3.1 decrypt_data: derive TLS 1.2 server
write key/IV via key expansion, AES-CBC decrypt ciphertext after the
28-byte cleartext blob prefix, and decrypt tunnel-opaque with the
decrypted enc-hs-key using the same TLS IV.
2026-06-25 19:41:05 +08:00
Kevin Yue 2fa8912d9e Add ESP GCM and NLB enc-hs-key handling (Phase 7)
Implement RFC4106 AES-GCM ESP for GlobalProtect gateways (gnutls and
OpenSSL backends), recognize aes128gcm8/12/16 ICV sizes, and add NLB
enc-hs-key blob parsing with TLS 1.2 session-key decipherment to
decrypt tunnel-opaque payloads.
2026-06-25 19:19:44 +08:00
Kevin Yue a5027d4ff5 Add GlobalProtect NLB integration (Phase 6)
Expose NLB session metadata through the Rust FFI, extend fake-gp-server
with NLB mode for integration testing, wire NLB unit tests into
Makefile.am, recognize AES-GCM algorithm strings in check_enc_algo,
and add gp-nlb-auth-and-config to verify getconfig parsing.
2026-06-25 18:51:42 +08:00
Kevin Yue 5fcef8c5ba Add GlobalProtect NLB lifecycle (Phase 5)
Refresh tunnel-opaque via targeted getconfig.esp when valid-period nears
expiry, without disturbing ESP keys or routes. Send periodic NLB ESP
keepalives on established sessions and reset keepalive state after refresh.
2026-06-25 18:41:22 +08:00
Kevin Yue 81ccdc6358 Add GlobalProtect NLB SSL failover (Phase 4)
Extend gpst_connect for NLB gateways: send install=yes with preferred IPs,
parse the 110...START_TUNNEL line protocol response, update tunnel VIP,
and install a split-include route for the inner gateway IP.
2026-06-25 18:36:39 +08:00
Kevin Yue e05b8fb358 Add GlobalProtect NLB ESP envelope (Phase 3)
Implement the 16-byte NLB UDP wrapper around ESP ciphertext per PanGPS
6.3.3.1 RE: encap/decap in gpst_nlb.c, recv/send hooks in esp.c for
PROTO_GPST, 56-byte NLB probe payloads, and keepalive-before-data on the
first ESP probe exchange.
2026-06-25 18:32:14 +08:00
Kevin Yue 8343d743e0 Add GlobalProtect NLB module skeleton (Phase 2)
Introduce gpst_nlb.c with PanGPS 6.3.3.1 RE notes, base64 opaque blob
decoding, NLB SSL response parsing, and stub ESP encap/decap hooks.
Wire gpst_nlb_prepare into setup and add an SSL parse regression test.
2026-06-25 18:24:11 +08:00
Kevin Yue 79110bbcd8 Add GlobalProtect NLB config parsing (Phase 1)
Parse hs-key, enc-hs-key, tunnel-opaque, and related NLB fields from
getconfig.esp XML into vpninfo, align getconfig request parameters with
the official client, and expose diagnostic APIs for NLB detection.
2026-06-25 18:20:06 +08:00
15 changed files with 27 additions and 586 deletions

No files matched your search

+3 -2
View File
@@ -1,6 +1,7 @@
[submodule "crates/openconnect/deps/openconnect"]
path = crates/openconnect/deps/openconnect
url = https://gitlab.com/openconnect/openconnect.git
url = https://github.com/yuezk/openconnect.git
branch = globalprotect
[submodule "crates/openconnect/deps/libxml2"]
path = crates/openconnect/deps/libxml2
url = https://gitlab.gnome.org/GNOME/libxml2.git
url = https://github.com/GNOME/libxml2.git
+2
View File
@@ -213,6 +213,7 @@ mod tests {
prior_secs: 1_800,
message: "Session expires soon".to_string(),
}),
..Default::default()
},
true,
);
@@ -233,6 +234,7 @@ mod tests {
prior_secs: 1_800,
message: "Session expires soon".to_string(),
}),
..Default::default()
},
false,
);
+3 -37
View File
@@ -1,34 +1,4 @@
use std::{env, path::PathBuf, process::Command};
fn apply_patches(patches_dir: &PathBuf, build_src: &PathBuf) {
let patches = std::fs::read_dir(patches_dir)
.expect("Failed to read patches directory")
.filter_map(|entry| entry.ok())
.filter(|entry| entry.path().extension().and_then(|s| s.to_str()) == Some("patch"))
.map(|entry| entry.path())
.collect::<Vec<_>>();
// Sort patches to ensure they are applied in order
let mut patches = patches;
patches.sort();
for patch in patches {
println!("cargo:rerun-if-changed={}", patch.display());
println!("Applying patch: {}", patch.display());
let status = Command::new("patch")
.arg("-p1") // Strip one level of path (standard for git diffs)
.arg("-i") // Input file
.arg(&patch)
.current_dir(build_src) // Run INSIDE the copied dir
.status()
.expect("Failed to execute patch command");
if !status.success() {
panic!("Failed to apply patch file: {}", patch.display());
}
}
}
use std::{env, path::PathBuf};
fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
let libxml2_dir = deps_dir.join("libxml2");
@@ -91,12 +61,11 @@ fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
let openconnect_dir = deps_dir.join("openconnect");
let patches_dir = deps_dir.join("patches");
// The temporary location where we will build
let build_src = out_dir.join("openconnect_build");
// Track changes so cargo rebuilds if patch or submodule changes
// Track changes so cargo rebuilds if submodule changes
println!("cargo:rerun-if-changed={}", openconnect_dir.display());
// Prepare the build directory
@@ -114,9 +83,6 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
fs_extra::dir::copy(&openconnect_dir, &build_src, &options).expect("Failed to copy C source code to OUT_DIR");
// Apply all patches from the patches directory
apply_patches(&patches_dir, &build_src);
// Build the OpenConnect library using autotools
// We explicitly enable static and disable shared to ensure we get a .a file.
// .reconf("-ivf") is CRITICAL for git submodules because 'configure'
@@ -215,4 +181,4 @@ fn main() {
.include("src/ffi")
.include(&oc_dst.join("include"))
.compile("vpn");
}
}
@@ -1,114 +0,0 @@
From a8d5ec198ca9ae47a0e6b4f1ea244d2738acf055 Mon Sep 17 00:00:00 2001
From: Kevin Yue <[email protected]>
Date: Sun, 14 Dec 2025 17:10:02 +0800
Subject: [PATCH 1/4] Add support for GlobalProtect app version handling
- Introduced `gp_app_version` field in `openconnect_info` structure.
- Implemented `openconnect_set_gp_app_version` and `openconnect_get_gp_app_version` functions.
- Updated `gpst_get_config` to use the app version in requests.
- Free `gp_app_version` in `openconnect_vpninfo_free` to prevent memory leaks.
---
gpst.c | 8 +++++---
library.c | 15 +++++++++++++++
openconnect-internal.h | 4 ++++
openconnect.h | 2 ++
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/gpst.c b/gpst.c
index 244aaf04..5c24bbd2 100644
--- a/gpst.c
+++ b/gpst.c
@@ -650,8 +650,11 @@ static int gpst_get_config(struct openconnect_info *vpninfo)
/* submit getconfig request */
+ const char *app_version = openconnect_get_gp_app_version(vpninfo);
+ vpn_progress(vpninfo, PRG_DEBUG, _("Using GlobalProtect app version: %s\n"), app_version);
+
buf_append(request_body, "client-type=1&protocol-version=p1&internal=no");
- append_opt(request_body, "app-version", vpninfo->csd_ticket ? : "6.3.0-33");
+ append_opt(request_body, "app-version", app_version);
append_opt(request_body, "ipv6-support", vpninfo->disable_ipv6 ? "no" : "yes");
append_opt(request_body, "clientos", gpst_os_name(vpninfo));
append_opt(request_body, "os-version", vpninfo->platname);
@@ -1040,8 +1043,7 @@ static int run_hip_script(struct openconnect_info *vpninfo)
* accept new ones.
*/
unsetenv("APP_VERSION");
- if (vpninfo->csd_ticket)
- if (setenv("APP_VERSION", vpninfo->csd_ticket, 1))
+ if (setenv("APP_VERSION", openconnect_get_gp_app_version(vpninfo), 1))
goto out;
execv(hip_argv[0], (char **)hip_argv);
diff --git a/library.c b/library.c
index b5e74e9b..18334c76 100644
--- a/library.c
+++ b/library.c
@@ -896,6 +896,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
free(vpninfo->localname);
free(vpninfo->useragent);
+ free(vpninfo->gp_app_version);
free(vpninfo->authgroup);
#ifdef HAVE_LIBSTOKEN
if (vpninfo->stoken_pin)
@@ -1019,6 +1020,20 @@ int openconnect_set_useragent(struct openconnect_info *vpninfo,
return 0;
}
+int openconnect_set_gp_app_version(struct openconnect_info *vpninfo,
+ const char *gp_app_version)
+{
+ UTF8CHECK(gp_app_version);
+
+ STRDUP(vpninfo->gp_app_version, gp_app_version);
+ return 0;
+}
+
+const char *openconnect_get_gp_app_version(struct openconnect_info *vpninfo)
+{
+ return vpninfo->csd_ticket ?: (vpninfo->gp_app_version ?: "6.3.0-33");
+}
+
int openconnect_set_urlpath(struct openconnect_info *vpninfo,
const char *urlpath)
{
diff --git a/openconnect-internal.h b/openconnect-internal.h
index abf45bbd..988f85f0 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -786,6 +786,7 @@ struct openconnect_info {
int is_dyndns; /* Attempt to redo DNS lookup on each CSTP reconnect */
char *useragent;
char *version_string;
+ char *gp_app_version;
const char *quit_reason;
const char *delay_tunnel_reason; /* If non-null, provides a reason why protocol is not yet ready for tunnel setup */
@@ -1677,6 +1678,9 @@ void openconnect_set_juniper(struct openconnect_info *vpninfo);
/* hpke.c */
int handle_external_browser(struct openconnect_info *vpninfo);
+/* Get the app version */
+const char *openconnect_get_gp_app_version(struct openconnect_info *vpninfo);
+
/* version.c */
extern const char openconnect_version_str[];
diff --git a/openconnect.h b/openconnect.h
index 136f181a..7d4f3399 100644
--- a/openconnect.h
+++ b/openconnect.h
@@ -470,6 +470,8 @@ int openconnect_set_http_proxy(struct openconnect_info *vpninfo,
int openconnect_set_useragent(struct openconnect_info *vpninfo,
const char *useragent);
+int openconnect_set_gp_app_version(struct openconnect_info *vpninfo,
+ const char *gp_app_version);
int openconnect_passphrase_from_fsid(struct openconnect_info *vpninfo);
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
int openconnect_init_ssl(void);
--
2.50.1 (Apple Git-155)
@@ -1,32 +0,0 @@
From 8591eba702f52dae335601c997271786be50dff7 Mon Sep 17 00:00:00 2001
From: Kevin Yue <[email protected]>
Date: Sun, 14 Dec 2025 17:10:52 +0800
Subject: [PATCH 2/4] Update user agent for common headers in GlobalProtect
authentication
---
auth-globalprotect.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/auth-globalprotect.c b/auth-globalprotect.c
index 8d094273..27e41c2b 100644
--- a/auth-globalprotect.c
+++ b/auth-globalprotect.c
@@ -34,14 +34,7 @@ struct login_context {
void gpst_common_headers(struct openconnect_info *vpninfo,
struct oc_text_buf *buf)
{
- char *orig_ua = vpninfo->useragent;
-
- /* XX: more recent servers don't appear to require this specific UA value,
- * but we don't have any good way to detect them.
- */
- vpninfo->useragent = (char *)"PAN GlobalProtect";
http_common_headers(vpninfo, buf);
- vpninfo->useragent = orig_ua;
}
/* Translate platform names (derived from AnyConnect) into the values
--
2.50.1 (Apple Git-155)
@@ -1,121 +0,0 @@
From dda2aceca7e614af65b968e632065ef223cb6612 Mon Sep 17 00:00:00 2001
From: Kevin Yue <[email protected]>
Date: Sun, 14 Dec 2025 17:14:08 +0800
Subject: [PATCH 3/4] Add support for OS version handling in GlobalProtect
authentication
---
auth-globalprotect.c | 2 +-
gpst.c | 4 ++--
library.c | 15 +++++++++++++++
openconnect-internal.h | 4 ++++
openconnect.h | 3 +++
5 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/auth-globalprotect.c b/auth-globalprotect.c
index 27e41c2b..59d6de3b 100644
--- a/auth-globalprotect.c
+++ b/auth-globalprotect.c
@@ -731,7 +731,7 @@ static int gpst_login(struct openconnect_info *vpninfo, int portal, struct login
buf_append(request_body, "jnlpReady=jnlpReady&ok=Login&direct=yes&clientVer=4100&prot=https:&internal=no");
append_opt(request_body, "ipv6-support", vpninfo->disable_ipv6 ? "no" : "yes");
append_opt(request_body, "clientos", gpst_os_name(vpninfo));
- append_opt(request_body, "os-version", vpninfo->platname);
+ append_opt(request_body, "os-version", openconnect_get_gp_os_version(vpninfo));
append_opt(request_body, "server", vpninfo->hostname);
append_opt(request_body, "computer", vpninfo->localname);
if (ctx->portal_userauthcookie)
diff --git a/gpst.c b/gpst.c
index 5c24bbd2..0373fce0 100644
--- a/gpst.c
+++ b/gpst.c
@@ -657,7 +657,7 @@ static int gpst_get_config(struct openconnect_info *vpninfo)
append_opt(request_body, "app-version", app_version);
append_opt(request_body, "ipv6-support", vpninfo->disable_ipv6 ? "no" : "yes");
append_opt(request_body, "clientos", gpst_os_name(vpninfo));
- append_opt(request_body, "os-version", vpninfo->platname);
+ append_opt(request_body, "os-version", openconnect_get_gp_os_version(vpninfo));
append_opt(request_body, "hmac-algo", "sha1,md5,sha256");
append_opt(request_body, "enc-algo", "aes-128-cbc,aes-256-cbc");
if (old_addr || old_addr6) {
@@ -1044,7 +1044,7 @@ static int run_hip_script(struct openconnect_info *vpninfo)
*/
unsetenv("APP_VERSION");
if (setenv("APP_VERSION", openconnect_get_gp_app_version(vpninfo), 1))
- goto out;
+ goto out;
execv(hip_argv[0], (char **)hip_argv);
diff --git a/library.c b/library.c
index 18334c76..e2169054 100644
--- a/library.c
+++ b/library.c
@@ -897,6 +897,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
free(vpninfo->localname);
free(vpninfo->useragent);
free(vpninfo->gp_app_version);
+ free(vpninfo->gp_os_version);
free(vpninfo->authgroup);
#ifdef HAVE_LIBSTOKEN
if (vpninfo->stoken_pin)
@@ -1034,6 +1035,20 @@ const char *openconnect_get_gp_app_version(struct openconnect_info *vpninfo)
return vpninfo->csd_ticket ?: (vpninfo->gp_app_version ?: "6.3.0-33");
}
+int openconnect_set_gp_os_version(struct openconnect_info *vpninfo,
+ const char *gp_os_version)
+{
+ UTF8CHECK(gp_os_version);
+
+ STRDUP(vpninfo->gp_os_version, gp_os_version);
+ return 0;
+}
+
+const char *openconnect_get_gp_os_version(struct openconnect_info *vpninfo)
+{
+ return vpninfo->gp_os_version ?: vpninfo->platname;
+}
+
int openconnect_set_urlpath(struct openconnect_info *vpninfo,
const char *urlpath)
{
diff --git a/openconnect-internal.h b/openconnect-internal.h
index 988f85f0..5c8d2909 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -787,6 +787,7 @@ struct openconnect_info {
char *useragent;
char *version_string;
char *gp_app_version;
+ char *gp_os_version;
const char *quit_reason;
const char *delay_tunnel_reason; /* If non-null, provides a reason why protocol is not yet ready for tunnel setup */
@@ -1681,6 +1682,9 @@ int handle_external_browser(struct openconnect_info *vpninfo);
/* Get the app version */
const char *openconnect_get_gp_app_version(struct openconnect_info *vpninfo);
+/* Get the OS version string for GP */
+const char *openconnect_get_gp_os_version(struct openconnect_info *vpninfo);
+
/* version.c */
extern const char openconnect_version_str[];
diff --git a/openconnect.h b/openconnect.h
index 7d4f3399..aa96a53b 100644
--- a/openconnect.h
+++ b/openconnect.h
@@ -472,6 +472,9 @@ int openconnect_set_useragent(struct openconnect_info *vpninfo,
int openconnect_set_gp_app_version(struct openconnect_info *vpninfo,
const char *gp_app_version);
+int openconnect_set_gp_os_version(struct openconnect_info *vpninfo,
+ const char *gp_os_version);
+
int openconnect_passphrase_from_fsid(struct openconnect_info *vpninfo);
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
int openconnect_init_ssl(void);
--
2.50.1 (Apple Git-155)
@@ -1,39 +0,0 @@
From 3915a51c81831a1a9b087d82f0c760365682f23b Mon Sep 17 00:00:00 2001
From: Kevin Yue <[email protected]>
Date: Mon, 15 Dec 2025 19:20:44 +0800
Subject: [PATCH 4/4] Add client version and OS information to HIP script
arguments
---
gpst.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/gpst.c b/gpst.c
index 0373fce0..d04c42c2 100644
--- a/gpst.c
+++ b/gpst.c
@@ -1013,6 +1013,12 @@ static int run_hip_script(struct openconnect_info *vpninfo)
exit(1);
hip_argv[i++] = openconnect_utf8_to_legacy(vpninfo, vpninfo->csd_wrapper);
+ hip_argv[i++] = "--client-version";
+ hip_argv[i++] = openconnect_get_gp_app_version(vpninfo);
+ hip_argv[i++] = "--client-os";
+ hip_argv[i++] = gpst_os_name(vpninfo);
+ hip_argv[i++] = "--os-version";
+ hip_argv[i++] = openconnect_get_gp_os_version(vpninfo);
hip_argv[i++] = "--cookie";
hip_argv[i++] = vpninfo->cookie;
if (vpninfo->ip_info.addr) {
@@ -1025,8 +1031,6 @@ static int run_hip_script(struct openconnect_info *vpninfo)
}
hip_argv[i++] = "--md5";
hip_argv[i++] = vpninfo->csd_token;
- hip_argv[i++] = "--client-os";
- hip_argv[i++] = gpst_os_name(vpninfo);
hip_argv[i++] = NULL;
/* XX: Sending the above parameters as --long-options was a mistake that was
--
2.50.1 (Apple Git-155)
@@ -1,124 +0,0 @@
diff --git a/gpst.c b/gpst.c
index 244aaf04..78c16d1c 100644
--- a/gpst.c
+++ b/gpst.c
@@ -438,8 +438,19 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
new_ip_info.netmask = add_option_steal(&new_opts, "netmask", &s);
} else if (!xmlnode_get_val(xml_node, "mtu", &s))
new_ip_info.mtu = atoi(s);
- else if (!xmlnode_get_val(xml_node, "lifetime", &s))
+ else if (!xmlnode_get_val(xml_node, "lifetime", &s)) {
+ vpninfo->gp_session_lifetime = atoi(s);
vpninfo->auth_expiration = time(NULL) + atol(s);
+ } else if (!xmlnode_get_val(xml_node, "user-expires", &s) ||
+ !xmlnode_get_val(xml_node, "user_expires", &s)) {
+ vpninfo->gp_user_expires = atol(s);
+ } else if (!xmlnode_get_val(xml_node, "lifetime-notify-prior", &s)) {
+ vpninfo->gp_lifetime_notify_prior = atoi(s);
+ } else if (!xmlnode_get_val(xml_node, "lifetime-notify-message", &s)) {
+ free(vpninfo->gp_lifetime_notify_message);
+ vpninfo->gp_lifetime_notify_message = s;
+ s = NULL;
+ }
else if (!xmlnode_get_val(xml_node, "quarantine", &s)) {
if (strcmp(s, "no"))
vpn_progress(vpninfo, PRG_DEBUG,
diff --git a/libopenconnect.map.in b/libopenconnect.map.in
index f036c071..44110486 100644
--- a/libopenconnect.map.in
+++ b/libopenconnect.map.in
@@ -113,6 +113,10 @@ OPENCONNECT_5_7 {
openconnect_set_cookie;
openconnect_set_allow_insecure_crypto;
openconnect_get_auth_expiration;
+ openconnect_get_gp_session_lifetime;
+ openconnect_get_gp_user_expires;
+ openconnect_get_gp_lifetime_notify_prior;
+ openconnect_get_gp_lifetime_notify_message;
openconnect_disable_dtls;
openconnect_get_connect_url;
openconnect_set_webview_callback;
diff --git a/libopenconnect5.symbols b/libopenconnect5.symbols
index 7cb04d05..2c7af781 100644
--- a/libopenconnect5.symbols
+++ b/libopenconnect5.symbols
@@ -94,6 +94,10 @@ libopenconnect.so.5 libopenconnect5 #MINVER#
openconnect_set_cookie@OPENCONNECT_5_7 8.20
openconnect_set_allow_insecure_crypto@OPENCONNECT_5_7 8.20
openconnect_get_auth_expiration@OPENCONNECT_5_7 8.20
+ openconnect_get_gp_session_lifetime@OPENCONNECT_5_7 8.20
+ openconnect_get_gp_user_expires@OPENCONNECT_5_7 8.20
+ openconnect_get_gp_lifetime_notify_prior@OPENCONNECT_5_7 8.20
+ openconnect_get_gp_lifetime_notify_message@OPENCONNECT_5_7 8.20
openconnect_disable_dtls@OPENCONNECT_5_7 8.20
openconnect_get_connect_url@OPENCONNECT_5_7 8.20
openconnect_set_webview_callback@OPENCONNECT_5_7 8.20
diff --git a/library.c b/library.c
index b5e74e9b..03f47004 100644
--- a/library.c
+++ b/library.c
@@ -838,6 +838,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
free(vpninfo->dtls_cipher);
free(vpninfo->peer_cert_hash);
free(vpninfo->ciphersuite_config);
+ free(vpninfo->gp_lifetime_notify_message);
#if defined(OPENCONNECT_OPENSSL)
free(vpninfo->cstp_cipher);
#if defined(HAVE_BIO_METH_FREE)
@@ -1137,6 +1138,26 @@ time_t openconnect_get_auth_expiration(struct openconnect_info *vpninfo)
return vpninfo->auth_expiration;
}
+int openconnect_get_gp_session_lifetime(struct openconnect_info *vpninfo)
+{
+ return vpninfo->gp_session_lifetime;
+}
+
+time_t openconnect_get_gp_user_expires(struct openconnect_info *vpninfo)
+{
+ return vpninfo->gp_user_expires;
+}
+
+int openconnect_get_gp_lifetime_notify_prior(struct openconnect_info *vpninfo)
+{
+ return vpninfo->gp_lifetime_notify_prior;
+}
+
+const char *openconnect_get_gp_lifetime_notify_message(struct openconnect_info *vpninfo)
+{
+ return vpninfo->gp_lifetime_notify_message;
+}
+
int openconnect_get_ip_info(struct openconnect_info *vpninfo,
const struct oc_ip_info **info,
const struct oc_vpn_option **cstp_options,
diff --git a/openconnect-internal.h b/openconnect-internal.h
index abf45bbd..dd5507ca 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -647,6 +647,10 @@ struct openconnect_info {
int dtls_attempt_period;
int udp_probes_sent;
time_t auth_expiration;
+ int gp_session_lifetime;
+ time_t gp_user_expires;
+ int gp_lifetime_notify_prior;
+ char *gp_lifetime_notify_message;
time_t new_dtls_started;
#if defined(OPENCONNECT_OPENSSL)
SSL_CTX *dtls_ctx;
diff --git a/openconnect.h b/openconnect.h
index 136f181a..febf15cc 100644
--- a/openconnect.h
+++ b/openconnect.h
@@ -655,6 +655,10 @@ void openconnect_set_dpd(struct openconnect_info *, int min_seconds);
void openconnect_set_trojan_interval(struct openconnect_info *, int seconds);
int openconnect_get_idle_timeout(struct openconnect_info *);
time_t openconnect_get_auth_expiration(struct openconnect_info *);
+int openconnect_get_gp_session_lifetime(struct openconnect_info *);
+time_t openconnect_get_gp_user_expires(struct openconnect_info *);
+int openconnect_get_gp_lifetime_notify_prior(struct openconnect_info *);
+const char *openconnect_get_gp_lifetime_notify_message(struct openconnect_info *);
/* The returned structures are owned by the library and may be freed/replaced
due to rekey or reconnect. Assume that once the mainloop starts, the
@@ -1,101 +0,0 @@
From 78078b21f53801b31fef352ec0de40d319edcae9 Mon Sep 17 00:00:00 2001
From: Kevin Yue <[email protected]>
Date: Sat, 13 Jun 2026 12:00:00 +0800
Subject: [PATCH 6/6] Add host ID to GlobalProtect HIP script arguments
---
gpst.c | 4 ++++
library.c | 15 +++++++++++++++
openconnect-internal.h | 4 ++++
openconnect.h | 3 +++
4 files changed, 26 insertions(+)
diff --git a/gpst.c b/gpst.c
index 78c16d1c..f1e1f6bb 100644
--- a/gpst.c
+++ b/gpst.c
@@ -1019,6 +1019,10 @@ static int run_hip_script(struct openconnect_info *vpninfo)
hip_argv[i++] = "--client-os";
hip_argv[i++] = gpst_os_name(vpninfo);
hip_argv[i++] = "--os-version";
hip_argv[i++] = openconnect_get_gp_os_version(vpninfo);
+ if (openconnect_get_gp_host_id(vpninfo)) {
+ hip_argv[i++] = "--host-id";
+ hip_argv[i++] = openconnect_get_gp_host_id(vpninfo);
+ }
hip_argv[i++] = "--cookie";
hip_argv[i++] = vpninfo->cookie;
if (vpninfo->ip_info.addr) {
diff --git a/library.c b/library.c
index 03f47004..9e585119 100644
--- a/library.c
+++ b/library.c
@@ -900,6 +900,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
free(vpninfo->useragent);
free(vpninfo->gp_app_version);
free(vpninfo->gp_os_version);
+ free(vpninfo->gp_host_id);
free(vpninfo->authgroup);
#ifdef HAVE_LIBSTOKEN
if (vpninfo->stoken_pin)
@@ -1049,6 +1050,20 @@ const char *openconnect_get_gp_os_version(struct openconnect_info *vpninfo)
return vpninfo->gp_os_version ?: vpninfo->platname;
}
+int openconnect_set_gp_host_id(struct openconnect_info *vpninfo,
+ const char *gp_host_id)
+{
+ UTF8CHECK(gp_host_id);
+
+ STRDUP(vpninfo->gp_host_id, gp_host_id);
+ return 0;
+}
+
+const char *openconnect_get_gp_host_id(struct openconnect_info *vpninfo)
+{
+ return vpninfo->gp_host_id;
+}
+
int openconnect_set_urlpath(struct openconnect_info *vpninfo,
const char *urlpath)
{
diff --git a/openconnect-internal.h b/openconnect-internal.h
index a7e80659..76034fbd 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -788,6 +788,7 @@ struct openconnect_info {
char *version_string;
char *gp_app_version;
char *gp_os_version;
+ char *gp_host_id;
const char *quit_reason;
const char *delay_tunnel_reason; /* If non-null, provides a reason why protocol is not yet ready for tunnel setup */
@@ -1684,6 +1685,9 @@ const char *openconnect_get_gp_app_version(struct openconnect_info *vpninfo);
/* Get the OS version string for GP */
const char *openconnect_get_gp_os_version(struct openconnect_info *vpninfo);
+/* Get the host ID string for GP */
+const char *openconnect_get_gp_host_id(struct openconnect_info *vpninfo);
+
/* version.c */
extern const char openconnect_version_str[];
diff --git a/openconnect.h b/openconnect.h
index 40de2811..3c65c090 100644
--- a/openconnect.h
+++ b/openconnect.h
@@ -472,8 +472,11 @@ int openconnect_set_useragent(struct openconnect_info *vpninfo,
int openconnect_set_gp_app_version(struct openconnect_info *vpninfo,
const char *gp_app_version);
int openconnect_set_gp_os_version(struct openconnect_info *vpninfo,
const char *gp_os_version);
+int openconnect_set_gp_host_id(struct openconnect_info *vpninfo,
+ const char *gp_host_id);
+
int openconnect_passphrase_from_fsid(struct openconnect_info *vpninfo);
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
int openconnect_init_ssl(void);
--
2.50.1 (Apple Git-155)
@@ -1,15 +0,0 @@
diff --git a/gpst.c b/gpst.c
index 244aaf04..fb8d945d 100644
--- a/gpst.c
+++ b/gpst.c
@@ -669,6 +669,10 @@ static int gpst_get_config(struct openconnect_info *vpninfo)
result = do_https_request(vpninfo, "POST", "application/x-www-form-urlencoded", request_body, &xml_buf, NULL, HTTP_NO_FLAGS);
free(vpninfo->urlpath);
vpninfo->urlpath = orig_path;
+ if (result >= 0 && xml_buf)
+ vpn_progress(vpninfo, PRG_DEBUG,
+ "GlobalProtect getconfig.esp response:\n%s\n",
+ xml_buf);
/* parse getconfig result */
if (result >= 0)
+2
View File
@@ -47,6 +47,8 @@ pub(crate) struct VpnSessionInfoRaw {
pub user_expires: c_long,
pub lifetime_warning_prior: c_int,
pub lifetime_warning_message: *const c_char,
pub nlb_enabled: c_int,
pub nlb_connected_gw_ip: *const c_char,
}
#[link(name = "vpn")]
+3
View File
@@ -59,6 +59,9 @@ static void setup_tun_handler(void *_vpninfo)
openconnect_get_gp_lifetime_notify_prior(_vpninfo),
.lifetime_warning_message =
openconnect_get_gp_lifetime_notify_message(_vpninfo),
.nlb_enabled = openconnect_get_gp_nlb_enabled(_vpninfo),
.nlb_connected_gw_ip =
openconnect_get_gp_nlb_connected_gw_ip(_vpninfo),
};
on_vpn_connected(g_cmd_pipe_fd, &session_info, g_user_data);
}
+2
View File
@@ -9,6 +9,8 @@ typedef struct vpn_session_info {
long user_expires;
int lifetime_warning_prior;
const char *lifetime_warning_message;
int nlb_enabled;
const char *nlb_connected_gw_ip;
} vpn_session_info;
typedef void (*vpn_connected_callback)(int cmd_pipe_fd,
+11
View File
@@ -16,6 +16,8 @@ pub struct VpnSessionInfo {
pub lifetime_secs: Option<u32>,
pub user_expires: Option<u32>,
pub lifetime_warning: Option<VpnSessionWarning>,
pub nlb_enabled: bool,
pub nlb_connected_gw_ip: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -41,6 +43,8 @@ pub(crate) fn session_info_from_raw(raw: *const ffi::VpnSessionInfoRaw) -> VpnSe
(Some(prior_secs), Some(message)) => Some(VpnSessionWarning { prior_secs, message }),
_ => None,
},
nlb_enabled: raw.nlb_enabled != 0,
nlb_connected_gw_ip: unsafe { optional_c_string(raw.nlb_connected_gw_ip) },
}
}
@@ -426,12 +430,15 @@ mod tests {
#[test]
fn maps_session_info_from_callback_payload() {
let message = CString::new("Session expires soon").unwrap();
let connected_gw = CString::new("10.1.2.3").unwrap();
let raw = ffi::VpnSessionInfoRaw {
auth_expiration: 0,
lifetime_secs: 43_200,
user_expires: 1_776_828_409,
lifetime_warning_prior: 1_800,
lifetime_warning_message: message.as_ptr(),
nlb_enabled: 1,
nlb_connected_gw_ip: connected_gw.as_ptr(),
};
let info = session_info_from_raw(&raw);
@@ -445,6 +452,8 @@ mod tests {
message: "Session expires soon".to_string(),
})
);
assert!(info.nlb_enabled);
assert_eq!(info.nlb_connected_gw_ip.as_deref(), Some("10.1.2.3"));
}
#[test]
@@ -455,6 +464,8 @@ mod tests {
user_expires: 0,
lifetime_warning_prior: 0,
lifetime_warning_message: std::ptr::null(),
nlb_enabled: 0,
nlb_connected_gw_ip: std::ptr::null(),
};
let info = session_info_from_raw(&raw);