From 79fd218dc99898be26cb21c1ee231ea16568be68 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 25 Nov 2024 16:14:16 +0100 Subject: [PATCH] Fix build with esp core greater than 3.0.4 --- src/Arduino_ESP32_OTA.cpp | 21 +++++++++++++++++++-- src/Arduino_ESP32_OTA.h | 5 ++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index 39dd327..c67a9f9 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -34,6 +34,7 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA() , _http_client(nullptr) ,_ca_cert{amazon_root_ca} ,_ca_cert_bundle{nullptr} +,_ca_cert_bundle_size(0) ,_magic(0) { @@ -83,6 +84,14 @@ void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle) } } +void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle, size_t size) +{ + if(bundle != nullptr && size != 0) { + _ca_cert_bundle = bundle; + _ca_cert_bundle_size = size; + } +} + void Arduino_ESP32_OTA::setMagic(uint32_t magic) { _magic = magic; @@ -114,9 +123,17 @@ int Arduino_ESP32_OTA::startDownload(const char * ota_url) _client = new WiFiClientSecure(); if (_ca_cert != nullptr) { static_cast(_client)->setCACert(_ca_cert); - } else if (_ca_cert_bundle != nullptr) { + } +#if (ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3, 0, 4)) + else if (_ca_cert_bundle != nullptr) { static_cast(_client)->setCACertBundle(_ca_cert_bundle); - } else { + } +#else + else if (_ca_cert_bundle != nullptr && _ca_cert_bundle_size != 0) { + static_cast(_client)->setCACertBundle(_ca_cert_bundle, _ca_cert_bundle_size); + } +#endif + else { DEBUG_VERBOSE("%s: CA not configured for download client"); } } else { diff --git a/src/Arduino_ESP32_OTA.h b/src/Arduino_ESP32_OTA.h index f82c6e1..f518a58 100644 --- a/src/Arduino_ESP32_OTA.h +++ b/src/Arduino_ESP32_OTA.h @@ -24,6 +24,7 @@ #include #include +#include #include "decompress/utility.h" #include "decompress/lzss.h" #include @@ -87,7 +88,8 @@ class Arduino_ESP32_OTA Arduino_ESP32_OTA::Error begin(uint32_t magic = ARDUINO_ESP32_OTA_MAGIC); void setMagic(uint32_t magic); void setCACert(const char *rootCA); - void setCACertBundle(const uint8_t * bundle); + void setCACertBundle(const uint8_t * bundle) __attribute__((deprecated)); + void setCACertBundle (const uint8_t * bundle, size_t size); // blocking version for the download // returns the size of the downloaded binary @@ -151,6 +153,7 @@ class Arduino_ESP32_OTA HttpClient* _http_client; const char * _ca_cert; const uint8_t * _ca_cert_bundle; + size_t _ca_cert_bundle_size; uint32_t _magic; void clean();