@@ -212,16 +212,14 @@ class URLStreamESP32 : public AbstractURLStream {
212
212
http_config.buffer_size = buffer_size;
213
213
http_config.timeout_ms = _timeout;
214
214
http_config.user_data = this ;
215
- // for SSL
215
+ // for SSL certificate
216
216
if (pem_cert != nullptr ) {
217
217
http_config.cert_pem = (const char *)pem_cert;
218
218
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;
225
223
}
226
224
227
225
switch (action) {
@@ -324,11 +322,19 @@ class URLStreamESP32 : public AbstractURLStream {
324
322
setCACert ((const uint8_t *)cert, len + 1 );
325
323
}
326
324
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
+
327
331
// / Defines the read buffer size
328
- void setReadBufferSize (int size) { buffer_size = size; }
332
+ void setReadBufferSize (int size) {
333
+ buffer_size = size; }
329
334
330
335
// / Used for request and reply header parameters
331
- HttpRequest& httpRequest () override { return request; }
336
+ HttpRequest& httpRequest () override {
337
+ return request; }
332
338
333
339
// / Does nothing
334
340
void setClient (Client& client) override {}
@@ -343,6 +349,8 @@ class URLStreamESP32 : public AbstractURLStream {
343
349
int buffer_size = DEFAULT_BUFFER_SIZE;
344
350
const uint8_t * pem_cert = nullptr ;
345
351
int pem_cert_len = 0 ;
352
+ esp_err_t (*crt_bundle_attach)(void *conf) = nullptr ;
353
+
346
354
347
355
// / Define the Root PEM Certificate for SSL: the last byte must be null, the
348
356
// / len is including the ending null
0 commit comments