Skip to content

Commit c87b58b

Browse files
committed
Attach trusted CAs to ssl_client object
Credits @meltdown03 espressif#3646 (comment)
1 parent 6a5b765 commit c87b58b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
103103
}
104104

105105
log_v("Setting up the SSL/TLS structure...");
106-
106+
ret = esp_crt_bundle_attach(&ssl_client->ssl_conf);
107+
108+
if (ret < 0) {
109+
return handle_error(ret);
110+
}
111+
107112
if ((ret = mbedtls_ssl_config_defaults(&ssl_client->ssl_conf,
108113
MBEDTLS_SSL_IS_CLIENT,
109114
MBEDTLS_SSL_TRANSPORT_STREAM,
@@ -155,8 +160,10 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
155160
return handle_error(ret);
156161
}
157162
} else {
158-
mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_NONE);
159-
log_i("WARNING: Use certificates for a more secure communication!");
163+
log_d("Loading trusted CA certs");
164+
mbedtls_x509_crt_init(&ssl_client->ca_cert);
165+
mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED);
166+
mbedtls_ssl_conf_ca_chain(&ssl_client->ssl_conf, &ssl_client->ca_cert, NULL);
160167
}
161168

162169
if (cli_cert != NULL && cli_key != NULL) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mbedtls/entropy.h"
1212
#include "mbedtls/ctr_drbg.h"
1313
#include "mbedtls/error.h"
14+
#include "esp_crt_bundle.h"
1415

1516
typedef struct sslclient_context {
1617
int socket;

0 commit comments

Comments
 (0)