浏览代码

simplify artwork and bypass server certificate verification

Philippe G 3 年之前
父节点
当前提交
72657d6951
共有 3 个文件被更改,包括 20 次插入20 次删除
  1. 3 2
      build-scripts/I2S-4MFlash-sdkconfig.defaults
  2. 3 2
      build-scripts/SqueezeAmp-sdkconfig.defaults
  3. 14 16
      components/tools/tools.c

+ 3 - 2
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
 

+ 3 - 2
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
 

+ 14 - 16
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);
-
+	
+	esp_http_client_config_t config = {
+		.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,
+	};	
+		
 	http_context->callback = callback;
 	http_context->user_context = context;
 	http_context->max = max;
-	http_context->url = strdup(url);
+	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_config_t config = {
-		.url = http_context->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);
+
+	esp_http_client_perform(http_context->client);
+	esp_http_client_cleanup(http_context->client);
 	
-	free(http_context->url);
 	free(http_context);
-	
 	vTaskDelete(NULL);
 }