From 9bd7703d05f8b28616945ba596d6904fb965d2a2 Mon Sep 17 00:00:00 2001 From: ok-home Date: Wed, 4 Oct 2023 09:22:53 +0700 Subject: [PATCH] preencrypted EMBED_TEXTFILES --- CMakeLists.txt | 1 + source/ota_ws_update_esp_preencrypted.c | 10 +++++++--- source/ota_ws_update_http.c | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c1ce10..0e15f15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ if(CONFIG_OTA_PRE_ENCRYPTED_MODE) #esp_wifi EMBED_FILES source/ota_ws_update.html + EMBED_TXTFILES rsa_key/private.pem ) #openssl genrsa -out rsa_key/private.pem 3072 diff --git a/source/ota_ws_update_esp_preencrypted.c b/source/ota_ws_update_esp_preencrypted.c index 252c275..39a8b7a 100644 --- a/source/ota_ws_update_esp_preencrypted.c +++ b/source/ota_ws_update_esp_preencrypted.c @@ -32,7 +32,7 @@ static bool image_header_was_checked = false; static esp_ota_handle_t update_handle = 0; // pre-encrypted handle static esp_decrypt_handle_t enc_handle; // handle -static esp_decrypt_cfg_t enc_cfg = {}; // cfg +//static esp_decrypt_cfg_t enc_cfg = {}; // cfg static pre_enc_decrypt_arg_t enc_arg = {}; // arg extern const char rsa_private_pem_start[] asm("_binary_private_pem_start"); @@ -75,6 +75,7 @@ esp_err_t start_ota_ws(void) image_header_was_checked = false; + esp_decrypt_cfg_t enc_cfg; // cfg enc_cfg.rsa_priv_key = rsa_private_pem_start; enc_cfg.rsa_priv_key_len = rsa_private_pem_end-rsa_private_pem_start; @@ -91,6 +92,7 @@ esp_err_t start_ota_ws(void) esp_err_t write_ota_ws(int enc_data_read, uint8_t *enc_ota_write_data) { //return ESP_OK; // debug return + pre_enc_decrypt_arg_t enc_arg; enc_arg.data_in = (char*)enc_ota_write_data; enc_arg.data_in_len = enc_data_read; esp_err_t ret = esp_encrypted_img_decrypt_data(enc_handle, &enc_arg); @@ -144,7 +146,6 @@ esp_err_t end_ota_ws(void) abort_ota_ws(); return ret; } - ret = esp_ota_end(update_handle); if (ret != ESP_OK) { if (ret == ESP_ERR_OTA_VALIDATE_FAILED) { @@ -168,7 +169,10 @@ esp_err_t abort_ota_ws(void) { esp_err_t ret = esp_encrypted_img_decrypt_abort(enc_handle); if(ret) - {return ret;} + { + esp_ota_abort(update_handle); + return ret; + } return esp_ota_abort(update_handle); } // false - rollback disable diff --git a/source/ota_ws_update_http.c b/source/ota_ws_update_http.c index 5af4e5e..d865020 100644 --- a/source/ota_ws_update_http.c +++ b/source/ota_ws_update_http.c @@ -171,13 +171,14 @@ static esp_err_t ota_ws_handler(httpd_req_t *req) } if (strncmp(json_key, OTA_PROCESS_ROLLBACK, sizeof(OTA_PROCESS_ROLLBACK)) == 0) // process rollback & { - ESP_LOGI(TAG,"rollback command %s %s",json_key,json_value); if(strncmp(json_value,"true",sizeof("true")) == 0) { + ESP_LOGI(TAG,"Rollback and restart"); ret = rollback_ota_ws(true); // rollback and restart } else { + ESP_LOGI(TAG,"App veryfied, fix ota update"); ret = rollback_ota_ws(false); // app veryfied } goto _recv_ret;