summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-03-09 12:22:39 +0100
committerThomas Haller <thaller@redhat.com>2015-03-17 12:05:59 +0100
commit17f12fe1a94f3d433c12174a1e5ae3ed9f947680 (patch)
treeeb3e1f04327f3ba5f0ea86f97345fbc116a3c878
parentf7fc65ab79202f102badfb7afe827ff46d433b96 (diff)
downloadNetworkManager-th/wep-key-bgo745890.tar.gz
libnm: accept unknown WEP key type in nm_utils_wep_key_valid()th/wep-key-bgo745890
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.
-rw-r--r--libnm-core/nm-utils.c9
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c11
-rw-r--r--src/supplicant-manager/nm-supplicant-config.c7
3 files changed, 22 insertions, 5 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 7e0c6d9217..d3557f578a 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 5fe88746a3..75547641b1 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 d976bd703f..5df7b1e760 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)) {