From 20f612d99893259136fb5e4937dbe165c4268978 Mon Sep 17 00:00:00 2001 From: Purushottam Kushwaha Date: Fri, 10 Aug 2018 12:33:14 +0530 Subject: [PATCH] DPP: Set group id through DPP_AUTH_INIT or dpp_configurator_params This enhances DPP_AUTH_INIT, DPP_CONFIGURATOR_SIGN, and SET dpp_configurator_params to allow optional setting of the DPP groupId string for a Connector. If the value is not set, the previously wildcard value ("*") is used by default. Signed-off-by: Jouni Malinen --- src/ap/dpp_hostapd.c | 25 +++++++++++++++++++++++++ src/common/dpp.c | 7 ++++++- src/common/dpp.h | 1 + wpa_supplicant/dpp_supplicant.c | 25 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/ap/dpp_hostapd.c b/src/ap/dpp_hostapd.c index 4d2b71ad8..4ec044e17 100644 --- a/src/ap/dpp_hostapd.c +++ b/src/ap/dpp_hostapd.c @@ -518,6 +518,7 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, size_t pass_len = 0; u8 psk[PMK_LEN]; int psk_set = 0; + char *group_id = NULL; if (!cmd) return; @@ -553,6 +554,20 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, psk_set = 1; } + pos = os_strstr(cmd, " group_id="); + if (pos) { + size_t group_id_len; + + pos += 10; + end = os_strchr(pos, ' '); + group_id_len = end ? (size_t) (end - pos) : os_strlen(pos); + group_id = os_malloc(group_id_len + 1); + if (!group_id) + goto fail; + os_memcpy(group_id, pos, group_id_len); + group_id[group_id_len] = '\0'; + } + if (os_strstr(cmd, " conf=sta-")) { conf_sta = os_zalloc(sizeof(struct dpp_configuration)); if (!conf_sta) @@ -580,6 +595,10 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, } else { goto fail; } + if (os_strstr(cmd, " group_id=")) { + conf_sta->group_id = group_id; + group_id = NULL; + } } if (os_strstr(cmd, " conf=ap-")) { @@ -609,6 +628,10 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, } else { goto fail; } + if (os_strstr(cmd, " group_id=")) { + conf_ap->group_id = group_id; + group_id = NULL; + } } pos = os_strstr(cmd, " expiry="); @@ -639,12 +662,14 @@ static void hostapd_dpp_set_configurator(struct hostapd_data *hapd, auth->conf_sta = conf_sta; auth->conf_ap = conf_ap; auth->conf = conf; + os_free(group_id); return; fail: wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters"); dpp_configuration_free(conf_sta); dpp_configuration_free(conf_ap); + os_free(group_id); } diff --git a/src/common/dpp.c b/src/common/dpp.c index ea00c9384..74a524d21 100644 --- a/src/common/dpp.c +++ b/src/common/dpp.c @@ -3988,6 +3988,7 @@ void dpp_configuration_free(struct dpp_configuration *conf) if (!conf) return; str_clear_free(conf->passphrase); + os_free(conf->group_id); bin_clear_free(conf, sizeof(*conf)); } @@ -4134,6 +4135,9 @@ dpp_build_conf_obj_dpp(struct dpp_authentication *auth, int ap, extra_len += os_strlen(auth->groups_override); #endif /* CONFIG_TESTING_OPTIONS */ + if (conf->group_id) + extra_len += os_strlen(conf->group_id); + /* Connector (JSON dppCon object) */ dppcon = wpabuf_alloc(extra_len + 2 * auth->curve->prime_len * 4 / 3); if (!dppcon) @@ -4152,7 +4156,8 @@ dpp_build_conf_obj_dpp(struct dpp_authentication *auth, int ap, goto skip_groups; } #endif /* CONFIG_TESTING_OPTIONS */ - wpabuf_put_str(dppcon, "{\"groups\":[{\"groupId\":\"*\","); + wpabuf_printf(dppcon, "{\"groups\":[{\"groupId\":\"%s\",", + conf->group_id ? conf->group_id : "*"); wpabuf_printf(dppcon, "\"netRole\":\"%s\"}],", ap ? "ap" : "sta"); #ifdef CONFIG_TESTING_OPTIONS skip_groups: diff --git a/src/common/dpp.h b/src/common/dpp.h index 185a31c03..25759088a 100644 --- a/src/common/dpp.h +++ b/src/common/dpp.h @@ -153,6 +153,7 @@ struct dpp_configuration { os_time_t netaccesskey_expiry; /* TODO: groups */ + char *group_id; /* For legacy configuration */ char *passphrase; diff --git a/wpa_supplicant/dpp_supplicant.c b/wpa_supplicant/dpp_supplicant.c index d14203ff9..899c4c224 100644 --- a/wpa_supplicant/dpp_supplicant.c +++ b/wpa_supplicant/dpp_supplicant.c @@ -540,6 +540,7 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, size_t pass_len = 0; u8 psk[PMK_LEN]; int psk_set = 0; + char *group_id = NULL; if (!cmd) return; @@ -575,6 +576,20 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, psk_set = 1; } + pos = os_strstr(cmd, " group_id="); + if (pos) { + size_t group_id_len; + + pos += 10; + end = os_strchr(pos, ' '); + group_id_len = end ? (size_t) (end - pos) : os_strlen(pos); + group_id = os_malloc(group_id_len + 1); + if (!group_id) + goto fail; + os_memcpy(group_id, pos, group_id_len); + group_id[group_id_len] = '\0'; + } + if (os_strstr(cmd, " conf=sta-")) { conf_sta = os_zalloc(sizeof(struct dpp_configuration)); if (!conf_sta) @@ -602,6 +617,10 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, } else { goto fail; } + if (os_strstr(cmd, " group_id=")) { + conf_sta->group_id = group_id; + group_id = NULL; + } } if (os_strstr(cmd, " conf=ap-")) { @@ -631,6 +650,10 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, } else { goto fail; } + if (os_strstr(cmd, " group_id=")) { + conf_ap->group_id = group_id; + group_id = NULL; + } } pos = os_strstr(cmd, " expiry="); @@ -660,12 +683,14 @@ static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, auth->conf_sta = conf_sta; auth->conf_ap = conf_ap; auth->conf = conf; + os_free(group_id); return; fail: wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters"); dpp_configuration_free(conf_sta); dpp_configuration_free(conf_ap); + os_free(group_id); }