@@ -46,7 +46,7 @@ void WebSocketsClient::begin(const char * host, uint16_t port, const char * url,
46
46
_host = host;
47
47
_port = port;
48
48
#if defined(HAS_SSL)
49
- _fingerprint = " " ;
49
+ _fingerprint = SSL_FINGERPRINT_NULL ;
50
50
_CA_cert = NULL ;
51
51
#endif
52
52
@@ -97,6 +97,7 @@ void WebSocketsClient::begin(IPAddress host, uint16_t port, const char * url, co
97
97
}
98
98
99
99
#if defined(HAS_SSL)
100
+ #if defined(SSL_AXTLS)
100
101
void WebSocketsClient::beginSSL (const char * host, uint16_t port, const char * url, const char * fingerprint, const char * protocol) {
101
102
begin (host, port, url, protocol);
102
103
_client.isSSL = true ;
@@ -111,10 +112,31 @@ void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String f
111
112
void WebSocketsClient::beginSslWithCA (const char * host, uint16_t port, const char * url, const char * CA_cert, const char * protocol) {
112
113
begin (host, port, url, protocol);
113
114
_client.isSSL = true ;
114
- _fingerprint = " " ;
115
+ _fingerprint = SSL_FINGERPRINT_NULL ;
115
116
_CA_cert = CA_cert;
116
117
}
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
118
140
119
141
void WebSocketsClient::beginSocketIO (const char * host, uint16_t port, const char * url, const char * protocol) {
120
142
begin (host, port, url, protocol);
@@ -130,7 +152,7 @@ void WebSocketsClient::beginSocketIOSSL(const char * host, uint16_t port, const
130
152
begin (host, port, url, protocol);
131
153
_client.isSocketIO = true ;
132
154
_client.isSSL = true ;
133
- _fingerprint = " " ;
155
+ _fingerprint = SSL_FINGERPRINT_NULL ;
134
156
}
135
157
136
158
void WebSocketsClient::beginSocketIOSSL (String host, uint16_t port, String url, String protocol) {
@@ -141,8 +163,12 @@ void WebSocketsClient::beginSocketIOSSLWithCA(const char * host, uint16_t port,
141
163
begin (host, port, url, protocol);
142
164
_client.isSocketIO = true ;
143
165
_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
146
172
}
147
173
#endif
148
174
@@ -175,14 +201,20 @@ void WebSocketsClient::loop(void) {
175
201
DEBUG_WEBSOCKETS (" [WS-Client] setting CA certificate" );
176
202
#if defined(ESP32)
177
203
_client.ssl ->setCACert (_CA_cert);
178
- #elif defined(ESP8266)
204
+ #elif defined(ESP8266) && defined(SSL_AXTLS)
179
205
_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);
180
208
#else
181
209
#error setCACert not implemented
182
210
#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 ();
186
218
#endif
187
219
}
188
220
} else {
@@ -774,14 +806,18 @@ void WebSocketsClient::connectedCb() {
774
806
#endif
775
807
776
808
#if defined(HAS_SSL)
809
+ #if defined(SSL_AXTLS) || defined(ESP32)
777
810
if (_client.isSSL && _fingerprint.length ()) {
778
811
if (!_client.ssl ->verify (_fingerprint.c_str (), _host.c_str ())) {
779
812
DEBUG_WEBSOCKETS (" [WS-Client] certificate mismatch\n " );
780
813
WebSockets::clientDisconnect (&_client, 1000 );
781
814
return ;
782
815
}
816
+ #else
817
+ if (_client.isSSL && _fingerprint) {
818
+ #endif
783
819
} else if (_client.isSSL && !_CA_cert) {
784
- #if defined(wificlientbearssl_h) && !defined(USING_AXTLS) && !defined(wificlientsecure_h )
820
+ #if defined(SSL_BARESSL )
785
821
_client.ssl ->setInsecure ();
786
822
#endif
787
823
}
0 commit comments