fix(esp_local_ctrl): update for changes in protocomm security2 scheme

This commit is contained in:
Mahavir Jain
2025-03-04 22:51:27 +05:30
parent e708375782
commit 76bd80a56b
4 changed files with 44 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -19,6 +19,8 @@
#include "esp_local_ctrl.pb-c.h" #include "esp_local_ctrl.pb-c.h"
#define ESP_LOCAL_CTRL_VERSION "v1.0" #define ESP_LOCAL_CTRL_VERSION "v1.0"
/* JSON format string for version endpoint */
#define ESP_LOCAL_CTRL_VER_FMT_STR "{\"local_ctrl\":{\"ver\":\"%s\",\"sec_ver\":%d,\"sec_patch_ver\":%d}}"
struct inst_ctx { struct inst_ctx {
protocomm_t *pc; protocomm_t *pc;
@ -135,14 +137,6 @@ esp_err_t esp_local_ctrl_start(const esp_local_ctrl_config_t *config)
} }
} }
ret = protocomm_set_version(local_ctrl_inst_ctx->pc, "esp_local_ctrl/version",
ESP_LOCAL_CTRL_VERSION);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to set version endpoint");
esp_local_ctrl_stop();
return ret;
}
protocomm_security_t *proto_sec_handle = NULL; protocomm_security_t *proto_sec_handle = NULL;
switch (local_ctrl_inst_ctx->config.proto_sec.version) { switch (local_ctrl_inst_ctx->config.proto_sec.version) {
case PROTOCOM_SEC_CUSTOM: case PROTOCOM_SEC_CUSTOM:
@ -182,6 +176,29 @@ esp_err_t esp_local_ctrl_start(const esp_local_ctrl_config_t *config)
return ret; return ret;
} }
int sec_ver = 0;
uint8_t sec_patch_ver = 0;
protocomm_get_sec_version(local_ctrl_inst_ctx->pc, &sec_ver, &sec_patch_ver);
const int rsize = snprintf(NULL, 0, ESP_LOCAL_CTRL_VER_FMT_STR, ESP_LOCAL_CTRL_VERSION, sec_ver, sec_patch_ver) + 1;
char *ver_str = malloc(rsize);
if (!ver_str) {
ESP_LOGE(TAG, "Failed to allocate memory for version string");
esp_local_ctrl_stop();
return ESP_ERR_NO_MEM;
}
snprintf(ver_str, rsize, ESP_LOCAL_CTRL_VER_FMT_STR, ESP_LOCAL_CTRL_VERSION, sec_ver, sec_patch_ver);
ESP_LOGD(TAG, "ver_str: %s", ver_str);
ret = protocomm_set_version(local_ctrl_inst_ctx->pc, "esp_local_ctrl/version",
ver_str);
free(ver_str);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to set version endpoint");
esp_local_ctrl_stop();
return ret;
}
ret = protocomm_add_endpoint(local_ctrl_inst_ctx->pc, "esp_local_ctrl/control", ret = protocomm_add_endpoint(local_ctrl_inst_ctx->pc, "esp_local_ctrl/control",
esp_local_ctrl_data_handler, NULL); esp_local_ctrl_data_handler, NULL);
if (ret != ESP_OK) { if (ret != ESP_OK) {

View File

@ -348,6 +348,8 @@ static esp_err_t wifi_prov_mgr_start_service(const char *service_name, const cha
/* Set version information / capabilities of provisioning service and application */ /* Set version information / capabilities of provisioning service and application */
cJSON *version_json = wifi_prov_get_info_json(); cJSON *version_json = wifi_prov_get_info_json();
char *version_str = cJSON_Print(version_json); char *version_str = cJSON_Print(version_json);
ESP_LOGD(TAG, "version_str :%s:", version_str);
ret = protocomm_set_version(prov_ctx->pc, "proto-ver", version_str); ret = protocomm_set_version(prov_ctx->pc, "proto-ver", version_str);
free(version_str); free(version_str);
cJSON_Delete(version_json); cJSON_Delete(version_json);

View File

@ -1,9 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import argparse import argparse
import asyncio import asyncio
import json import json
@ -161,7 +160,7 @@ async def version_match(tp, protover, verbose=False):
# information with versions and capabilities of both # information with versions and capabilities of both
# provisioning service and application # provisioning service and application
info = json.loads(response) info = json.loads(response)
if info['prov']['ver'].lower() == protover.lower(): if info['local_ctrl']['ver'].lower() == protover.lower():
return True return True
except ValueError: except ValueError:
@ -188,14 +187,19 @@ async def has_capability(tp, capability='none', verbose=False):
# information with versions and capabilities of both # information with versions and capabilities of both
# provisioning service and application # provisioning service and application
info = json.loads(response) info = json.loads(response)
supported_capabilities = info['prov']['cap'] try:
if capability.lower() == 'none': supported_capabilities = info['local_ctrl']['cap']
# No specific capability to check, but capabilities if capability.lower() == 'none':
# feature is present so return True # No specific capability to check, but capabilities
return True # feature is present so return True
elif capability in supported_capabilities: return True
return True elif capability in supported_capabilities:
return False return True
return False
except KeyError:
# If capabilities field is not present, it means
# that capabilities are not supported
return False
except ValueError: except ValueError:
# If decoding as JSON fails, it means that capabilities # If decoding as JSON fails, it means that capabilities

View File

@ -431,7 +431,7 @@ async def main():
args.sec1_pop = '' args.sec1_pop = ''
if (args.secver == 2): if (args.secver == 2):
sec_patch_ver = await get_sec_patch_ver(obj_transport) sec_patch_ver = await get_sec_patch_ver(obj_transport, args.verbose)
if len(args.sec2_usr) == 0: if len(args.sec2_usr) == 0:
args.sec2_usr = input('Security Scheme 2 - SRP6a Username required: ') args.sec2_usr = input('Security Scheme 2 - SRP6a Username required: ')
if len(args.sec2_pwd) == 0: if len(args.sec2_pwd) == 0: