Skip to content
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

Add certificate bundle support #17

Merged
merged 1 commit into from
Oct 16, 2023
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
16 changes: 15 additions & 1 deletion src/Arduino_ESP32_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA()
,_ota_size(0)
,_crc32(0)
,_ca_cert{amazon_root_ca}
,_ca_cert_bundle{nullptr}
{

}
Expand Down Expand Up @@ -85,6 +86,13 @@ void Arduino_ESP32_OTA::setCACert (const char *rootCA)
}
}

void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle)
{
if(bundle != nullptr) {
_ca_cert_bundle = bundle;
}
}

uint8_t Arduino_ESP32_OTA::read_byte_from_network()
{
bool is_http_data_timeout = false;
Expand Down Expand Up @@ -118,7 +126,13 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
port = 80;
} else if (url.protocol_ == "https") {
_client = new WiFiClientSecure();
static_cast<WiFiClientSecure*>(_client)->setCACert(_ca_cert);
if (_ca_cert != nullptr) {
static_cast<WiFiClientSecure*>(_client)->setCACert(_ca_cert);
} else if (_ca_cert_bundle != nullptr) {
static_cast<WiFiClientSecure*>(_client)->setCACertBundle(_ca_cert_bundle);
} else {
DEBUG_VERBOSE("%s: CA not configured for download client");
}
port = 443;
} else {
DEBUG_ERROR("%s: Failed to parse OTA URL %s", __FUNCTION__, ota_url);
Expand Down
2 changes: 2 additions & 0 deletions src/Arduino_ESP32_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Arduino_ESP32_OTA

Arduino_ESP32_OTA::Error begin();
void setCACert (const char *rootCA);
void setCACertBundle(const uint8_t * bundle);
int download(const char * ota_url);
uint8_t read_byte_from_network();
void write_byte_to_flash(uint8_t data);
Expand All @@ -93,6 +94,7 @@ class Arduino_ESP32_OTA
size_t _ota_size;
uint32_t _crc32;
const char * _ca_cert;
const uint8_t * _ca_cert_bundle;
};

#endif /* ARDUINO_ESP32_OTA_H_ */