From 148b74c1806cca671659dced901a227beec5202d Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 6 Nov 2024 09:18:31 +0100 Subject: [PATCH] WiFiSSLSE050Client: fix sni setting --- libraries/SE05X/src/WiFiSSLSE050Client.h | 4 ++++ libraries/SocketWrapper/src/MbedSSLClient.cpp | 6 +++++- libraries/SocketWrapper/src/MbedSSLClient.h | 7 +++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libraries/SE05X/src/WiFiSSLSE050Client.h b/libraries/SE05X/src/WiFiSSLSE050Client.h index 255ff2f47..6d3409652 100644 --- a/libraries/SE05X/src/WiFiSSLSE050Client.h +++ b/libraries/SE05X/src/WiFiSSLSE050Client.h @@ -48,6 +48,10 @@ class MbedSSLSE050Client : public arduino::MbedSSLClient { return 0; } + if(_hostname && !_disableSNI) { + ((TLSSocket*)sock)->set_hostname(_hostname); + } + if( NSAPI_ERROR_OK != ((TLSSocket*)sock)->append_root_ca_cert(_ca_cert_custom)) { return 0; } diff --git a/libraries/SocketWrapper/src/MbedSSLClient.cpp b/libraries/SocketWrapper/src/MbedSSLClient.cpp index e0aa1d2dd..ce4cc9fca 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.cpp +++ b/libraries/SocketWrapper/src/MbedSSLClient.cpp @@ -1,5 +1,9 @@ #include "MbedSSLClient.h" -arduino::MbedSSLClient::MbedSSLClient(): _disableSNI{false} { +arduino::MbedSSLClient::MbedSSLClient() + : _ca_cert_custom(nullptr), + _hostname(nullptr), + _disableSNI(false) { + onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA)); }; diff --git a/libraries/SocketWrapper/src/MbedSSLClient.h b/libraries/SocketWrapper/src/MbedSSLClient.h index 67c496f5c..d4c48fc82 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.h +++ b/libraries/SocketWrapper/src/MbedSSLClient.h @@ -53,8 +53,9 @@ class MbedSSLClient : public arduino::MbedClient { } protected: - const char* _ca_cert_custom = NULL; - const char* _hostname = NULL; + const char* _ca_cert_custom; + const char* _hostname; + bool _disableSNI; private: int setRootCA() { @@ -90,8 +91,6 @@ class MbedSSLClient : public arduino::MbedClient { } return err; } - - bool _disableSNI; }; }