mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 14:06:14 -05:00
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.
This commit is contained in:
1 file changed
+238
@@ -0,0 +1,238 @@
|
||||
From 0000000000000000000000000000000000000001 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Yue <[email protected]>
|
||||
Date: Wed, 25 Jun 2026 18:00:00 +0800
|
||||
Subject: [PATCH 7/7] Support GlobalProtect NLB config
|
||||
|
||||
Parse NLB fields from getconfig.esp XML, store them in vpninfo, and
|
||||
align the getconfig request with the official GlobalProtect client.
|
||||
---
|
||||
gpst.c | 58 ++++++++++++++++++++++++++++++++++++++--
|
||||
libopenconnect.map.in | 2 ++
|
||||
libopenconnect5.symbols | 2 ++
|
||||
library.c | 16 +++++++++++
|
||||
openconnect-internal.h | 15 ++++++++++
|
||||
openconnect.h | 2 ++
|
||||
6 files changed, 93 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/gpst.c b/gpst.c
|
||||
index f1e1f6bb..a8b3c4d5 100644
|
||||
--- a/gpst.c
|
||||
+++ b/gpst.c
|
||||
@@ -477,6 +477,10 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
|
||||
* gateway is meaningless." See esp_send_probes_gp for the
|
||||
* gory details of what this field actually means.
|
||||
*/
|
||||
+ if (!strcmp(s, "127.127.127.127")) {
|
||||
+ free(vpninfo->gp_nlb.tunnel_vip);
|
||||
+ vpninfo->gp_nlb.tunnel_vip = strdup(s);
|
||||
+ }
|
||||
if (vpninfo->peer_addr->sa_family == IPPROTO_IP &&
|
||||
vpninfo->ip_info.gateway_addr && strcmp(s, vpninfo->ip_info.gateway_addr))
|
||||
vpn_progress(vpninfo, PRG_DEBUG,
|
||||
@@ -495,12 +499,17 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
|
||||
inet_pton(AF_INET6, s, &esp_magic_v6);
|
||||
#endif /* HAVE_ESP */
|
||||
} else if (!xmlnode_get_val(xml_node, "connected-gw-ip", &s)) {
|
||||
- if (vpninfo->ip_info.gateway_addr && strcmp(s, vpninfo->ip_info.gateway_addr))
|
||||
+ free(vpninfo->gp_nlb.connected_gw_ip);
|
||||
+ vpninfo->gp_nlb.connected_gw_ip = s;
|
||||
+ s = NULL;
|
||||
+ if (vpninfo->ip_info.gateway_addr &&
|
||||
+ strcmp(vpninfo->gp_nlb.connected_gw_ip, vpninfo->ip_info.gateway_addr))
|
||||
vpn_progress(vpninfo, PRG_DEBUG, _("Config XML <connected-gw-ip> address (%s) differs from external\n"
|
||||
"gateway address (%s). Please report this to\n"
|
||||
"<%s>, including any problems\n"
|
||||
"with ESP or other apparent loss of connectivity or performance.\n"),
|
||||
- s, vpninfo->ip_info.gateway_addr, "[email protected]");
|
||||
+ vpninfo->gp_nlb.connected_gw_ip, vpninfo->ip_info.gateway_addr,
|
||||
+ "[email protected]");
|
||||
} else if (xmlnode_is_named(xml_node, "dns-v6") ||
|
||||
xmlnode_is_named(xml_node, "dns")) {
|
||||
for (member = xml_node->children; member && n_dns<3; member=member->next) {
|
||||
@@ -575,6 +584,36 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
|
||||
#else
|
||||
vpn_progress(vpninfo, PRG_DEBUG, _("Ignoring ESP keys since ESP support not available in this build\n"));
|
||||
#endif
|
||||
+ } else if (xmlnode_is_named(xml_node, "hs-key")) {
|
||||
+#ifdef HAVE_ESP
|
||||
+ int keylen = xml_to_key(xml_node, vpninfo->gp_nlb.hs_key, sizeof(vpninfo->gp_nlb.hs_key));
|
||||
+ if (keylen > 0) {
|
||||
+ vpninfo->gp_nlb.hs_key_len = keylen;
|
||||
+ vpninfo->gp_nlb.hs_key_bits = keylen * 8;
|
||||
+ vpninfo->gp_nlb.enabled = 1;
|
||||
+ }
|
||||
+#endif /* HAVE_ESP */
|
||||
+ } else if (!xmlnode_get_val(xml_node, "enc-hs-key", &s)) {
|
||||
+ free(vpninfo->gp_nlb.enc_hs_key);
|
||||
+ vpninfo->gp_nlb.enc_hs_key = s;
|
||||
+ s = NULL;
|
||||
+ vpninfo->gp_nlb.enabled = 1;
|
||||
+ } else if (xmlnode_is_named(xml_node, "tunnel-opaque")) {
|
||||
+ if (!xmlnode_get_val(xml_node, "val", &s)) {
|
||||
+ free(vpninfo->gp_nlb.tunnel_opaque);
|
||||
+ vpninfo->gp_nlb.tunnel_opaque = s;
|
||||
+ s = NULL;
|
||||
+ vpninfo->gp_nlb.enabled = 1;
|
||||
+ }
|
||||
+ if (!xmlnode_get_val(xml_node, "valid-period", &s)) {
|
||||
+ vpninfo->gp_nlb.opaque_valid_until = time(NULL) + atol(s);
|
||||
+ }
|
||||
+ } else if (!xmlnode_get_val(xml_node, "valid-period", &s)) {
|
||||
+ vpninfo->gp_nlb.opaque_valid_until = time(NULL) + atol(s);
|
||||
+ } else if (!xmlnode_get_val(xml_node, "in-tunnel-gw-cert-chksum", &s)) {
|
||||
+ free(vpninfo->gp_nlb.in_tunnel_gw_cert_chksum);
|
||||
+ vpninfo->gp_nlb.in_tunnel_gw_cert_chksum = s;
|
||||
+ s = NULL;
|
||||
} else if (xmlnode_is_named(xml_node, "need-tunnel")
|
||||
|| xmlnode_is_named(xml_node, "bw-c2s")
|
||||
|| xmlnode_is_named(xml_node, "bw-s2c")
|
||||
@@ -585,7 +624,8 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
|
||||
|| xmlnode_is_named(xml_node, "ip-address-v6-preferred")
|
||||
|| xmlnode_is_named(xml_node, "ipv6-connection")
|
||||
|| xmlnode_is_named(xml_node, "portal")
|
||||
- || xmlnode_is_named(xml_node, "user")) {
|
||||
+ || xmlnode_is_named(xml_node, "user")
|
||||
+ || xmlnode_is_named(xml_node, "use-ssl-tunnel")) {
|
||||
/* XX: Do these have any potential value at all for routing configuration or diagnostics? */
|
||||
} else if (xml_node->type == XML_ELEMENT_NODE) {
|
||||
free(s);
|
||||
@@ -597,6 +637,15 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
|
||||
}
|
||||
}
|
||||
|
||||
+ if (vpninfo->gp_nlb.tunnel_opaque)
|
||||
+ vpninfo->gp_nlb.enabled = 1;
|
||||
+
|
||||
+ if (vpninfo->gp_nlb.enabled)
|
||||
+ vpn_progress(vpninfo, PRG_INFO, _("NLB enabled\n"));
|
||||
+ else
|
||||
+ vpn_progress(vpninfo, PRG_DEBUG,
|
||||
+ _("hs-key section is not specified. Non-nlb\n"));
|
||||
+
|
||||
/* Set 10-second DPD/keepalive (same as Windows client) unless
|
||||
* overridden with --force-dpd */
|
||||
if (!vpninfo->ssl_times.dpd)
|
||||
@@ -670,13 +719,17 @@ static int gpst_get_config(struct openconnect_info *vpninfo)
|
||||
append_opt(request_body, "clientos", gpst_os_name(vpninfo));
|
||||
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");
|
||||
+ append_opt(request_body, "enc-algo", "aes-256-gcm,aes-128-gcm,aes-128-cbc");
|
||||
+ append_opt(request_body, "clientgpversion", app_version);
|
||||
+ if (openconnect_get_gp_host_id(vpninfo))
|
||||
+ append_opt(request_body, "host-id", openconnect_get_gp_host_id(vpninfo));
|
||||
if (old_addr || old_addr6) {
|
||||
append_opt(request_body, "preferred-ip", old_addr);
|
||||
append_opt(request_body, "preferred-ipv6", old_addr6);
|
||||
filter_opts(request_body, vpninfo->cookie, "preferred-ip,preferred-ipv6", 0);
|
||||
} else
|
||||
buf_append(request_body, "&%s", vpninfo->cookie);
|
||||
+ filter_opts(request_body, vpninfo->cookie, "serialno,clientgpversion,host-id", 1);
|
||||
if ((result = buf_error(request_body)))
|
||||
goto out;
|
||||
|
||||
diff --git a/libopenconnect.map.in b/libopenconnect.map.in
|
||||
index 44110486..8c2f1a3b 100644
|
||||
--- a/libopenconnect.map.in
|
||||
+++ b/libopenconnect.map.in
|
||||
@@ -117,6 +117,8 @@ OPENCONNECT_5_7 {
|
||||
openconnect_get_gp_user_expires;
|
||||
openconnect_get_gp_lifetime_notify_prior;
|
||||
openconnect_get_gp_lifetime_notify_message;
|
||||
+ openconnect_get_gp_nlb_enabled;
|
||||
+ openconnect_get_gp_nlb_connected_gw_ip;
|
||||
openconnect_disable_dtls;
|
||||
openconnect_get_connect_url;
|
||||
openconnect_set_webview_callback;
|
||||
diff --git a/libopenconnect5.symbols b/libopenconnect5.symbols
|
||||
index 2c7af781..b4e8d9a2 100644
|
||||
--- a/libopenconnect5.symbols
|
||||
+++ b/libopenconnect5.symbols
|
||||
@@ -98,6 +98,8 @@ libopenconnect.so.5 libopenconnect5 #MINVER#
|
||||
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_get_gp_nlb_enabled@OPENCONNECT_5_7 8.20
|
||||
+ openconnect_get_gp_nlb_connected_gw_ip@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 9e585119..c3d4e5f6 100644
|
||||
--- a/library.c
|
||||
+++ b/library.c
|
||||
@@ -839,6 +839,12 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
|
||||
free(vpninfo->peer_cert_hash);
|
||||
free(vpninfo->ciphersuite_config);
|
||||
free(vpninfo->gp_lifetime_notify_message);
|
||||
+ free(vpninfo->gp_nlb.enc_hs_key);
|
||||
+ free(vpninfo->gp_nlb.tunnel_opaque);
|
||||
+ free(vpninfo->gp_nlb.inner_gw_ip);
|
||||
+ free(vpninfo->gp_nlb.tunnel_vip);
|
||||
+ free(vpninfo->gp_nlb.connected_gw_ip);
|
||||
+ free(vpninfo->gp_nlb.in_tunnel_gw_cert_chksum);
|
||||
#if defined(OPENCONNECT_OPENSSL)
|
||||
free(vpninfo->cstp_cipher);
|
||||
#if defined(HAVE_BIO_METH_FREE)
|
||||
@@ -1201,6 +1207,16 @@ const char *openconnect_get_gp_lifetime_notify_message(struct openconnect_info *v
|
||||
return vpninfo->gp_lifetime_notify_message;
|
||||
}
|
||||
|
||||
+int openconnect_get_gp_nlb_enabled(struct openconnect_info *vpninfo)
|
||||
+{
|
||||
+ return vpninfo->gp_nlb.enabled;
|
||||
+}
|
||||
+
|
||||
+const char *openconnect_get_gp_nlb_connected_gw_ip(struct openconnect_info *vpninfo)
|
||||
+{
|
||||
+ return vpninfo->gp_nlb.connected_gw_ip;
|
||||
+}
|
||||
+
|
||||
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 76034fbd..91a2b3c4 100644
|
||||
--- a/openconnect-internal.h
|
||||
+++ b/openconnect-internal.h
|
||||
@@ -391,6 +391,20 @@ struct oc_ip_info {
|
||||
|
||||
struct openconnect_info;
|
||||
|
||||
+struct gp_nlb_config {
|
||||
+ int enabled;
|
||||
+ unsigned char hs_key[32];
|
||||
+ int hs_key_bits;
|
||||
+ int hs_key_len;
|
||||
+ char *enc_hs_key;
|
||||
+ char *tunnel_opaque;
|
||||
+ time_t opaque_valid_until;
|
||||
+ char *inner_gw_ip;
|
||||
+ char *tunnel_vip;
|
||||
+ char *connected_gw_ip;
|
||||
+ char *in_tunnel_gw_cert_chksum;
|
||||
+};
|
||||
+
|
||||
struct cert_info {
|
||||
struct openconnect_info *vpninfo;
|
||||
char *cert;
|
||||
@@ -651,6 +665,7 @@ struct openconnect_info {
|
||||
time_t gp_user_expires;
|
||||
int gp_lifetime_notify_prior;
|
||||
char *gp_lifetime_notify_message;
|
||||
+ struct gp_nlb_config gp_nlb;
|
||||
time_t new_dtls_started;
|
||||
#if defined(OPENCONNECT_OPENSSL)
|
||||
SSL_CTX *dtls_ctx;
|
||||
diff --git a/openconnect.h b/openconnect.h
|
||||
index febf15cc..d7e8f9a0 100644
|
||||
--- a/openconnect.h
|
||||
+++ b/openconnect.h
|
||||
@@ -667,6 +667,8 @@ 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 *);
|
||||
+int openconnect_get_gp_nlb_enabled(struct openconnect_info *);
|
||||
+const char *openconnect_get_gp_nlb_connected_gw_ip(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
|
||||
Reference in new issue
Block a user