mirror of
				https://github.com/espressif/esp-idf.git
				synced 2025-11-04 14:14:11 +00:00 
			
		
		
		
	examples: add dependency on cert bundle configuration
Refactor examples to build with MBEDTLS_CERTIFICATE_BUNDLE disabled. Only examples that can work with certificate bundle disabled have been modified here.
This commit is contained in:
		
				
					committed by
					
						
						Harshit Malpani
					
				
			
			
				
	
			
			
			
						parent
						
							d8ffa6df04
						
					
				
				
					commit
					2cfae63c2b
				
			@@ -18,6 +18,9 @@
 | 
				
			|||||||
#include "esp_netif.h"
 | 
					#include "esp_netif.h"
 | 
				
			||||||
#include "protocol_examples_common.h"
 | 
					#include "protocol_examples_common.h"
 | 
				
			||||||
#include "esp_tls.h"
 | 
					#include "esp_tls.h"
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
 | 
					#include "esp_crt_bundle.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "esp_http_client.h"
 | 
					#include "esp_http_client.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -366,12 +369,13 @@ static void http_auth_digest(void)
 | 
				
			|||||||
    esp_http_client_cleanup(client);
 | 
					    esp_http_client_cleanup(client);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
static void https_with_url(void)
 | 
					static void https_with_url(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    esp_http_client_config_t config = {
 | 
					    esp_http_client_config_t config = {
 | 
				
			||||||
        .url = "https://www.howsmyssl.com",
 | 
					        .url = "https://www.howsmyssl.com",
 | 
				
			||||||
        .event_handler = _http_event_handler,
 | 
					        .event_handler = _http_event_handler,
 | 
				
			||||||
        .cert_pem = howsmyssl_com_root_cert_pem_start,
 | 
					        .crt_bundle_attach = esp_crt_bundle_attach,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    esp_http_client_handle_t client = esp_http_client_init(&config);
 | 
					    esp_http_client_handle_t client = esp_http_client_init(&config);
 | 
				
			||||||
    esp_err_t err = esp_http_client_perform(client);
 | 
					    esp_err_t err = esp_http_client_perform(client);
 | 
				
			||||||
@@ -385,6 +389,7 @@ static void https_with_url(void)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    esp_http_client_cleanup(client);
 | 
					    esp_http_client_cleanup(client);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#endif // CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void https_with_hostname_path(void)
 | 
					static void https_with_hostname_path(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -637,12 +642,13 @@ static void http_native_request(void)
 | 
				
			|||||||
    esp_http_client_cleanup(client);
 | 
					    esp_http_client_cleanup(client);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
static void http_partial_download(void)
 | 
					static void http_partial_download(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    esp_http_client_config_t config = {
 | 
					    esp_http_client_config_t config = {
 | 
				
			||||||
        .url = "https://dl.espressif.com/dl/esp-idf/ci/esp_http_client_demo.txt",
 | 
					        .url = "https://dl.espressif.com/dl/esp-idf/ci/esp_http_client_demo.txt",
 | 
				
			||||||
        .event_handler = _http_event_handler,
 | 
					        .event_handler = _http_event_handler,
 | 
				
			||||||
        .cert_pem = dl_espressif_com_root_cert_pem_start,
 | 
					        .crt_bundle_attach = esp_crt_bundle_attach,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    esp_http_client_handle_t client = esp_http_client_init(&config);
 | 
					    esp_http_client_handle_t client = esp_http_client_init(&config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -681,6 +687,7 @@ static void http_partial_download(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    esp_http_client_cleanup(client);
 | 
					    esp_http_client_cleanup(client);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#endif // CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void http_test_task(void *pvParameters)
 | 
					static void http_test_task(void *pvParameters)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -693,7 +700,9 @@ static void http_test_task(void *pvParameters)
 | 
				
			|||||||
    http_auth_digest();
 | 
					    http_auth_digest();
 | 
				
			||||||
    http_relative_redirect();
 | 
					    http_relative_redirect();
 | 
				
			||||||
    http_absolute_redirect();
 | 
					    http_absolute_redirect();
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
    https_with_url();
 | 
					    https_with_url();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    https_with_hostname_path();
 | 
					    https_with_hostname_path();
 | 
				
			||||||
    http_redirect_to_https();
 | 
					    http_redirect_to_https();
 | 
				
			||||||
    http_download_chunk();
 | 
					    http_download_chunk();
 | 
				
			||||||
@@ -701,7 +710,9 @@ static void http_test_task(void *pvParameters)
 | 
				
			|||||||
    https_async();
 | 
					    https_async();
 | 
				
			||||||
    https_with_invalid_url();
 | 
					    https_with_invalid_url();
 | 
				
			||||||
    http_native_request();
 | 
					    http_native_request();
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
    http_partial_download();
 | 
					    http_partial_download();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ESP_LOGI(TAG, "Finish http example");
 | 
					    ESP_LOGI(TAG, "Finish http example");
 | 
				
			||||||
    vTaskDelete(NULL);
 | 
					    vTaskDelete(NULL);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,22 +5,13 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * Adapted from the ssl_client1 example in mbedtls.
 | 
					 * Adapted from the ssl_client1 example in mbedtls.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Original Copyright (C) 2006-2016, ARM Limited, All Rights Reserved, Apache 2.0 License.
 | 
					 * SPDX-FileCopyrightText: 2006-2016 ARM Limited, All Rights Reserved
 | 
				
			||||||
 * Additions Copyright (C) Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD, Apache 2.0 License.
 | 
					 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 * SPDX-FileContributor: 2015-2022 Espressif Systems (Shanghai) CO LTD
 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 | 
				
			||||||
 * You may obtain a copy of the License at
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Unless required by applicable law or agreed to in writing, software
 | 
					 | 
				
			||||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					 | 
				
			||||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					 | 
				
			||||||
 * See the License for the specific language governing permissions and
 | 
					 | 
				
			||||||
 * limitations under the License.
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include "freertos/FreeRTOS.h"
 | 
					#include "freertos/FreeRTOS.h"
 | 
				
			||||||
@@ -41,7 +32,9 @@
 | 
				
			|||||||
#include "lwip/dns.h"
 | 
					#include "lwip/dns.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "esp_tls.h"
 | 
					#include "esp_tls.h"
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
#include "esp_crt_bundle.h"
 | 
					#include "esp_crt_bundle.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Constants that aren't configurable in menuconfig */
 | 
					/* Constants that aren't configurable in menuconfig */
 | 
				
			||||||
#define WEB_SERVER "www.howsmyssl.com"
 | 
					#define WEB_SERVER "www.howsmyssl.com"
 | 
				
			||||||
@@ -134,6 +127,7 @@ exit:
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
static void https_get_request_using_crt_bundle(void)
 | 
					static void https_get_request_using_crt_bundle(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ESP_LOGI(TAG, "https_request using crt bundle");
 | 
					    ESP_LOGI(TAG, "https_request using crt bundle");
 | 
				
			||||||
@@ -142,6 +136,7 @@ static void https_get_request_using_crt_bundle(void)
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
    https_get_request(cfg);
 | 
					    https_get_request(cfg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#endif // CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void https_get_request_using_cacert_buf(void)
 | 
					static void https_get_request_using_cacert_buf(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -173,7 +168,9 @@ static void https_request_task(void *pvparameters)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    ESP_LOGI(TAG, "Start https_request example");
 | 
					    ESP_LOGI(TAG, "Start https_request example");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
 | 
				
			||||||
    https_get_request_using_crt_bundle();
 | 
					    https_get_request_using_crt_bundle();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    https_get_request_using_cacert_buf();
 | 
					    https_get_request_using_cacert_buf();
 | 
				
			||||||
    https_get_request_using_global_ca_store();
 | 
					    https_get_request_using_global_ca_store();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user