From 5030d7d9fde000d29d204d8c57153dc46827baca Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 15 Sep 2017 17:54:31 +0300 Subject: [PATCH] DPP: Allow raw hex PSK to be used for legacy configuration The new psk= can be used as an alternative to pass= when configuring the DPP Configurator with a legacy network parameters. Signed-off-by: Jouni Malinen --- src/ap/dpp_hostapd.c | 30 ++++++++++++++++++++++++------ wpa_supplicant/dpp_supplicant.c | 30 ++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/ap/dpp_hostapd.c b/src/ap/dpp_hostapd.c index 8b6a630c4..c73c56cc4 100644 --- a/src/ap/dpp_hostapd.c +++ b/src/ap/dpp_hostapd.c @@ -337,6 +337,8 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, size_t ssid_len = 4; char pass[64] = { }; size_t pass_len = 0; + u8 psk[PMK_LEN]; + int psk_set = 0; if (!cmd) return; @@ -364,6 +366,14 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, goto fail; } + pos = os_strstr(cmd, " psk="); + if (pos) { + pos += 5; + if (hexstr2bin(pos, psk, PMK_LEN) < 0) + goto fail; + psk_set = 1; + } + if (os_strstr(cmd, " conf=sta-")) { conf_sta = os_zalloc(sizeof(struct dpp_configuration)); if (!conf_sta) @@ -372,9 +382,13 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, conf_sta->ssid_len = ssid_len; if (os_strstr(cmd, " conf=sta-psk")) { conf_sta->dpp = 0; - conf_sta->passphrase = os_strdup(pass); - if (!conf_sta->passphrase) - goto fail; + if (psk_set) { + os_memcpy(conf_sta->psk, psk, PMK_LEN); + } else { + conf_sta->passphrase = os_strdup(pass); + if (!conf_sta->passphrase) + goto fail; + } } else if (os_strstr(cmd, " conf=sta-dpp")) { conf_sta->dpp = 1; } else { @@ -390,9 +404,13 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, conf_ap->ssid_len = ssid_len; if (os_strstr(cmd, " conf=ap-psk")) { conf_ap->dpp = 0; - conf_ap->passphrase = os_strdup(pass); - if (!conf_ap->passphrase) - goto fail; + if (psk_set) { + os_memcpy(conf_ap->psk, psk, PMK_LEN); + } else { + conf_ap->passphrase = os_strdup(pass); + if (!conf_ap->passphrase) + goto fail; + } } else if (os_strstr(cmd, " conf=ap-dpp")) { conf_ap->dpp = 1; } else { diff --git a/wpa_supplicant/dpp_supplicant.c b/wpa_supplicant/dpp_supplicant.c index f5d1409c3..44178f971 100644 --- a/wpa_supplicant/dpp_supplicant.c +++ b/wpa_supplicant/dpp_supplicant.c @@ -387,6 +387,8 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, size_t ssid_len = 4; char pass[64] = { }; size_t pass_len = 0; + u8 psk[PMK_LEN]; + int psk_set = 0; if (!cmd) return; @@ -414,6 +416,14 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, goto fail; } + pos = os_strstr(cmd, " psk="); + if (pos) { + pos += 5; + if (hexstr2bin(pos, psk, PMK_LEN) < 0) + goto fail; + psk_set = 1; + } + if (os_strstr(cmd, " conf=sta-")) { conf_sta = os_zalloc(sizeof(struct dpp_configuration)); if (!conf_sta) @@ -422,9 +432,13 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, conf_sta->ssid_len = ssid_len; if (os_strstr(cmd, " conf=sta-psk")) { conf_sta->dpp = 0; - conf_sta->passphrase = os_strdup(pass); - if (!conf_sta->passphrase) - goto fail; + if (psk_set) { + os_memcpy(conf_sta->psk, psk, PMK_LEN); + } else { + conf_sta->passphrase = os_strdup(pass); + if (!conf_sta->passphrase) + goto fail; + } } else if (os_strstr(cmd, " conf=sta-dpp")) { conf_sta->dpp = 1; } else { @@ -440,9 +454,13 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, conf_ap->ssid_len = ssid_len; if (os_strstr(cmd, " conf=ap-psk")) { conf_ap->dpp = 0; - conf_ap->passphrase = os_strdup(pass); - if (!conf_ap->passphrase) - goto fail; + if (psk_set) { + os_memcpy(conf_ap->psk, psk, PMK_LEN); + } else { + conf_ap->passphrase = os_strdup(pass); + if (!conf_ap->passphrase) + goto fail; + } } else if (os_strstr(cmd, " conf=ap-dpp")) { conf_ap->dpp = 1; } else {