diff --git a/system-settings/plugins/ifcfg-rh/reader.c b/system-settings/plugins/ifcfg-rh/reader.c index a084d30b16..1c7e8eb6c7 100644 --- a/system-settings/plugins/ifcfg-rh/reader.c +++ b/system-settings/plugins/ifcfg-rh/reader.c @@ -1622,21 +1622,27 @@ add_one_wep_key (shvarFile *ifcfg, p++; } key = g_strdup (value); - } else if ( strncmp (value, "s:", 2) + } else if ( !strncmp (value, "s:", 2) && (strlen (value) == 7 || strlen (value) == 15)) { - /* ASCII passphrase */ + /* ASCII key */ char *p = value + 2; while (*p) { if (!isascii ((int) (*p))) { g_set_error (error, ifcfg_plugin_error_quark (), 0, - "Invalid ASCII WEP passphrase."); + "Invalid ASCII WEP key."); goto out; } p++; } - key = utils_bin2hexstr (value, strlen (value), strlen (value) * 2); + /* Remove 's:' prefix. + * Don't convert to hex string. wpa_supplicant takes 'wep_key0' option over D-Bus as byte array + * and converts it to hex string itself. Even though we convert hex string keys into a bin string + * before passing to wpa_supplicant, this prevents two unnecessary conversions. And mainly, + * ASCII WEP key doesn't change to HEX WEP key in UI, which could confuse users. + */ + key = g_strdup (value + 2); } } diff --git a/system-settings/plugins/ifcfg-rh/writer.c b/system-settings/plugins/ifcfg-rh/writer.c index de69e0039e..2d206c7354 100644 --- a/system-settings/plugins/ifcfg-rh/writer.c +++ b/system-settings/plugins/ifcfg-rh/writer.c @@ -605,6 +605,8 @@ write_wireless_security_setting (NMConnection *connection, key = nm_setting_wireless_security_get_wep_key (s_wsec, i); if (key) { + char *ascii_key = NULL; + /* Passphrase needs a different ifcfg key since with WEP, there * are some passphrases that are indistinguishable from WEP hex * keys. @@ -612,11 +614,19 @@ write_wireless_security_setting (NMConnection *connection, key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec); if (key_type == NM_WEP_KEY_TYPE_PASSPHRASE) tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - else + else { tmp = g_strdup_printf ("KEY%d", i + 1); + /* Add 's:' prefix for ASCII keys */ + if (strlen (key) == 5 || strlen (key) == 13) { + ascii_key = g_strdup_printf ("s:%s", key); + key = ascii_key; + } + } + set_secret (ifcfg, tmp, key, FALSE); g_free (tmp); + g_free (ascii_key); } } }