From: Jouni Malinen Date: Mon, 3 Jul 2017 10:01:35 +0000 (+0300) Subject: DPP: Update hostapd configurator parameters to match wpa_supplicant X-Git-Tag: hostap_2_7~1236 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6b140f0fa24494b77ca8987c2bf27c9509f82fa6;p=thirdparty%2Fhostap.git DPP: Update hostapd configurator parameters to match wpa_supplicant This updates the previously copied implementation to be up-to-date with the more recent wpa_supplicant changes. Signed-off-by: Jouni Malinen --- diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index e5c7e9962..5503f4476 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -1325,6 +1325,11 @@ static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd) * disallowing station logic. */ #endif /* CONFIG_MBO */ +#ifdef CONFIG_DPP + } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) { + os_free(hapd->dpp_configurator_params); + hapd->dpp_configurator_params = os_strdup(value); +#endif /* CONFIG_DPP */ } else { struct sta_info *sta; struct vlan_description vlan_id; diff --git a/src/ap/dpp_hostapd.c b/src/ap/dpp_hostapd.c index 648ae6503..f6ac9c8cf 100644 --- a/src/ap/dpp_hostapd.c +++ b/src/ap/dpp_hostapd.c @@ -25,6 +25,20 @@ static void hostapd_dpp_auth_success(struct hostapd_data *hapd, int initiator); static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; +static struct dpp_configurator * +hostapd_dpp_configurator_get_id(struct hostapd_data *hapd, unsigned int id) +{ + struct dpp_configurator *conf; + + dl_list_for_each(conf, &hapd->dpp_configurator, + struct dpp_configurator, list) { + if (conf->id == id) + return conf; + } + return NULL; +} + + static unsigned int hapd_dpp_next_id(struct hostapd_data *hapd) { struct dpp_bootstrap_info *bi; @@ -293,53 +307,41 @@ static void hostapd_dpp_set_testing_options(struct hostapd_data *hapd, } -int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd) +static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, + struct dpp_authentication *auth, + const char *cmd) { - const char *pos; - struct dpp_bootstrap_info *peer_bi, *own_bi = NULL; - struct wpabuf *msg; - const u8 *dst; - int res; - int configurator = 1; + const char *pos, *end; struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL; + struct dpp_configurator *conf = NULL; + u8 ssid[32] = { "test" }; + size_t ssid_len = 4; + char pass[64] = { }; + size_t pass_len = 0; - pos = os_strstr(cmd, " peer="); - if (!pos) - return -1; - pos += 6; - peer_bi = dpp_bootstrap_get_id(hapd, atoi(pos)); - if (!peer_bi) { - wpa_printf(MSG_INFO, - "DPP: Could not find bootstrapping info for the identified peer"); - return -1; - } + if (!cmd) + return; - pos = os_strstr(cmd, " own="); + wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd); + pos = os_strstr(cmd, " ssid="); if (pos) { - pos += 5; - own_bi = dpp_bootstrap_get_id(hapd, atoi(pos)); - if (!own_bi) { - wpa_printf(MSG_INFO, - "DPP: Could not find bootstrapping info for the identified local entry"); - return -1; - } - - if (peer_bi->curve != own_bi->curve) { - wpa_printf(MSG_INFO, - "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)", - peer_bi->curve->name, own_bi->curve->name); - return -1; - } + pos += 6; + end = os_strchr(pos, ' '); + ssid_len = end ? (size_t) (end - pos) : os_strlen(pos); + ssid_len /= 2; + if (ssid_len > sizeof(ssid) || + hexstr2bin(pos, ssid, ssid_len) < 0) + goto fail; } - pos = os_strstr(cmd, " role="); + pos = os_strstr(cmd, " pass="); if (pos) { pos += 6; - if (os_strncmp(pos, "configurator", 12) == 0) - configurator = 1; - else if (os_strncmp(pos, "enrollee", 8) == 0) - configurator = 0; - else + end = os_strchr(pos, ' '); + pass_len = end ? (size_t) (end - pos) : os_strlen(pos); + pass_len /= 2; + if (pass_len > sizeof(pass) - 1 || pass_len < 8 || + hexstr2bin(pos, (u8 *) pass, pass_len) < 0) goto fail; } @@ -347,13 +349,11 @@ int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd) conf_sta = os_zalloc(sizeof(struct dpp_configuration)); if (!conf_sta) goto fail; - /* TODO: Configuration of network parameters from upper layers - */ - os_memcpy(conf_sta->ssid, "test", 4); - conf_sta->ssid_len = 4; + os_memcpy(conf_sta->ssid, ssid, ssid_len); + conf_sta->ssid_len = ssid_len; if (os_strstr(cmd, " conf=sta-psk")) { conf_sta->dpp = 0; - conf_sta->passphrase = os_strdup("secret passphrase"); + conf_sta->passphrase = os_strdup(pass); if (!conf_sta->passphrase) goto fail; } else if (os_strstr(cmd, " conf=sta-dpp")) { @@ -367,13 +367,11 @@ int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd) conf_ap = os_zalloc(sizeof(struct dpp_configuration)); if (!conf_ap) goto fail; - /* TODO: Configuration of network parameters from upper layers - */ - os_memcpy(conf_ap->ssid, "test", 4); - conf_ap->ssid_len = 4; + os_memcpy(conf_ap->ssid, ssid, ssid_len); + conf_ap->ssid_len = ssid_len; if (os_strstr(cmd, " conf=ap-psk")) { conf_ap->dpp = 0; - conf_ap->passphrase = os_strdup("secret passphrase"); + conf_ap->passphrase = os_strdup(pass); if (!conf_ap->passphrase) goto fail; } else if (os_strstr(cmd, " conf=ap-dpp")) { @@ -397,14 +395,86 @@ int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd) conf_ap->netaccesskey_expiry = val; } + pos = os_strstr(cmd, " configurator="); + if (pos) { + auth->configurator = 1; + pos += 14; + conf = hostapd_dpp_configurator_get_id(hapd, atoi(pos)); + if (!conf) { + wpa_printf(MSG_INFO, + "DPP: Could not find the specified configurator"); + goto fail; + } + } + auth->conf_sta = conf_sta; + auth->conf_ap = conf_ap; + auth->conf = conf; + return; + +fail: + wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters"); + dpp_configuration_free(conf_sta); + dpp_configuration_free(conf_ap); +} + + +int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd) +{ + const char *pos; + struct dpp_bootstrap_info *peer_bi, *own_bi = NULL; + struct wpabuf *msg; + const u8 *dst; + int res; + int configurator = 1; + struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL; + + pos = os_strstr(cmd, " peer="); + if (!pos) + return -1; + pos += 6; + peer_bi = dpp_bootstrap_get_id(hapd, atoi(pos)); + if (!peer_bi) { + wpa_printf(MSG_INFO, + "DPP: Could not find bootstrapping info for the identified peer"); + return -1; + } + + pos = os_strstr(cmd, " own="); + if (pos) { + pos += 5; + own_bi = dpp_bootstrap_get_id(hapd, atoi(pos)); + if (!own_bi) { + wpa_printf(MSG_INFO, + "DPP: Could not find bootstrapping info for the identified local entry"); + return -1; + } + + if (peer_bi->curve != own_bi->curve) { + wpa_printf(MSG_INFO, + "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)", + peer_bi->curve->name, own_bi->curve->name); + return -1; + } + } + + pos = os_strstr(cmd, " role="); + if (pos) { + pos += 6; + if (os_strncmp(pos, "configurator", 12) == 0) + configurator = 1; + else if (os_strncmp(pos, "enrollee", 8) == 0) + configurator = 0; + else + goto fail; + } + if (hapd->dpp_auth) dpp_auth_deinit(hapd->dpp_auth); hapd->dpp_auth = dpp_auth_init(hapd, peer_bi, own_bi, configurator); if (!hapd->dpp_auth) goto fail; hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth); - hapd->dpp_auth->conf_sta = conf_sta; - hapd->dpp_auth->conf_ap = conf_ap; + hostapd_dpp_set_configurator(hapd, hapd->dpp_auth, cmd); /* TODO: Support iteration over all frequencies and filtering of * frequencies based on locally enabled channels that allow initiation @@ -530,6 +600,8 @@ static void hostapd_dpp_rx_auth_req(struct hostapd_data *hapd, const u8 *src, return; } hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth); + hostapd_dpp_set_configurator(hapd, hapd->dpp_auth, + hapd->dpp_configurator_params); os_memcpy(hapd->dpp_auth->peer_mac_addr, src, ETH_ALEN); msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP, @@ -1395,4 +1467,6 @@ void hostapd_dpp_deinit(struct hostapd_data *hapd) hapd->dpp_auth = NULL; hostapd_dpp_pkex_remove(hapd, "*"); hapd->dpp_pkex = NULL; + os_free(hapd->dpp_configurator_params); + hapd->dpp_configurator_params = NULL; } diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 794635f66..2afeee218 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -334,6 +334,7 @@ struct hostapd_data { char *dpp_pkex_code; char *dpp_pkex_identifier; char *dpp_pkex_auth_cmd; + char *dpp_configurator_params; #ifdef CONFIG_TESTING_OPTIONS char *dpp_config_obj_override; char *dpp_discovery_override;