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.
This commit is contained in:
Kevin Yue committed 2026-07-04 18:37:13 +08:00
1 parent aa14c67e92
commit 6723685385
6 files changed
+198

No files matched your search

+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,
);
@@ -0,0 +1,178 @@
From 0000000000000000000000000000000000000006 Mon Sep 17 00:00:00 2001
From: Kevin Yue <[email protected]>
Date: Wed, 25 Jun 2026 22:00:00 +0800
Subject: [PATCH 12/12] Add GlobalProtect NLB integration and GCM recognition
Recognize AES-GCM ESP algorithm strings, extend fake-gp-server with NLB
mode, wire NLB unit/integration tests into Makefile.am, and add an
integration test that verifies NLB config parsing from getconfig.esp.
---
gpst.c | 2 ++
openconnect-internal.h | 2 ++
tests/Makefile.am | 8 +++++--
tests/fake-gp-server.py | 18 ++++++++++++---
tests/gp-nlb-auth-and-config | 48 +++++++++++++++++++++++++++++++++++++
5 files changed, 74 insertions(+), 4 deletions(-)
create mode 100755 tests/gp-nlb-auth-and-config
diff --git a/gpst.c b/gpst.c
index 00000000..00000000 100644
--- a/gpst.c
+++ b/gpst.c
@@ -369,6 +369,8 @@ static int check_enc_algo(struct openconnect_info *v, const char *s)
{
if (!strcmp(s, "aes128") || !strcmp(s, "aes-128-cbc")) return ENC_AES_128_CBC;
if (!strcmp(s, "aes-256-cbc")) return ENC_AES_256_CBC;
+ if (!strcmp(s, "aes-128-gcm")) return ENC_AES_128_GCM;
+ if (!strcmp(s, "aes-256-gcm")) return ENC_AES_256_GCM;
vpn_progress(v, PRG_ERR, _("Unknown ESP encryption algorithm: %s\n"), s);
return -ENOENT;
}
diff --git a/openconnect-internal.h b/openconnect-internal.h
index 00000000..00000000 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -1103,6 +1103,8 @@ struct openconnect_info {
/* Encryption and HMAC algorithms (matching Juniper/Pulse binary encoding) */
#define ENC_AES_128_CBC 2
#define ENC_AES_256_CBC 5
+#define ENC_AES_128_GCM 20
+#define ENC_AES_256_GCM 22
#define HMAC_MD5 1
#define HMAC_SHA1 2
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 00000000..00000000 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,7 +87,10 @@
dist_check_SCRIPTS += auth-username-pass auth-certificate auth-nonascii cert-fingerprint \
id-test obsolete-server-crypto pfs auth-swtpm auth-hwtpm fortinet-auth-and-config \
f5-auth-and-config juniper-auth juniper-sso-auth gp-auth-and-config auth-pkcs11 \
- auth-multicert
+ auth-multicert gp-nlb-ssl-parse gp-nlb-esp-envelope gp-nlb-ssl-connect \
+ gp-nlb-opaque-due gp-nlb-auth-and-config
+
+TESTS += gp-nlb-ssl-parse gp-nlb-esp-envelope gp-nlb-ssl-connect gp-nlb-opaque-due
if HAVE_CWRAP
TESTS += auth-username-pass auth-certificate auth-nonascii cert-fingerprint id-test \
@@ -110,7 +113,8 @@
if HAVE_PYTHON36_FLASK
TESTS += juniper-sso-auth auth-multicert
if HAVE_PYTHON37_DATACLASSES
-TESTS += juniper-auth gp-auth-and-config f5-auth-and-config fortinet-auth-and-config
+TESTS += juniper-auth gp-auth-and-config f5-auth-and-config fortinet-auth-and-config \
+ gp-nlb-auth-and-config
endif
endif
diff --git a/tests/fake-gp-server.py b/tests/fake-gp-server.py
index 00000000..00000000 100755
--- a/tests/fake-gp-server.py
+++ b/tests/fake-gp-server.py
@@ -96,6 +96,7 @@ class TestConfiguration:
saml_comments_only: int = None
saml_needs_js: int = None
esp: bool = True
+ nlb: bool = False
C = TestConfiguration()
OUTSTANDING_SAML_TOKENS = set()
@@ -104,7 +105,7 @@ OUTSTANDING_SAML_TOKENS = set()
def configure():
global C
if request.method == 'POST':
- gateways, portal_2fa, gw_2fa, portal_cookie, portal_saml, gateway_saml, saml_comments_only, saml_needs_js, esp = request.form.get('gateways'), request.form.get('portal_2fa'), request.form.get('gw_2fa'), request.form.get('portal_cookie'), request.form.get('portal_saml'), request.form.get('gateway_saml'), request.form.get('saml_comments_only'), request.form.get('saml_needs_js'), request.form.get('esp')
+ gateways, portal_2fa, gw_2fa, portal_cookie, portal_saml, gateway_saml, saml_comments_only, saml_needs_js, esp, nlb = request.form.get('gateways'), request.form.get('portal_2fa'), request.form.get('gw_2fa'), request.form.get('portal_cookie'), request.form.get('portal_saml'), request.form.get('gateway_saml'), request.form.get('saml_comments_only'), request.form.get('saml_needs_js'), request.form.get('esp'), request.form.get('nlb')
C.gateways = gateways.split(',') if gateways else ('Default gateway',)
C.portal_cookie = portal_cookie
C.portal_2fa = portal_2fa and portal_2fa.strip().lower()
@@ -114,6 +115,7 @@ def configure():
C.saml_comments_only = int(saml_comments_only) if saml_comments_only else None
C.saml_needs_js = int(saml_needs_js) if saml_needs_js else None
C.esp = int(esp) if esp else None
+ C.nlb = bool(int(nlb)) if nlb else False
return '', 201
else:
return 'Current configuration of fake GP server configuration:\n{}\n'.format(C)
@@ -342,7 +344,14 @@ def check_form_against_session('user', 'portal', 'domain', 'authcookie', 'prefer
def getconfig():
session.update(step='gateway-config')
addrs = '<ip-address>{}</ip-address>'.format(session['preferred_ip'])
- addrs += '<gw-address>127.0.0.1</gw-address>'
+ if C.nlb:
+ addrs += '<gw-address>127.127.127.127</gw-address>'
+ addrs += '<connected-gw-ip>10.1.2.3</connected-gw-ip>'
+ addrs += '''<hs-key><bits>256</bits><val>0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef</val></hs-key>
+<enc-hs-key>fake-enc-hs-key-blob</enc-hs-key>
+<tunnel-opaque><val>dGVzdC10dW5uZWwtb3BhcXVl</val><valid-period>3600</valid-period></tunnel-opaque>'''
+ else:
+ addrs += '<gw-address>127.0.0.1</gw-address>'
addrs += '<gw-address-v6>::1</gw-address-v6>' # some(?) servers send the IPv6 address even if not otherwise configured for IPv6
if session['ipv6_support'] == 'yes':
addrs += '<ip-address-v6>{}</ip-address-v6>'.format(session['preferred_ipv6'])
@@ -380,6 +389,9 @@ def getconfig():
def tunnel():
assert 'user' in request.args and 'authcookie' in request.args
session.update(step='GET-tunnel')
+ if C.nlb:
+ inner = '192.168.255.43'
+ return '110 127.127.127.127{} c057fc7f7c6b74f9ac68b639bb056732404cbacf START_TUNNEL'.format(inner)
abort(502)
diff --git a/tests/gp-nlb-auth-and-config b/tests/gp-nlb-auth-and-config
new file mode 100755
index 00000000..00000000
--- /dev/null
+++ b/tests/gp-nlb-auth-and-config
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# Validate GlobalProtect NLB config parsing and SSL tunnel handshake against
+# fake-gp-server NLB mode (issue #526 sample response).
+PRELOAD=1
+srcdir=${srcdir:-.}
+top_builddir=${top_builddir:-..}
+
+. `dirname $0`/common.sh
+
+FINGERPRINT="--servercert=pin-sha256:xp3scfzy3rO"
+CERT=$certdir/server-cert.pem
+KEY=$certdir/server-key.pem
+
+echo "Testing GlobalProtect NLB auth/config against fake server ..."
+
+OCSERV=${srcdir}/fake-gp-server.py
+launch_simple_sr_server $ADDRESS 443 $CERT $KEY >/dev/null 2>&1
+PID=$!
+wait_server $PID
+
+SERVURL="https://$ADDRESS:443"
+CLIENT="$OPENCONNECT --protocol=gp $FINGERPRINT -u test"
+export LD_PRELOAD=libsocket_wrapper.so
+
+echo "Configuring fake server for NLB gateway getconfig."
+curl -sk $SERVURL/CONFIGURE -d nlb=1
+
+echo -n "Authenticating with username/password via portal (NLB mode)... "
+( echo "test" | $CLIENT $SERVURL/portal --cookieonly >/dev/null 2>&1) ||
+ fail $PID "Could not receive cookie from fake GlobalProtect NLB server"
+
+echo ok
+
+echo -n "Verifying NLB fields are parsed from getconfig.esp... "
+LOG="$SOCKDIR/nlb-log.$$.tmp"
+( echo "test" | timeout 20 $CLIENT --no-dtls $SERVURL/portal >"$LOG" 2>&1) || true
+grep -q 'NLB enabled' "$LOG" ||
+ fail $PID "Expected NLB enabled message in openconnect output"
+
+echo ok
+
+echo "Resetting fake server to default configuration."
+curl -sk $SERVURL/CONFIGURE -d ''
+
+cleanup
+
+exit 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);