@@ -128,6 +128,12 @@ void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const ch
128128 _CA_bundle = NULL ;
129129}
130130
131+ void WebSocketsClient::beginSslWithClientKey (const char * host, uint16_t port, const char * url, const char * CA_cert, const char * clientCert, const char * clientPrivateKey, const char * protocol) {
132+ _client_cert = clientCert;
133+ _client_key = clientPrivateKey;
134+ beginSslWithCA (host, port, url, CA_cert, protocol);
135+ }
136+
131137#if defined(ESP32) && ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
132138void WebSocketsClient::beginSslWithBundle (const char * host, uint16_t port, const char * url, const uint8_t * CA_bundle, size_t CA_bundle_size, const char * protocol) {
133139 begin (host, port, url, protocol);
@@ -256,8 +262,15 @@ void WebSocketsClient::loop(void) {
256262 _client.ssl = new WEBSOCKETS_NETWORK_SSL_CLASS ();
257263 _client.tcp = _client.ssl ;
258264 if (_CA_cert) {
259- DEBUG_WEBSOCKETS (" [WS-Client] setting CA certificate" );
265+ DEBUG_WEBSOCKETS (" [WS-Client] setting CA certificate\n " );
260266#if defined(ESP32)
267+ if (_client_cert && _client_key) {
268+ DEBUG_WEBSOCKETS (" [WS-Client] setting client certificate and private key\n " );
269+ _client.ssl ->setCertificate (_client_cert);
270+ _client.ssl ->setPrivateKey (_client_key);
271+ } else {
272+ DEBUG_WEBSOCKETS (" [WS-Client] no client certificate and/or private key set\n " );
273+ }
261274 _client.ssl ->setCACert (_CA_cert);
262275#elif defined(ESP8266) && defined(SSL_AXTLS)
263276 _client.ssl ->setCACert ((const uint8_t *)_CA_cert, strlen (_CA_cert) + 1 );
@@ -272,7 +285,7 @@ void WebSocketsClient::loop(void) {
272285#endif
273286#if defined(ESP32)
274287 } else if (_CA_bundle) {
275- DEBUG_WEBSOCKETS (" [WS-Client] setting CA bundle" );
288+ DEBUG_WEBSOCKETS (" [WS-Client] setting CA bundle\n " );
276289#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
277290 _client.ssl ->setCACertBundle (_CA_bundle, _CA_bundle_size);
278291#else
@@ -287,8 +300,10 @@ void WebSocketsClient::loop(void) {
287300 _client.ssl ->setInsecure ();
288301 }
289302 if (_client_cert && _client_key) {
303+ DEBUG_WEBSOCKETS (" [WS-Client] setting client certificate and private key\n " );
290304 _client.ssl ->setClientRSACert (_client_cert, _client_key);
291- DEBUG_WEBSOCKETS (" [WS-Client] setting client certificate and key" );
305+ } else {
306+ DEBUG_WEBSOCKETS (" [WS-Client] no client certificate and/or private key set\n " );
292307#endif
293308 }
294309 } else {
0 commit comments