A library to add a secure connection to a Client object
The SSLClientESP32 library allows establishing a secure connection using SSL/TLS. Has been designed
for ESP32. Allows you to give a secure connection to any object derived from Client, such as
WiFiClient and TinyGsmClient. Offers to be able to attach a Certificate Bundle to the client, reducing the
number of certificates entered manually into the firmware and increasing the possibility of
establish a secure connection to most servers.
Here are some basic examples...
; Most recent changeslib_deps =
https://github.com/alkonosst/SSLClientESP32.git
; Release vx.y.zlib_deps =
https://github.com/alkonosst/SSLClientESP32.git#v2.0.0#include<WiFi.h>
#include"SSLClientESP32.h"// Create clients
WiFiClient base_client;
SSLClientESP32 ssl_client(&base_client);
// Root Certificate ISRG Root X1constchar* isrg_root_ca = "-----BEGIN CERTIFICATE-----\n""...\n""-----END CERTIFICATE-----\n";
voidsetup() {
// Attach certificate
ssl_client.setCACert(isrg_root_ca);
// Enable WiFi
WiFi.begin(WIFI_SSID, WIFI_PASS);
}
voidfoo() {
if (!ssl_client.connect(SERVER, 443)) {
// Connection failed
} else {
// Connection successful
}
}platformio.ini
; File must exist in ./data/crt/; You can use the file in /examples/https_wifi_and_sim7600_certbundle/data/crt/x509_crt_bundle.bin of this repoboard_build.embed_files = data/crt/x509_crt_bundle.binmain.cpp
#include<WiFi.h>
#include"TinyGSM.h"
#include"SSLClientESP32.h"// Modem SIM7600G-H
TinyGsm modem(Serial1);
// Create clients
TinyGsmClient base_client(modem);
SSLClientESP32 ssl_client(&base_client);
// Declaration of binary fileexternconstuint8_t ca_cert_bundle_start[] asm("_binary_data_crt_x509_crt_bundle_bin_start");
externconstuint8_t ca_cert_bundle_end[] asm("_binary_data_crt_x509_crt_bundle_bin_end");
voidsetup() {
// Attach certificate bundle
ssl_client.setCACertBundle(ca_cert_bundle_start);
// Enable and connect modem...
}
voidfoo() {
if (!ssl_client.connect(SERVER, 443)) {
// Connection failed
} else {
// Connection successful
}
}#include<WiFi.h>
#include"TinyGSM.h"
#include"SSLClientESP32.h"// Modem SIM7600G-H
TinyGsm modem(Serial1);
// Create clients
WiFiClient base_client_1, base_client_2;
TinyGsmClient base_client_3(modem);
SSLClientESP32 ssl_client(&base_client_1);
voidsetup() {
// Attach certificate...// Enable WiFi...// Enable and connect modem...
}
voidfoo(uint8_t client) {
switch(client) {
case1: ssl_client.setClient(&base_client_1); break;
case2: ssl_client.setClient(&base_client_2); break;
case3: ssl_client.setClient(&base_client_3); break;
}
}Huge thanks to govorox to provide the base code of this library 🙌
