]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Allow arbitrary key configuration for testing
authorJouni Malinen <j@w1.fi>
Sat, 14 Oct 2017 14:49:33 +0000 (17:49 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 16 Oct 2017 14:47:24 +0000 (17:47 +0300)
The new hostapd control interface command SET_KEY can be used to request
an arbitrary key to be configured to the driver.

This functionality is for testing purposes and included only in builds
with CONFIG_TESTING_OPTIONS=y.

Signed-off-by: Jouni Malinen <j@w1.fi>
hostapd/ctrl_iface.c

index 4f4ed62d72aaf6cdea5673c530001ea3de08a50f..8e6b5371aed39386ef67c9a70609f2c3674a071a 100644 (file)
@@ -2034,6 +2034,54 @@ static int hostapd_ctrl_reset_pn(struct hostapd_data *hapd, const char *cmd)
 }
 
 
+static int hostapd_ctrl_set_key(struct hostapd_data *hapd, const char *cmd)
+{
+       u8 addr[ETH_ALEN];
+       const char *pos = cmd;
+       enum wpa_alg alg;
+       int idx, set_tx;
+       u8 seq[6], key[WPA_TK_MAX_LEN];
+       size_t key_len;
+
+       /* parameters: alg addr idx set_tx seq key */
+
+       alg = atoi(pos);
+       pos = os_strchr(pos, ' ');
+       if (!pos)
+               return -1;
+       pos++;
+       if (hwaddr_aton(pos, addr))
+               return -1;
+       pos += 17;
+       if (*pos != ' ')
+               return -1;
+       pos++;
+       idx = atoi(pos);
+       pos = os_strchr(pos, ' ');
+       if (!pos)
+               return -1;
+       pos++;
+       set_tx = atoi(pos);
+       pos = os_strchr(pos, ' ');
+       if (!pos)
+               return -1;
+       pos++;
+       if (hexstr2bin(pos, seq, sizeof(6)) < 0)
+               return -1;
+       pos += 2 * 6;
+       if (*pos != ' ')
+               return -1;
+       pos++;
+       key_len = os_strlen(pos) / 2;
+       if (hexstr2bin(pos, key, key_len) < 0)
+               return -1;
+
+       wpa_printf(MSG_INFO, "TESTING: Set key");
+       return hostapd_drv_set_key(hapd->conf->iface, hapd, alg, addr, idx,
+                                  set_tx, seq, 6, key, key_len);
+}
+
+
 static int hostapd_ctrl_resend_m1(struct hostapd_data *hapd, const char *cmd)
 {
        struct sta_info *sta;
@@ -2807,6 +2855,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
        } else if (os_strncmp(buf, "RESET_PN ", 9) == 0) {
                if (hostapd_ctrl_reset_pn(hapd, buf + 9) < 0)
                        reply_len = -1;
+       } else if (os_strncmp(buf, "SET_KEY ", 8) == 0) {
+               if (hostapd_ctrl_set_key(hapd, buf + 8) < 0)
+                       reply_len = -1;
        } else if (os_strncmp(buf, "RESEND_M1 ", 10) == 0) {
                if (hostapd_ctrl_resend_m1(hapd, buf + 10) < 0)
                        reply_len = -1;