WPS: Convert WEP key to hex
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 27 Feb 2009 15:08:17 +0000 (17:08 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 27 Feb 2009 15:08:17 +0000 (17:08 +0200)
Use of hex is safer since the enrollee may configure AP with 5 or 13
random octets of binary data as the key.

hostapd/wps_hostapd.c

index 0905391..9def50a 100644 (file)
@@ -333,12 +333,15 @@ static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
                                key_idx--;
                        fprintf(nconf, "wep_default_key=%d\n", key_idx);
                        fprintf(nconf, "wep_key%d=", key_idx);
-                       if (cred->key_len != 10 && cred->key_len != 26)
-                               fputc('"', nconf);
-                       for (i = 0; i < cred->key_len; i++)
-                               fputc(cred->key[i], nconf);
-                       if (cred->key_len != 10 && cred->key_len != 26)
-                               fputc('"', nconf);
+                       if (cred->key_len == 10 || cred->key_len == 26) {
+                               /* WEP key as a hex string */
+                               for (i = 0; i < cred->key_len; i++)
+                                       fputc(cred->key[i], nconf);
+                       } else {
+                               /* Raw WEP key; convert to hex */
+                               for (i = 0; i < cred->key_len; i++)
+                                       fprintf(nconf, "%02x", cred->key[i]);
+                       }
                        fprintf(nconf, "\n");
                }
        }