From fbe7b1d7fa0d9d0a34e9740e2ac094d7f088ca90 Mon Sep 17 00:00:00 2001 From: Ambroise Rosset Date: Sun, 1 May 2022 21:17:07 +0200 Subject: [PATCH] Add the possibility to tune the VPN useragent Add the hability to tune the VPN useragent with the new function openconnect_set_useragent added in opeconnect v9.0 (libopenconnect 5.8) --- auth-dialog/main.c | 4 ++++ properties/nm-openconnect-editor-plugin.c | 12 ++++++++++++ properties/nm-openconnect-editor.c | 5 +++++ shared/nm-service-defines.h | 1 + 4 files changed, 22 insertions(+) diff --git a/auth-dialog/main.c b/auth-dialog/main.c index bca5956ce..5f42fdfa8 100644 --- a/auth-dialog/main.c +++ b/auth-dialog/main.c @@ -1255,6 +1255,10 @@ static int get_config (auth_ui_data *ui_data, if (!g_strcmp0(protocol, "pulse")) ui_data->connect_urlpath = TRUE; + useragent = g_hash_table_lookup (options, NM_OPENCONNECT_KEY_USERAGENT); + if (useragent) + openconnect_set_useragent(vpninfo, OC3DUP(useragent)); + cafile = g_hash_table_lookup (options, NM_OPENCONNECT_KEY_CACERT); if (cafile) openconnect_set_cafile(vpninfo, OC3DUP (cafile)); diff --git a/properties/nm-openconnect-editor-plugin.c b/properties/nm-openconnect-editor-plugin.c index 90dd5af55..1da4152bc 100644 --- a/properties/nm-openconnect-editor-plugin.c +++ b/properties/nm-openconnect-editor-plugin.c @@ -229,6 +229,11 @@ import (NMVpnEditorPlugin *iface, const char *path, GError **error) if (buf) nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PROXY, buf); + /* UserAgent */ + buf = g_key_file_get_string (keyfile, "openconnect", "UserAgent", NULL); + if (buf) + nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_USERAGENT, buf); + /* Cisco Secure Desktop */ bval = g_key_file_get_boolean (keyfile, "openconnect", "CSDEnable", NULL); if (bval) @@ -290,6 +295,7 @@ export (NMVpnEditorPlugin *iface, const char *cacert = NULL; const char *protocol = NULL; const char *proxy = NULL; + const char *useragent = NULL; gboolean csd_enable = FALSE; const char *csd_wrapper = NULL; const char *reported_os = NULL; @@ -338,6 +344,10 @@ export (NMVpnEditorPlugin *iface, if (value && strlen (value)) proxy = value; + value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_USERAGENT); + if (value && strlen (value)) + useragent = value; + value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_CSD_ENABLE); if (value && !strcmp (value, "yes")) csd_enable = TRUE; @@ -387,6 +397,7 @@ export (NMVpnEditorPlugin *iface, "Protocol=%s\n" "Proxy=%s\n" "CSDEnable=%s\n" + "UserAgent=%s\n" "CSDWrapper=%s\n" "ReportedOS=%s\n" "UserCertificate=%s\n" @@ -401,6 +412,7 @@ export (NMVpnEditorPlugin *iface, /* Protocol */ protocol ? protocol : "anyconnect", /* Proxy */ proxy ? proxy : "", /* Cisco Secure Desktop */ csd_enable ? "1" : "0", + /* UserAgent */ useragent ? useragent : "", /* CSD Wrapper Script */ csd_wrapper ? csd_wrapper : "", /* Reported OS */ reported_os ? reported_os : "", /* User Certificate */ usercert ? usercert : "", diff --git a/properties/nm-openconnect-editor.c b/properties/nm-openconnect-editor.c index de0c27a1b..22055c0c1 100644 --- a/properties/nm-openconnect-editor.c +++ b/properties/nm-openconnect-editor.c @@ -460,6 +460,11 @@ update_connection (NMVpnEditor *iface, if (str && strlen (str)) nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PROXY, str); + widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_agent_entry")); + str = (char *) gtk_editable_get_text (GTK_EDITABLE (widget)); + if (str && strlen (str)) + nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_USERAGENT, str); + widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "fsid_button")); str = gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))?"yes":"no"; nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PEM_PASSPHRASE_FSID, str); diff --git a/shared/nm-service-defines.h b/shared/nm-service-defines.h index 4e7d48132..21e1ce4f5 100644 --- a/shared/nm-service-defines.h +++ b/shared/nm-service-defines.h @@ -46,6 +46,7 @@ #define NM_OPENCONNECT_KEY_PROTOCOL "protocol" #define NM_OPENCONNECT_KEY_PROXY "proxy" #define NM_OPENCONNECT_KEY_CSD_ENABLE "enable_csd_trojan" +#define NM_OPENCONNECT_KEY_USERAGENT "useragent" #define NM_OPENCONNECT_KEY_CSD_WRAPPER "csd_wrapper" #define NM_OPENCONNECT_KEY_TOKEN_MODE "stoken_source" #define NM_OPENCONNECT_KEY_TOKEN_SECRET "stoken_string"