From 628f47285dbefe2d57ba42e64db6c8843bdbf742 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 9 Mar 2015 12:22:39 +0100 Subject: [PATCH] libnm: accept unknown WEP key type in nm_utils_wep_key_valid() libnm-core treated the UNKNOWN WEP key type as KEY. Relax that and try to guess the correct type based on the key. This is for example important if you have a valid connection with wep-key-type=0 (unknown) If you request passwords for such a connection, the user cannot enter them in password format -- but there is no UI indication that the password must be KEY. --- libnm-core/nm-utils.c | 9 ++++++--- src/settings/plugins/ifcfg-rh/writer.c | 11 +++++++++-- src/supplicant-manager/nm-supplicant-config.c | 7 +++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 7e0c6d921..d3557f578 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -999,9 +999,13 @@ nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type) if (!key) return FALSE; + if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) { + return nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY) || + nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE); + } + keylen = strlen (key); - if ( wep_type == NM_WEP_KEY_TYPE_KEY - || wep_type == NM_WEP_KEY_TYPE_UNKNOWN) { + if (wep_type == NM_WEP_KEY_TYPE_KEY) { if (keylen == 10 || keylen == 26) { /* Hex key */ for (i = 0; i < keylen; i++) { @@ -1016,7 +1020,6 @@ nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type) } } else return FALSE; - } else if (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE) { if (!keylen || keylen > 64) return FALSE; diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 5fe88746a..75547641b 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -696,9 +696,15 @@ write_wireless_security_setting (NMConnection *connection, * keys. */ key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec); + if (key_type == NM_WEP_KEY_TYPE_UNKNOWN) { + if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY)) + key_type = NM_WEP_KEY_TYPE_KEY; + else if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE)) + key_type = NM_WEP_KEY_TYPE_PASSPHRASE; + } if (key_type == NM_WEP_KEY_TYPE_PASSPHRASE) tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - else { + else if (key_type == NM_WEP_KEY_TYPE_KEY) { tmp = g_strdup_printf ("KEY%d", i + 1); /* Add 's:' prefix for ASCII keys */ @@ -706,7 +712,8 @@ write_wireless_security_setting (NMConnection *connection, ascii_key = g_strdup_printf ("s:%s", key); key = ascii_key; } - } + } else + key = NULL; set_secret (ifcfg, tmp, diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c index d976bd703..5df7b1e76 100644 --- a/src/supplicant-manager/nm-supplicant-config.c +++ b/src/supplicant-manager/nm-supplicant-config.c @@ -526,6 +526,13 @@ add_wep_key (NMSupplicantConfig *self, if (!key || !key_len) return TRUE; + if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) { + if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY)) + wep_type = NM_WEP_KEY_TYPE_KEY; + else if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE)) + wep_type = NM_WEP_KEY_TYPE_PASSPHRASE; + } + if ( (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) || (wep_type == NM_WEP_KEY_TYPE_KEY)) { if ((key_len == 10) || (key_len == 26)) {