Skip to content

Fix build with esp core greater than 3.0.4 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/Arduino_ESP32_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -114,9 +123,17 @@ int Arduino_ESP32_OTA::startDownload(const char * ota_url)
_client = new WiFiClientSecure();
if (_ca_cert != nullptr) {
static_cast<WiFiClientSecure*>(_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<WiFiClientSecure*>(_client)->setCACertBundle(_ca_cert_bundle);
} else {
}
#else
else if (_ca_cert_bundle != nullptr && _ca_cert_bundle_size != 0) {
static_cast<WiFiClientSecure*>(_client)->setCACertBundle(_ca_cert_bundle, _ca_cert_bundle_size);
}
#endif
else {
DEBUG_VERBOSE("%s: CA not configured for download client");
}
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/Arduino_ESP32_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <Arduino_DebugUtils.h>
#include <WiFiClientSecure.h>
#include <WiFi.h>
#include "decompress/utility.h"
#include "decompress/lzss.h"
#include <ArduinoHttpClient.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Loading