@@ -46,7 +46,7 @@ void WebSocketsClient::begin(const char * host, uint16_t port, const char * url,
4646 _host = host;
4747 _port = port;
4848#if defined(HAS_SSL)
49- _fingerprint = " " ;
49+ _fingerprint = SSL_FINGERPRINT_NULL ;
5050 _CA_cert = NULL ;
5151#endif
5252
@@ -97,6 +97,7 @@ void WebSocketsClient::begin(IPAddress host, uint16_t port, const char * url, co
9797}
9898
9999#if defined(HAS_SSL)
100+ #if defined(SSL_AXTLS)
100101void WebSocketsClient::beginSSL (const char * host, uint16_t port, const char * url, const char * fingerprint, const char * protocol) {
101102 begin (host, port, url, protocol);
102103 _client.isSSL = true ;
@@ -111,10 +112,31 @@ void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String f
111112void WebSocketsClient::beginSslWithCA (const char * host, uint16_t port, const char * url, const char * CA_cert, const char * protocol) {
112113 begin (host, port, url, protocol);
113114 _client.isSSL = true ;
114- _fingerprint = " " ;
115+ _fingerprint = SSL_FINGERPRINT_NULL ;
115116 _CA_cert = CA_cert;
116117}
117- #endif
118+ #else
119+ void WebSocketsClient::beginSSL (const char * host, uint16_t port, const char * url, const uint8_t * fingerprint, const char * protocol) {
120+ begin (host, port, url, protocol);
121+ _client.isSSL = true ;
122+ _fingerprint = fingerprint;
123+ _CA_cert = NULL ;
124+ }
125+ void WebSocketsClient::beginSslWithCA (const char * host, uint16_t port, const char * url, const char * CA_cert, const char * protocol) {
126+ begin (host, port, url, protocol);
127+ _client.isSSL = true ;
128+ _fingerprint = SSL_FINGERPRINT_NULL;
129+ _CA_cert = new BearSSL::X509List (CA_cert);
130+ }
131+
132+ void WebSocketsClient::beginSslWithCA (const char * host, uint16_t port, const char * url, BearSSL::X509List * CA_cert, const char * protocol) {
133+ begin (host, port, url, protocol);
134+ _client.isSSL = true ;
135+ _fingerprint = SSL_FINGERPRINT_NULL;
136+ _CA_cert = CA_cert;
137+ }
138+ #endif // SSL_AXTLS
139+ #endif // HAS_SSL
118140
119141void WebSocketsClient::beginSocketIO (const char * host, uint16_t port, const char * url, const char * protocol) {
120142 begin (host, port, url, protocol);
@@ -130,7 +152,7 @@ void WebSocketsClient::beginSocketIOSSL(const char * host, uint16_t port, const
130152 begin (host, port, url, protocol);
131153 _client.isSocketIO = true ;
132154 _client.isSSL = true ;
133- _fingerprint = " " ;
155+ _fingerprint = SSL_FINGERPRINT_NULL ;
134156}
135157
136158void WebSocketsClient::beginSocketIOSSL (String host, uint16_t port, String url, String protocol) {
@@ -141,8 +163,12 @@ void WebSocketsClient::beginSocketIOSSLWithCA(const char * host, uint16_t port,
141163 begin (host, port, url, protocol);
142164 _client.isSocketIO = true ;
143165 _client.isSSL = true ;
144- _fingerprint = " " ;
145- _CA_cert = CA_cert;
166+ _fingerprint = SSL_FINGERPRINT_NULL;
167+ #if defined(SSL_AXTLS)
168+ _CA_cert = CA_cert;
169+ #else
170+ _CA_cert = new BearSSL::X509List (CA_cert);
171+ #endif
146172}
147173#endif
148174
@@ -175,14 +201,20 @@ void WebSocketsClient::loop(void) {
175201 DEBUG_WEBSOCKETS (" [WS-Client] setting CA certificate" );
176202#if defined(ESP32)
177203 _client.ssl ->setCACert (_CA_cert);
178- #elif defined(ESP8266)
204+ #elif defined(ESP8266) && defined(SSL_AXTLS)
179205 _client.ssl ->setCACert ((const uint8_t *)_CA_cert, strlen (_CA_cert) + 1 );
206+ #elif defined(ESP8266) && defined(SSL_BARESSL)
207+ _client.ssl ->setTrustAnchors (_CA_cert);
180208#else
181209#error setCACert not implemented
182210#endif
183- } else if (_fingerprint.length ()) {
184- #if defined(wificlientbearssl_h) && !defined(USING_AXTLS) && !defined(wificlientsecure_h)
185- _client.ssl ->setFingerprint (_fingerprint.c_str ());
211+ #if defined(SSL_BARESSL)
212+ } else if (_fingerprint) {
213+ _client.ssl ->setFingerprint (_fingerprint);
214+ #endif
215+ } else {
216+ #if defined(SSL_BARESSL)
217+ _client.ssl ->setInsecure ();
186218#endif
187219 }
188220 } else {
@@ -774,14 +806,18 @@ void WebSocketsClient::connectedCb() {
774806#endif
775807
776808#if defined(HAS_SSL)
809+ #if defined(SSL_AXTLS) || defined(ESP32)
777810 if (_client.isSSL && _fingerprint.length ()) {
778811 if (!_client.ssl ->verify (_fingerprint.c_str (), _host.c_str ())) {
779812 DEBUG_WEBSOCKETS (" [WS-Client] certificate mismatch\n " );
780813 WebSockets::clientDisconnect (&_client, 1000 );
781814 return ;
782815 }
816+ #else
817+ if (_client.isSSL && _fingerprint) {
818+ #endif
783819 } else if (_client.isSSL && !_CA_cert) {
784- #if defined(wificlientbearssl_h) && !defined(USING_AXTLS) && !defined(wificlientsecure_h )
820+ #if defined(SSL_BARESSL )
785821 _client.ssl ->setInsecure ();
786822#endif
787823 }
0 commit comments