Skip to content

Commit 648be7d

Browse files
committed
fix(ssl): Make the bundle callback per context
1 parent ef94006 commit 648be7d

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Diff for: libraries/NetworkClientSecure/src/NetworkClientSecure.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ void NetworkClientSecure::setCACert(const char *rootCA) {
317317
void NetworkClientSecure::setCACertBundle(const uint8_t *bundle) {
318318
if (bundle != NULL) {
319319
esp_crt_bundle_set(bundle, sizeof(bundle));
320-
attach_ssl_certificate_bundle(true);
320+
attach_ssl_certificate_bundle(sslclient.get(), true);
321321
_use_ca_bundle = true;
322322
} else {
323323
esp_crt_bundle_detach(NULL);
324-
attach_ssl_certificate_bundle(false);
324+
attach_ssl_certificate_bundle(sslclient.get(), false);
325325
_use_ca_bundle = false;
326326
}
327327
}

Diff for: libraries/NetworkClientSecure/src/ssl_client.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626

2727
const char *pers = "esp32-tls";
2828

29-
typedef esp_err_t (*crt_bundle_attach_cb)(void *conf);
30-
static crt_bundle_attach_cb _bundle_attach_cb = NULL;
31-
3229
static int _handle_error(int err, const char *function, int line) {
3330
if (err == -30848) {
3431
return err;
@@ -54,11 +51,11 @@ void ssl_init(sslclient_context *ssl_client) {
5451
ssl_client->peek_buf = -1;
5552
}
5653

57-
void attach_ssl_certificate_bundle(bool att) {
54+
void attach_ssl_certificate_bundle(sslclient_context *ssl_client, bool att) {
5855
if (att) {
59-
_bundle_attach_cb = &esp_crt_bundle_attach;
56+
ssl_client->bundle_attach_cb = &esp_crt_bundle_attach;
6057
} else {
61-
_bundle_attach_cb = NULL;
58+
ssl_client->bundle_attach_cb = NULL;
6259
}
6360
}
6461

@@ -206,15 +203,14 @@ int start_ssl_client(
206203
return handle_error(ret);
207204
}
208205
} else if (useRootCABundle) {
209-
if (_bundle_attach_cb != NULL) {
206+
if (ssl_client->bundle_attach_cb != NULL) {
210207
log_v("Attaching root CA cert bundle");
211-
ret = _bundle_attach_cb(&ssl_client->ssl_conf);
212-
208+
ret = ssl_client->bundle_attach_cb(&ssl_client->ssl_conf);
213209
if (ret < 0) {
214210
return handle_error(ret);
215211
}
216212
} else {
217-
log_e("useRootCABundle is set, but attach_ssl_certificate_bundle(true); was not called!");
213+
log_e("useRootCABundle is set, but attach_ssl_certificate_bundle(ssl, true); was not called!");
218214
}
219215
} else if (pskIdent != NULL && psKey != NULL) {
220216
log_v("Setting up PSK");

Diff for: libraries/NetworkClientSecure/src/ssl_client.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "mbedtls/ctr_drbg.h"
1313
#include "mbedtls/error.h"
1414

15+
typedef esp_err_t (*crt_bundle_attach_cb)(void *conf);
16+
1517
typedef struct sslclient_context {
1618
int socket;
1719
mbedtls_ssl_context ssl_ctx;
@@ -24,6 +26,8 @@ typedef struct sslclient_context {
2426
mbedtls_x509_crt client_cert;
2527
mbedtls_pk_context client_key;
2628

29+
crt_bundle_attach_cb bundle_attach_cb;
30+
2731
unsigned long socket_timeout;
2832
unsigned long handshake_timeout;
2933

@@ -37,7 +41,7 @@ int start_ssl_client(
3741
sslclient_context *ssl_client, const IPAddress &ip, uint32_t port, const char *hostname, int timeout, const char *rootCABuff, bool useRootCABundle,
3842
const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos
3943
);
40-
void attach_ssl_certificate_bundle(bool att);
44+
void attach_ssl_certificate_bundle(sslclient_context *ssl_client, bool att);
4145
int ssl_starttls_handshake(sslclient_context *ssl_client);
4246
void stop_ssl_socket(sslclient_context *ssl_client);
4347
int data_to_read(sslclient_context *ssl_client);

0 commit comments

Comments
 (0)