mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
fix(wpa_supplicant): Fix few dpp bugs
1) Fix crash in dpp Listen without bootstrap 2) Fix crash on receiving dpp auth_req from hostapd with dpp akm 3) Ensures that the mode is set to station before dpp init 4) Ensures that dpp follows the path of init->bootstrap->listen
This commit is contained in:
parent
4ba42edafc
commit
8edd26b4f3
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -22,7 +22,7 @@ static void *s_dpp_api_lock = NULL;
|
|||||||
|
|
||||||
static bool s_dpp_stop_listening;
|
static bool s_dpp_stop_listening;
|
||||||
static int s_dpp_auth_retries;
|
static int s_dpp_auth_retries;
|
||||||
struct esp_dpp_context_t s_dpp_ctx;
|
static struct esp_dpp_context_t s_dpp_ctx;
|
||||||
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action;
|
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action;
|
||||||
|
|
||||||
#define DPP_API_LOCK() os_mutex_lock(s_dpp_api_lock)
|
#define DPP_API_LOCK() os_mutex_lock(s_dpp_api_lock)
|
||||||
@ -379,6 +379,10 @@ static void esp_dpp_task(void *pvParameters )
|
|||||||
static int counter;
|
static int counter;
|
||||||
int channel;
|
int channel;
|
||||||
|
|
||||||
|
if (p->num_chan <= 0) {
|
||||||
|
wpa_printf(MSG_ERROR, "Listen channel not set");
|
||||||
|
break;
|
||||||
|
}
|
||||||
channel = p->chan_list[counter++ % p->num_chan];
|
channel = p->chan_list[counter++ % p->num_chan];
|
||||||
esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, channel,
|
esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, channel,
|
||||||
BOOTSTRAP_ROC_WAIT_TIME, s_action_rx_cb);
|
BOOTSTRAP_ROC_WAIT_TIME, s_action_rx_cb);
|
||||||
@ -518,6 +522,10 @@ esp_err_t
|
|||||||
esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
|
esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
|
||||||
const char *key, const char *uri_info)
|
const char *key, const char *uri_info)
|
||||||
{
|
{
|
||||||
|
if (!s_dpp_ctx.dpp_global) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to bootstrap as dpp not initialized.");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
||||||
char *uri_chan_list = esp_dpp_parse_chan_list(chan_list);
|
char *uri_chan_list = esp_dpp_parse_chan_list(chan_list);
|
||||||
char *command = os_zalloc(1200);
|
char *command = os_zalloc(1200);
|
||||||
@ -581,6 +589,11 @@ fail:
|
|||||||
|
|
||||||
esp_err_t esp_supp_dpp_start_listen(void)
|
esp_err_t esp_supp_dpp_start_listen(void)
|
||||||
{
|
{
|
||||||
|
if (!s_dpp_ctx.dpp_global || s_dpp_ctx.id < 1) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to start listen as dpp not initialized or bootstrapped.");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
if (esp_wifi_get_user_init_flag_internal() == 0) {
|
if (esp_wifi_get_user_init_flag_internal() == 0) {
|
||||||
wpa_printf(MSG_ERROR, "DPP: ROC not possible before wifi is started");
|
wpa_printf(MSG_ERROR, "DPP: ROC not possible before wifi is started");
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
@ -598,6 +611,15 @@ void esp_supp_dpp_stop_listen(void)
|
|||||||
|
|
||||||
esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
|
esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
|
||||||
{
|
{
|
||||||
|
wifi_mode_t mode = 0;
|
||||||
|
if (esp_wifi_get_mode(&mode) || ((mode != WIFI_MODE_STA) && (mode != WIFI_MODE_APSTA))) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to init as not in station mode.");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
if (s_dpp_ctx.dpp_global) {
|
||||||
|
wpa_printf(MSG_ERROR, "DPP: failed to init as init already done.");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
struct dpp_global_config cfg = {0};
|
struct dpp_global_config cfg = {0};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -636,7 +658,6 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
|
|||||||
void esp_supp_dpp_deinit(void)
|
void esp_supp_dpp_deinit(void)
|
||||||
{
|
{
|
||||||
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
struct dpp_bootstrap_params_t *params = &s_dpp_ctx.bootstrap_params;
|
||||||
|
|
||||||
if (params->info) {
|
if (params->info) {
|
||||||
os_free(params->info);
|
os_free(params->info);
|
||||||
params->info = NULL;
|
params->info = NULL;
|
||||||
@ -647,7 +668,10 @@ void esp_supp_dpp_deinit(void)
|
|||||||
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ROC_DONE,
|
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ROC_DONE,
|
||||||
&offchan_event_handler);
|
&offchan_event_handler);
|
||||||
s_dpp_auth_retries = 0;
|
s_dpp_auth_retries = 0;
|
||||||
dpp_global_deinit(s_dpp_ctx.dpp_global);
|
if (s_dpp_ctx.dpp_global) {
|
||||||
esp_dpp_post_evt(SIG_DPP_DEL_TASK, 0);
|
dpp_global_deinit(s_dpp_ctx.dpp_global);
|
||||||
|
s_dpp_ctx.dpp_global = NULL;
|
||||||
|
esp_dpp_post_evt(SIG_DPP_DEL_TASK, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,7 +43,7 @@ struct dpp_global {
|
|||||||
static const struct dpp_curve_params dpp_curves[] = {
|
static const struct dpp_curve_params dpp_curves[] = {
|
||||||
/* The mandatory to support and the default NIST P-256 curve needs to
|
/* The mandatory to support and the default NIST P-256 curve needs to
|
||||||
* be the first entry on this list. */
|
* be the first entry on this list. */
|
||||||
{ "sec256r1", 32, 32, 16, 32, "P-256", 19, "ES256" },
|
{ "secp256r1", 32, 32, 16, 32, "P-256", 19, "ES256" },
|
||||||
{ "secp384r1", 48, 48, 24, 48, "P-384", 20, "ES384" },
|
{ "secp384r1", 48, 48, 24, 48, "P-384", 20, "ES384" },
|
||||||
{ "secp521r1", 64, 64, 32, 66, "P-521", 21, "ES512" },
|
{ "secp521r1", 64, 64, 32, 66, "P-521", 21, "ES512" },
|
||||||
{ "brainpoolP256r1", 32, 32, 16, 32, "BP-256", 28, "BS256" },
|
{ "brainpoolP256r1", 32, 32, 16, 32, "BP-256", 28, "BS256" },
|
||||||
@ -4669,7 +4669,8 @@ static struct crypto_key * dpp_parse_jwk(struct json_token *jwk,
|
|||||||
{
|
{
|
||||||
struct json_token *token;
|
struct json_token *token;
|
||||||
const struct dpp_curve_params *curve;
|
const struct dpp_curve_params *curve;
|
||||||
struct wpabuf *x = NULL, *y = NULL, *a = NULL;
|
struct wpabuf *x = NULL, *y = NULL;
|
||||||
|
unsigned char *a = NULL;
|
||||||
struct crypto_ec_group *group;
|
struct crypto_ec_group *group;
|
||||||
struct crypto_key *pkey = NULL;
|
struct crypto_key *pkey = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -4731,17 +4732,19 @@ static struct crypto_key * dpp_parse_jwk(struct json_token *jwk,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = wpabuf_len(x);
|
len = wpabuf_len(x) + wpabuf_len(y);
|
||||||
a = wpabuf_concat(x, y);
|
a = os_zalloc(len);
|
||||||
pkey = crypto_ec_set_pubkey_point(group, wpabuf_head(a),
|
os_memcpy(a, wpabuf_head(x), wpabuf_len(x));
|
||||||
len);
|
os_memcpy(a + wpabuf_len(x), wpabuf_head(y), wpabuf_len(y));
|
||||||
|
pkey = crypto_ec_set_pubkey_point(group, a, len);
|
||||||
|
|
||||||
crypto_ec_deinit((struct crypto_ec *)group);
|
crypto_ec_deinit((struct crypto_ec *)group);
|
||||||
*key_curve = curve;
|
*key_curve = curve;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
wpabuf_free(a);
|
|
||||||
wpabuf_free(x);
|
wpabuf_free(x);
|
||||||
wpabuf_free(y);
|
wpabuf_free(y);
|
||||||
|
os_free(a);
|
||||||
|
|
||||||
return pkey;
|
return pkey;
|
||||||
}
|
}
|
||||||
|
@ -155,9 +155,9 @@ void dpp_enrollee_init(void)
|
|||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb));
|
ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb));
|
||||||
ESP_ERROR_CHECK(dpp_enrollee_bootstrap());
|
ESP_ERROR_CHECK(dpp_enrollee_bootstrap());
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_start());
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
|
||||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||||
|
Loading…
x
Reference in New Issue
Block a user