@@ -212,16 +212,14 @@ class URLStreamESP32 : public AbstractURLStream {
212212 http_config.buffer_size = buffer_size;
213213 http_config.timeout_ms = _timeout;
214214 http_config.user_data = this ;
215- // for SSL
215+ // for SSL certificate
216216 if (pem_cert != nullptr ) {
217217 http_config.cert_pem = (const char *)pem_cert;
218218 http_config.cert_len = pem_cert_len;
219- } else {
220- #if defined(ARDUINO) && ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 3, 7) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0)
221- http_config.crt_bundle_attach = arduino_esp_crt_bundle_attach;
222- #else
223- http_config.crt_bundle_attach = esp_crt_bundle_attach;
224- #endif
219+ }
220+ // for SSL (use of a bundle for certificate verification)
221+ if (crt_bundle_attach != nullptr ) {
222+ http_config.crt_bundle_attach = crt_bundle_attach;
225223 }
226224
227225 switch (action) {
@@ -324,11 +322,19 @@ class URLStreamESP32 : public AbstractURLStream {
324322 setCACert ((const uint8_t *)cert, len + 1 );
325323 }
326324
325+ // / Attach and enable use of a bundle for certificate verification e.g.
326+ // / esp_crt_bundle_attach(void *conf)
327+ void setCACert (esp_err_t (*cb)(void *conf)){
328+ crt_bundle_attach = cb;
329+ }
330+
327331 // / Defines the read buffer size
328- void setReadBufferSize (int size) { buffer_size = size; }
332+ void setReadBufferSize (int size) {
333+ buffer_size = size; }
329334
330335 // / Used for request and reply header parameters
331- HttpRequest& httpRequest () override { return request; }
336+ HttpRequest& httpRequest () override {
337+ return request; }
332338
333339 // / Does nothing
334340 void setClient (Client& client) override {}
@@ -343,6 +349,8 @@ class URLStreamESP32 : public AbstractURLStream {
343349 int buffer_size = DEFAULT_BUFFER_SIZE;
344350 const uint8_t * pem_cert = nullptr ;
345351 int pem_cert_len = 0 ;
352+ esp_err_t (*crt_bundle_attach)(void *conf) = nullptr ;
353+
346354
347355 // / Define the Root PEM Certificate for SSL: the last byte must be null, the
348356 // / len is including the ending null
0 commit comments