From d228fc826c8524778d049d166572da9221610b2a Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Wed, 6 Jan 2021 15:49:11 +0530 Subject: [PATCH] protocomm security1: Restart security session if SESSION_STATE_CMD0 is received With the introduction of cookies to track a session, it is possible that the clients restart the provisioning on the same session, specifically when a user cancels a current provisioning attempt. This can result in an error as the state on the device side and client side will go out of sync. This has now been changed such that if SESSION_STATE_CMD0 is received on an existing session, the state is reset and flow allowed to continue. --- components/protocomm/src/security/security1.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/protocomm/src/security/security1.c b/components/protocomm/src/security/security1.c index b8a552f3ae..c32c51aeca 100644 --- a/components/protocomm/src/security/security1.c +++ b/components/protocomm/src/security/security1.c @@ -175,6 +175,8 @@ static esp_err_t handle_session_command1(session_t *cur_session, return ESP_OK; } +static esp_err_t sec1_new_session(protocomm_security_handle_t handle, uint32_t session_id); + static esp_err_t handle_session_command0(session_t *cur_session, uint32_t session_id, SessionData *req, SessionData *resp, @@ -186,8 +188,9 @@ static esp_err_t handle_session_command0(session_t *cur_session, int mbed_err; if (cur_session->state != SESSION_STATE_CMD0) { - ESP_LOGE(TAG, "Invalid state of session %d (expected %d)", SESSION_STATE_CMD0, cur_session->state); - return ESP_ERR_INVALID_STATE; + ESP_LOGW(TAG, "Invalid state of session %d (expected %d). Restarting session.", + SESSION_STATE_CMD0, cur_session->state); + sec1_new_session(cur_session, session_id); } if (in->sc0->client_pubkey.len != PUBLIC_KEY_LEN) {