Skip to content

Commit 4ffb3fb

Browse files
committed
Merge branch 'feat/add_support_for_cert_bundle_for_advanced_ota_example' into 'master'
fix(advanced_ota): Added support for cert bundle in advanced OTA See merge request espressif/esp-idf!39219
2 parents e05390f + 2c55305 commit 4ffb3fb

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

examples/system/ota/advanced_https_ota/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ idf_component_register(SRCS "advanced_https_ota_example.c" "ble_helper/bluedroid
33
INCLUDE_DIRS "." "./ble_helper/include/"
44
PRIV_REQUIRES esp_http_client app_update esp_https_ota
55
nvs_flash esp_netif esp_wifi efuse bt
6-
protocomm
6+
protocomm mbedtls
77
# Embed the server root certificate into the final binary
88
EMBED_TXTFILES ${project_dir}/server_certs/ca_cert.pem)

examples/system/ota/advanced_https_ota/main/Kconfig.projbuild

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@ menu "Example Configuration"
5353
This option allows one to configure the OTA process to resume downloading the OTA image
5454
from where it left off in case of an error or reboot.
5555

56+
config EXAMPLE_USE_CERT_BUNDLE
57+
bool "Enable certificate bundle"
58+
default y
59+
depends on MBEDTLS_CERTIFICATE_BUNDLE
60+
help
61+
Enable trusted root certificate bundle. This approach allows to have
62+
OTA updates functional with any public server without requirement
63+
to explicitly add its server certificate.
64+
5665
endmenu

examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include "nvs_flash.h"
2323
#include "protocol_examples_common.h"
2424

25+
26+
#ifdef CONFIG_EXAMPLE_USE_CERT_BUNDLE
27+
#include "esp_crt_bundle.h"
28+
#endif
29+
2530
#if CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK
2631
#include "esp_efuse.h"
2732
#endif
@@ -221,7 +226,11 @@ void advanced_ota_example_task(void *pvParameter)
221226
esp_err_t ota_finish_err = ESP_OK;
222227
esp_http_client_config_t config = {
223228
.url = CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL,
229+
#ifdef CONFIG_EXAMPLE_USE_CERT_BUNDLE
230+
.crt_bundle_attach = esp_crt_bundle_attach,
231+
#else
224232
.cert_pem = (char *)server_cert_pem_start,
233+
#endif
225234
.timeout_ms = CONFIG_EXAMPLE_OTA_RECV_TIMEOUT,
226235
.keep_alive_enable = true,
227236
#ifdef CONFIG_EXAMPLE_ENABLE_PARTIAL_HTTP_DOWNLOAD

examples/system/ota/advanced_https_ota/sdkconfig.defaults

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
# partition table layout, with a 4MB flash size
33
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
44
CONFIG_PARTITION_TABLE_TWO_OTA_LARGE=y
5+
6+
# Certificate bundle configuration
7+
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y
8+
CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE=y
9+
CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="server_certs/ca_cert.pem"

0 commit comments

Comments
 (0)