openconnect: Fix GlobalProtect authentication, reconnect and split routes
cover openconnect: Fix GlobalProtect authentication, reconnect and split routes
This series fixes the OpenConnect plugin with a Palo Alto GlobalProtect gateway (AuthType userpass, built-in authentication of connman-vpnd), the handling of openconnect's own reconnection after a suspend, and split routes pushed by the gateway.
1. The protocol was only given to the openconnect process started after
authentication: the built-in authentication always used AnyConnect, POSTed to /gateway and got 404 from a GlobalProtect gateway.
2. "attempt-reconnect" and "reconnect" from the vpnc-script were handled as a disconnect: the provider was torn down while openconnect was still running, leaving an orphaned process.
3. GlobalProtect names its password field "passwd": an empty password was sent...
4. ...and the rejected credentials were resubmitted in a tight loop (~50 times), which can lock an account.
5. Split routes without a gateway (CISCO_SPLIT_INC_*) were never signalled to connmand.
6. _MASKLEN was matched as _MASK, so IPv4 netmasks became "16", "32"...
7. The username was never offered again in the credentials request.
Tested on a phone running a ConnMan 1.40 based build (Sailfish OS) against a GlobalProtect gateway with MFA: login from the native UI, several reconnections after suspend, 25 split routes installed with the right netmasks. This series is the same change ported to current master; it builds without warnings here but was not run on master itself.
---
Stéphane COLIN (7):
openconnect: Set protocol before obtaining the cookie
openconnect: Do not treat reconnect reasons as disconnect
openconnect: Fill the GlobalProtect "passwd" form field
openconnect: Limit repeated credential forms
vpn-provider: Signal routes without gateway
openconnect: Do not take _MASKLEN for _MASK in split routes
openconnect: Offer the username again on the next login
vpn/plugins/openconnect.c | 53 ++++++++++++++++++++++++++++++++++++++++------- vpn/vpn-agent.c | 3 ++- vpn/vpn-provider.c | 7 ++++++- 3 files changed, 53 insertions(+), 10 deletions(-)
---
base-commit: 9e46e4a021cd8566b942d1a72b41b14a0a58f506
change-id: 20261113-openconnect-gp-fixes-7535c7c56fd6
Best regards,
Signature · 1 line
Stéphane COLIN <[email protected]>
PATCH 1/7 openconnect: Set protocol before obtaining the cookie
[openconnect] Set protocol before obtaining the cookie.
OpenConnect.Protocol was only passed to the openconnect process started after authentication. The built-in authentication done by connman-vpnd with openconnect_obtain_cookie() therefore always used the default AnyConnect protocol, even for GlobalProtect and Pulse/NC servers.
With a GlobalProtect gateway this sends an AnyConnect POST to the gateway, which answers 404, and the connection can never be established with the userpass authentication type.
Call openconnect_set_protocol() before obtaining the cookie, as the openconnect --protocol option does.
--- vpn/plugins/openconnect.c | 8 ++++++++ 1 file changed, 8 insertions(+)
vpn/plugins/openconnect.c +8 -0
@@ -1004,6 +1004,7 @@ static int authenticate(struct oc_private_data *data)const char *cert =NULL ;const char *key =NULL ;const char *urlpath; +const char *protocol;const char *vpnhost;DBG ("" );
@@ -1036,6 +1037,13 @@ static int authenticate(struct oc_private_data *data) oc_progress, data); +/* Same as openconnect's --protocol, needed before obtaining the cookie */ + protocol =vpn_provider_get_string (data->provider, +"OpenConnect.Protocol" ); +if (protocol && *protocol && +openconnect_set_protocol (data->vpninfo, protocol)) +connman_warn ("Unsupported OpenConnect protocol %s" , protocol); +/* Replicating how openconnect's --usergroup argument works */ urlpath =vpn_provider_get_string (data->provider,"OpenConnect.Usergroup" );
Signature · 1 line
2.50.1
PATCH 2/7 openconnect: Do not treat reconnect reasons as disconnect
In reply to Stéphane COLIN[openconnect] Do not treat reconnect reasons as disconnect.
When the connection is interrupted, e.g. after the device has been suspended, openconnect keeps the tun device and reconnects by itself. It calls the vpnc-script with the "attempt-reconnect" and "reconnect" reasons, but oc_notify() handles every reason other than "connect" as VPN_STATE_DISCONNECT.
As a result connman-vpnd tears the provider down while openconnect is still running: the tunnel is lost, the openconnect process is left orphaned and the UI stays in the "Disconnecting" state.
Return VPN_STATE_UNKNOWN for these two reasons so that the state is kept as is while openconnect reconnects.
--- vpn/plugins/openconnect.c | 9 +++++++++ 1 file changed, 9 insertions(+)
vpn/plugins/openconnect.c +9 -0
@@ -292,6 +292,15 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)return VPN_STATE_FAILURE ; } +/* +* openconnect keeps the tunnel up while it reconnects (e.g. after the +* device has been suspended) and reports it with these two reasons. +* They must not be treated as a disconnect. +*/ +if (!strcmp (reason,"attempt-reconnect" ) || + !strcmp (reason,"reconnect" )) +return VPN_STATE_UNKNOWN ; +if (strcmp (reason,"connect" ))return VPN_STATE_DISCONNECT ;
Signature · 1 line
2.50.1
PATCH 3/7 openconnect: Fill the GlobalProtect "passwd" form field
In reply to Stéphane COLIN[openconnect] Fill the GlobalProtect "passwd" form field.
process_auth_form() only fills password fields whose name starts with "password". The GlobalProtect login form names its password field "passwd", so it was left empty and the server rejected the login with an empty password, again and again.
Also fill a password field named "passwd".
--- vpn/plugins/openconnect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
vpn/plugins/openconnect.c +3 -1
@@ -917,7 +917,9 @@ static gboolean process_auth_form(void *user_data)if (user) opt->_value =strdup (user); }else if (opt->type ==OC_FORM_OPT_PASSWORD && -g_str_has_prefix (opt->name,"password" )) { + (g_str_has_prefix (opt->name,"password" ) || + !g_strcmp0 (opt->name,"passwd" ))) { +/* GlobalProtect names the password field "passwd" */ const char *pass = vpn_provider_get_string( data->provider,
Signature · 1 line
2.50.1
PATCH 4/7 openconnect: Limit repeated credential forms
In reply to Stéphane COLIN[openconnect] Limit repeated credential forms.
With the userpass authentication types the same stored credentials are submitted every time the server sends the login form again. When the server rejects them, connman-vpnd keeps resubmitting them in a tight loop (about 50 attempts were seen against a GlobalProtect gateway), which may lock the account.
Give up after OC_MAX_USERPASS_FORMS (3) forms: report an authentication failure and clear the stored credentials so that the user is asked for them again on the next attempt.
--- vpn/plugins/openconnect.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
vpn/plugins/openconnect.c +19 -0
@@ -92,6 +92,8 @@ enum oc_connect_type {static const char *connect_types[] = {"cookie" ,"cookie_with_userpass" ,"userpass" ,"publickey" ,"pkcs" ,NULL }; +#define OC_MAX_USERPASS_FORMS 3 +struct oc_private_data {struct vpn_provider *provider;struct connman_task *task;
@@ -111,6 +113,7 @@ struct oc_private_data {enum oc_connect_type connect_type;bool tried_passphrase;bool group_set; +int userpass_forms; }; typedef void (*request_input_reply_cb_t) (DBusMessage *reply,
@@ -848,6 +851,22 @@ static gboolean process_auth_form(void *user_data)switch (data->connect_type) {case OC_CONNECT_USERPASS :case OC_CONNECT_COOKIE_WITH_USERPASS : +/* +* The same stored credentials are submitted every time the +* server sends the form again. Stop after a few rounds so that +* rejected credentials do not hammer the server (and lock the +* account) in a tight loop. +*/ +if (++data->userpass_forms >OC_MAX_USERPASS_FORMS ) { +connman_warn ("Credentials rejected %d times, giving up" , +OC_MAX_USERPASS_FORMS ); +vpn_provider_add_error (data->provider, +VPN_PROVIDER_ERROR_AUTH_FAILED ); +clear_provider_credentials (data->provider, true); + data->err = -EACCES ; + form_data->status =OC_FORM_RESULT_ERR ; + goto out; + }break ;case OC_CONNECT_PKCS :
Signature · 1 line
2.50.1
PATCH 5/7 vpn-provider: Signal routes without gateway
In reply to Stéphane COLINSplit routes pushed to openconnect (CISCO_SPLIT_INC_n_ADDR/_MASK) have no gateway, so vpn_provider_append_route() never scheduled the ServerRoutes change and connmand, which ignores ServerRoutes when reading the initial connection properties, never installed them. A split tunnel then either sent all IPv4 through the VPN default route (SplitRouting false) or could not reach the VPN networks at all (SplitRouting true).
Signal the route as soon as it has a network and a netmask, the gateway being optional.
--- vpn/vpn-provider.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
vpn/vpn-provider.c +6 -1
@@ -3158,7 +3158,12 @@ int vpn_provider_append_route(struct vpn_provider *provider,break ; } -if (route->netmask && route->gateway && route->network) +/* +* Gateway is optional: split routes of e.g. openconnect +* (CISCO_SPLIT_INC_*) have only address and netmask and must still +* be signaled as ServerRoutes, otherwise connmand never adds them. +*/ +if (route->netmask && route->network)provider_schedule_changed (provider);return 0 ;
Signature · 1 line
2.50.1
PATCH 6/7 openconnect: Do not take _MASKLEN for _MASK in split routes
In reply to Stéphane COLINoc_route_env_parse() tested "_MASK" with strncmp() before "_MASKLEN", so CISCO_SPLIT_INC_n_MASKLEN also matched and, depending on the order of the environment, the IPv4 dotted netmask was replaced by the prefix length that connmand then passed to inet_addr().
Compare the suffixes exactly: _MASK for IPv4, _MASKLEN for IPv6.
--- vpn/plugins/openconnect.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
vpn/plugins/openconnect.c +3 -3
@@ -1831,11 +1831,11 @@ static int oc_route_env_parse(struct vpn_provider *provider, const char *key, *idx =g_ascii_strtoull (start, &end,10 ); -if (strncmp (end,"_ADDR" ,5 ) ==0 ) +if (strcmp (end,"_ADDR" ) ==0 ) *type =VPN_PROVIDER_ROUTE_TYPE_ADDR ; -else if (strncmp (end,"_MASK" ,5 ) ==0 ) +else if (strcmp (end,"_MASKLEN" ) ==0 && *family ==AF_INET6 ) *type =VPN_PROVIDER_ROUTE_TYPE_MASK ; -else if (strncmp (end,"_MASKLEN" ,8 ) ==0 && *family ==AF_INET6 ) +else if (strcmp (end,"_MASK" ) ==0 && *family ==AF_INET ) *type =VPN_PROVIDER_ROUTE_TYPE_MASK ;else return -EINVAL ;
Signature · 1 line
2.50.1
PATCH 7/7 openconnect: Offer the username again on the next login
In reply to Stéphane COLINThe username was never pre-filled in the credentials dialog: the plugin passed the username value to vpn_agent_append_user_info(), which expects the provider key, and the username was cleared to "-" together with the password after every connection attempt. Once the cookie had expired (e.g. after the VPN was fully down for the night), the user had to type it again.
Keep the username when the credentials are cleared, give the key to vpn_agent_append_user_info() and do not offer the "-" placeholder as a value. Password and cookie are still cleared as before. The username is kept in memory only; persisting it is left to the VPN agent.
--- vpn/plugins/openconnect.c | 7 +++---- vpn/vpn-agent.c | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-)
vpn/plugins/openconnect.c +3 -4
@@ -483,8 +483,8 @@ static bool strv_contains_prefix(const char *strv[], const char *str)static void clear_provider_credentials (struct vpn_provider *provider,bool clear_pkcs_pass) { +/* The username is kept: it is offered again on the next login */ const char *keys[] = {"OpenConnect.PKCSPassword" , -"OpenConnect.Username" ,"OpenConnect.Password" ,"OpenConnect.SecondPassword" ,"OpenConnect.Cookie" ,
@@ -1465,7 +1465,6 @@ static int request_input_credentials_full(const char *path;const char *agent_sender;const char *agent_path; -const char *username;DBusMessageIter iter;DBusMessageIter dict;int err;
@@ -1534,9 +1533,9 @@ static int request_input_credentials_full(case OC_CONNECT_COOKIE_WITH_USERPASS :/* fallthrough */ case OC_CONNECT_USERPASS : - username =vpn_provider_get_string (data->provider, +/* The key of the username, not its value */ +vpn_agent_append_user_info (&dict, data->provider,"OpenConnect.Username" ); -vpn_agent_append_user_info (&dict, data->provider, username); use_second_password = vpn_provider_get_boolean(data->provider, "OpenConnect.UseSecondPassword",
vpn/vpn-agent.c +2 -1
@@ -123,7 +123,8 @@ static void request_input_append_user_info(DBusMessageIter *iter,if (data->username_str) { str =vpn_provider_get_string (provider, data->username_str); -if (str) +/* "-" means cleared */ +if (str && *str &&g_strcmp0 (str,"-" ))connman_dbus_dict_append_basic (iter,"Value" ,DBUS_TYPE_STRING , &str); }
Signature · 1 line
2.50.1