mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
wpa_supplicant/dpp: Move adding prefix/postfix of DPP key to example
1. Move adding of prefix/postfix to the private key to example code. This is to preserve forward compatibility when more curves are supported. 2. Documentation correction of bootstrapping key configuration.
This commit is contained in:
parent
667edfa7a9
commit
282d3c6188
@ -71,7 +71,7 @@ void esp_supp_dpp_deinit(void);
|
||||
*
|
||||
* @param chan_list List of channels device will be available on for listening
|
||||
* @param type Bootstrap method type, only QR Code method is supported for now.
|
||||
* @param key (Optional) Private Key used to generate a Bootstrapping Public Key
|
||||
* @param key (Optional) 32 byte Raw Private Key for generating a Bootstrapping Public Key
|
||||
* @param info (Optional) Ancilliary Device Information like Serial Number
|
||||
*
|
||||
* @return
|
||||
|
@ -559,27 +559,9 @@ esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
|
||||
}
|
||||
}
|
||||
|
||||
if (key) {
|
||||
params->key_len = strlen(key);
|
||||
if (params->key_len) {
|
||||
char prefix[] = "30310201010420";
|
||||
char postfix[] = "a00a06082a8648ce3d030107";
|
||||
|
||||
params->key = os_zalloc(params->key_len +
|
||||
sizeof(prefix) + sizeof(postfix));
|
||||
if (!params->key) {
|
||||
os_free(command);
|
||||
ret = ESP_ERR_NO_MEM;
|
||||
goto fail;
|
||||
}
|
||||
sprintf(params->key, "%s%s%s", prefix, key, postfix);
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(command, "type=qrcode mac=" MACSTR "%s%s%s%s%s",
|
||||
MAC2STR(params->mac), uri_chan_list,
|
||||
params->key_len ? "key=" : "",
|
||||
params->key_len ? params->key : "",
|
||||
key ? "key=" : "", key ? key : "",
|
||||
params->info_len ? " info=" : "",
|
||||
params->info_len ? params->info : "");
|
||||
|
||||
@ -590,10 +572,6 @@ esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
|
||||
os_free(params->info);
|
||||
params->info = NULL;
|
||||
}
|
||||
if (params->key) {
|
||||
os_free(params->key);
|
||||
params->key = NULL;
|
||||
}
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -667,10 +645,6 @@ void esp_supp_dpp_deinit(void)
|
||||
os_free(params->info);
|
||||
params->info = NULL;
|
||||
}
|
||||
if (params->key) {
|
||||
os_free(params->key);
|
||||
params->key = NULL;
|
||||
}
|
||||
|
||||
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ACTION_TX_STATUS,
|
||||
&offchan_event_handler);
|
||||
|
@ -1,16 +1,8 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ESP_DPP_I_H
|
||||
#define ESP_DPP_I_H
|
||||
@ -47,8 +39,6 @@ struct dpp_bootstrap_params_t {
|
||||
uint8_t chan_list[14];
|
||||
uint8_t num_chan;
|
||||
uint8_t mac[6];
|
||||
uint32_t key_len;
|
||||
char *key;
|
||||
uint32_t info_len;
|
||||
char *info;
|
||||
};
|
||||
|
@ -8,7 +8,7 @@ menu "Example Configuration"
|
||||
config ESP_DPP_BOOTSTRAPPING_KEY
|
||||
string "Bootstrapping key"
|
||||
help
|
||||
Private key string for DPP Bootstrapping in PEM format.
|
||||
64 hex digits (or 32 bytes) of raw private key for DPP Bootstrapping.
|
||||
|
||||
config ESP_DPP_DEVICE_INFO
|
||||
string "Additional Device Info"
|
||||
|
@ -36,6 +36,8 @@
|
||||
#define EXAMPLE_DPP_DEVICE_INFO 0
|
||||
#endif
|
||||
|
||||
#define CURVE_SEC256R1_PKEY_HEX_DIGITS 64
|
||||
|
||||
static const char *TAG = "wifi dpp-enrollee";
|
||||
wifi_config_t s_dpp_wifi_config;
|
||||
|
||||
@ -104,6 +106,40 @@ void dpp_enrollee_event_cb(esp_supp_dpp_event_t event, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t dpp_enrollee_bootstrap(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
size_t pkey_len = strlen(EXAMPLE_DPP_BOOTSTRAPPING_KEY);
|
||||
char *key = NULL;
|
||||
|
||||
if (pkey_len) {
|
||||
/* Currently only NIST P-256 curve is supported, add prefix/postfix accordingly */
|
||||
char prefix[] = "30310201010420";
|
||||
char postfix[] = "a00a06082a8648ce3d030107";
|
||||
|
||||
if (pkey_len != CURVE_SEC256R1_PKEY_HEX_DIGITS) {
|
||||
ESP_LOGI(TAG, "Invalid key length! Private key needs to be 32 bytes (or 64 hex digits) long");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
key = malloc(sizeof(prefix) + pkey_len + sizeof(postfix));
|
||||
if (!key) {
|
||||
ESP_LOGI(TAG, "Failed to allocate for bootstrapping key");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
sprintf(key, "%s%s%s", prefix, EXAMPLE_DPP_BOOTSTRAPPING_KEY, postfix);
|
||||
}
|
||||
|
||||
/* Currently only supported method is QR Code */
|
||||
ret = esp_supp_dpp_bootstrap_gen(EXAMPLE_DPP_LISTEN_CHANNEL_LIST, DPP_BOOTSTRAP_QR_CODE,
|
||||
key, EXAMPLE_DPP_DEVICE_INFO);
|
||||
|
||||
if (key)
|
||||
free(key);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dpp_enrollee_init(void)
|
||||
{
|
||||
s_dpp_event_group = xEventGroupCreate();
|
||||
@ -120,10 +156,7 @@ void dpp_enrollee_init(void)
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb));
|
||||
/* Currently only supported method is QR Code */
|
||||
ESP_ERROR_CHECK(esp_supp_dpp_bootstrap_gen(EXAMPLE_DPP_LISTEN_CHANNEL_LIST, DPP_BOOTSTRAP_QR_CODE,
|
||||
EXAMPLE_DPP_BOOTSTRAPPING_KEY, EXAMPLE_DPP_DEVICE_INFO));
|
||||
|
||||
ESP_ERROR_CHECK(dpp_enrollee_bootstrap());
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
|
@ -1697,7 +1697,6 @@ components/wifi_provisioning/src/wifi_provisioning_priv.h
|
||||
components/wifi_provisioning/src/wifi_scan.c
|
||||
components/wpa_supplicant/esp_supplicant/include/esp_rrm.h
|
||||
components/wpa_supplicant/esp_supplicant/include/esp_wps.h
|
||||
components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h
|
||||
components/wpa_supplicant/esp_supplicant/src/esp_scan_i.h
|
||||
components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c
|
||||
components/wpa_supplicant/esp_supplicant/src/esp_wpa3_i.h
|
||||
|
Loading…
Reference in New Issue
Block a user