From 72657d69515bf6d1d4da9e5ff814a7016e9b994e Mon Sep 17 00:00:00 2001 From: Philippe G Date: Mon, 10 Jan 2022 11:24:19 -0800 Subject: [PATCH] simplify artwork and bypass server certificate verification --- build-scripts/I2S-4MFlash-sdkconfig.defaults | 5 +-- build-scripts/SqueezeAmp-sdkconfig.defaults | 5 +-- components/tools/tools.c | 32 +++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build-scripts/I2S-4MFlash-sdkconfig.defaults b/build-scripts/I2S-4MFlash-sdkconfig.defaults index aaa52f80..11d9651a 100644 --- a/build-scripts/I2S-4MFlash-sdkconfig.defaults +++ b/build-scripts/I2S-4MFlash-sdkconfig.defaults @@ -533,7 +533,8 @@ CONFIG_ESP_TLS_USING_MBEDTLS=y # CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set # CONFIG_ESP_TLS_SERVER is not set # CONFIG_ESP_TLS_PSK_VERIFICATION is not set -# CONFIG_ESP_TLS_INSECURE is not set +CONFIG_ESP_TLS_INSECURE=y +CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y # end of ESP-TLS # @@ -727,7 +728,7 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y # # ESP HTTP client # -# CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS is not set +CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS # CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set # end of ESP HTTP client diff --git a/build-scripts/SqueezeAmp-sdkconfig.defaults b/build-scripts/SqueezeAmp-sdkconfig.defaults index 57abadb8..3c3f7ecc 100644 --- a/build-scripts/SqueezeAmp-sdkconfig.defaults +++ b/build-scripts/SqueezeAmp-sdkconfig.defaults @@ -505,7 +505,8 @@ CONFIG_ESP_TLS_USING_MBEDTLS=y # CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set # CONFIG_ESP_TLS_SERVER is not set # CONFIG_ESP_TLS_PSK_VERIFICATION is not set -# CONFIG_ESP_TLS_INSECURE is not set +CONFIG_ESP_TLS_INSECURE=y +CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y # end of ESP-TLS # @@ -699,7 +700,7 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y # # ESP HTTP client # -# CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS is not set +CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS # CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set # end of ESP HTTP client diff --git a/components/tools/tools.c b/components/tools/tools.c index 1c877ff2..1ee41680 100644 --- a/components/tools/tools.c +++ b/components/tools/tools.c @@ -186,7 +186,7 @@ typedef struct { size_t max, bytes; bool abort; uint8_t *data; - char *url; + esp_http_client_handle_t client; } http_context_t; static void http_downloader(void *arg); @@ -194,32 +194,30 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt); void http_download(char *url, size_t max, http_download_cb_t callback, void *context) { http_context_t *http_context = (http_context_t*) heap_caps_calloc(sizeof(http_context_t), 1, MALLOC_CAP_SPIRAM); - - http_context->callback = callback; - http_context->user_context = context; - http_context->max = max; - http_context->url = strdup(url); - xTaskCreate(http_downloader, "downloader", 4*1024, http_context, ESP_TASK_PRIO_MIN + 1, NULL); -} - -static void http_downloader(void *arg) { - http_context_t *http_context = (http_context_t*) arg; esp_http_client_config_t config = { - .url = http_context->url, + .url = url, .event_handler = http_event_handler, .user_data = http_context, //.cert_pem = howsmyssl_com_root_cert_pem_start, //.skip_cert_common_name_check = true, }; - esp_http_client_handle_t client = esp_http_client_init(&config); - esp_http_client_perform(client); -// esp_http_client_cleanup(client); + http_context->callback = callback; + http_context->user_context = context; + http_context->max = max; + http_context->client = esp_http_client_init(&config); + + xTaskCreate(http_downloader, "downloader", 4*1024, http_context, ESP_TASK_PRIO_MIN + 1, NULL); +} + +static void http_downloader(void *arg) { + http_context_t *http_context = (http_context_t*) arg; + + esp_http_client_perform(http_context->client); + esp_http_client_cleanup(http_context->client); - free(http_context->url); free(http_context); - vTaskDelete(NULL); }