Skip to content

Commit a8c2644

Browse files
committed
Add beginSslWithClientKey
1 parent 6eee4c6 commit a8c2644

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/WebSocketsClient.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
132138
void 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,13 @@ 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+
_client.ssl->setCertificate(_client_cert);
269+
_client.ssl->setPrivateKey(_client_key);
270+
DEBUG_WEBSOCKETS("[WS-Client] no client certificate and key set\n");
271+
}
261272
_client.ssl->setCACert(_CA_cert);
262273
#elif defined(ESP8266) && defined(SSL_AXTLS)
263274
_client.ssl->setCACert((const uint8_t *)_CA_cert, strlen(_CA_cert) + 1);
@@ -272,7 +283,7 @@ void WebSocketsClient::loop(void) {
272283
#endif
273284
#if defined(ESP32)
274285
} else if(_CA_bundle) {
275-
DEBUG_WEBSOCKETS("[WS-Client] setting CA bundle");
286+
DEBUG_WEBSOCKETS("[WS-Client] setting CA bundle\n");
276287
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
277288
_client.ssl->setCACertBundle(_CA_bundle, _CA_bundle_size);
278289
#else
@@ -288,7 +299,7 @@ void WebSocketsClient::loop(void) {
288299
}
289300
if(_client_cert && _client_key) {
290301
_client.ssl->setClientRSACert(_client_cert, _client_key);
291-
DEBUG_WEBSOCKETS("[WS-Client] setting client certificate and key");
302+
DEBUG_WEBSOCKETS("[WS-Client] setting client certificate and key\n");
292303
#endif
293304
}
294305
} else {

src/WebSocketsClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class WebSocketsClient : protected WebSockets {
5555
void setSSLClientCertKey(const char * clientCert = NULL, const char * clientPrivateKey = NULL);
5656
#endif
5757
void beginSslWithCA(const char * host, uint16_t port, const char * url = "/", const char * CA_cert = NULL, const char * protocol = "arduino");
58+
void beginSslWithClientKey(const char * host, uint16_t port, const char * url, const char * CA_cert, const char * clientCert, const char * clientPrivateKey, const char * protocol);
5859
#ifdef ESP32
5960
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
6061
void beginSslWithBundle(const char * host, uint16_t port, const char * url = "/", const uint8_t * CA_bundle = NULL, size_t CA_bundle_size = 0, const char * protocol = "arduino");
@@ -122,6 +123,8 @@ class WebSocketsClient : protected WebSockets {
122123
String _fingerprint;
123124
const char * _CA_cert;
124125
const uint8_t * _CA_bundle;
126+
const char * _client_cert;
127+
const char * _client_key;
125128
#if defined(ESP32)
126129
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
127130
size_t _CA_bundle_size;

0 commit comments

Comments
 (0)