simplify artwork and bypass server certificate verification

This commit is contained in:
Philippe G
2022-01-10 11:24:19 -08:00
parent f09a95cc8b
commit 72657d6951
3 changed files with 21 additions and 21 deletions

View File

@@ -533,7 +533,8 @@ CONFIG_ESP_TLS_USING_MBEDTLS=y
# CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set # CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set
# CONFIG_ESP_TLS_SERVER is not set # CONFIG_ESP_TLS_SERVER is not set
# CONFIG_ESP_TLS_PSK_VERIFICATION 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 # end of ESP-TLS
# #
@@ -727,7 +728,7 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y
# #
# ESP HTTP client # 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 # CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set
# end of ESP HTTP client # end of ESP HTTP client

View File

@@ -505,7 +505,8 @@ CONFIG_ESP_TLS_USING_MBEDTLS=y
# CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set # CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set
# CONFIG_ESP_TLS_SERVER is not set # CONFIG_ESP_TLS_SERVER is not set
# CONFIG_ESP_TLS_PSK_VERIFICATION 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 # end of ESP-TLS
# #
@@ -699,7 +700,7 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y
# #
# ESP HTTP client # 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 # CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set
# end of ESP HTTP client # end of ESP HTTP client

View File

@@ -186,7 +186,7 @@ typedef struct {
size_t max, bytes; size_t max, bytes;
bool abort; bool abort;
uint8_t *data; uint8_t *data;
char *url; esp_http_client_handle_t client;
} http_context_t; } http_context_t;
static void http_downloader(void *arg); static void http_downloader(void *arg);
@@ -195,31 +195,29 @@ 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) { 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_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 = { esp_http_client_config_t config = {
.url = http_context->url, .url = url,
.event_handler = http_event_handler, .event_handler = http_event_handler,
.user_data = http_context, .user_data = http_context,
//.cert_pem = howsmyssl_com_root_cert_pem_start, //.cert_pem = howsmyssl_com_root_cert_pem_start,
//.skip_cert_common_name_check = true, //.skip_cert_common_name_check = true,
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); http_context->callback = callback;
esp_http_client_perform(client); http_context->user_context = context;
// esp_http_client_cleanup(client); 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); free(http_context);
vTaskDelete(NULL); vTaskDelete(NULL);
} }