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.
This commit is contained in:
Thomas Haller
2015-03-09 12:22:39 +01:00
parent dbbedce21f
commit 628f47285d
3 changed files with 22 additions and 5 deletions

View File

@@ -999,9 +999,13 @@ nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type)
if (!key) if (!key)
return FALSE; 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); keylen = strlen (key);
if ( wep_type == NM_WEP_KEY_TYPE_KEY if (wep_type == NM_WEP_KEY_TYPE_KEY) {
|| wep_type == NM_WEP_KEY_TYPE_UNKNOWN) {
if (keylen == 10 || keylen == 26) { if (keylen == 10 || keylen == 26) {
/* Hex key */ /* Hex key */
for (i = 0; i < keylen; i++) { for (i = 0; i < keylen; i++) {
@@ -1016,7 +1020,6 @@ nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type)
} }
} else } else
return FALSE; return FALSE;
} else if (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE) { } else if (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE) {
if (!keylen || keylen > 64) if (!keylen || keylen > 64)
return FALSE; return FALSE;

View File

@@ -696,9 +696,15 @@ write_wireless_security_setting (NMConnection *connection,
* keys. * keys.
*/ */
key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec); 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) if (key_type == NM_WEP_KEY_TYPE_PASSPHRASE)
tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); 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); tmp = g_strdup_printf ("KEY%d", i + 1);
/* Add 's:' prefix for ASCII keys */ /* Add 's:' prefix for ASCII keys */
@@ -706,7 +712,8 @@ write_wireless_security_setting (NMConnection *connection,
ascii_key = g_strdup_printf ("s:%s", key); ascii_key = g_strdup_printf ("s:%s", key);
key = ascii_key; key = ascii_key;
} }
} } else
key = NULL;
set_secret (ifcfg, set_secret (ifcfg,
tmp, tmp,

View File

@@ -526,6 +526,13 @@ add_wep_key (NMSupplicantConfig *self,
if (!key || !key_len) if (!key || !key_len)
return TRUE; 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) if ( (wep_type == NM_WEP_KEY_TYPE_UNKNOWN)
|| (wep_type == NM_WEP_KEY_TYPE_KEY)) { || (wep_type == NM_WEP_KEY_TYPE_KEY)) {
if ((key_len == 10) || (key_len == 26)) { if ((key_len == 10) || (key_len == 26)) {