From 0000000000000000000000000000000000000006 Mon Sep 17 00:00:00 2001 From: Kevin Yue 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 = '{}'.format(session['preferred_ip']) - addrs += '127.0.0.1' + if C.nlb: + addrs += '127.127.127.127' + addrs += '10.1.2.3' + addrs += '''2560123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef +fake-enc-hs-key-blob +dGVzdC10dW5uZWwtb3BhcXVl3600''' + else: + addrs += '127.0.0.1' addrs += '::1' # some(?) servers send the IPv6 address even if not otherwise configured for IPv6 if session['ipv6_support'] == 'yes': addrs += '{}'.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