@@ -62,6 +62,18 @@ int WiFiSSLClient::connect(const char* host, uint16_t port) {
6262 if (!modem.passthrough ((uint8_t *)_ecc_cert, _ecc_cert_len)) {
6363 return 0 ;
6464 }
65+ } else if (_client_cert != nullptr && _private_key != nullptr ) { // TODO make sure if set certificate is called to not use the above code
66+ size_t size = strlen (_client_cert);
67+ modem.write_nowait (string (PROMPT (_SSLCLIENTSETCERT)),res, " %s%d,%d\r\n " , CMD_WRITE (_SSLCLIENTSETCERT), _sock, size);
68+ if (!modem.passthrough ((uint8_t *)_client_cert, size)) {
69+ return 0 ;
70+ }
71+
72+ size = strlen (_private_key);
73+ modem.write_nowait (string (PROMPT (_SSLCLIENTSETPKEY)),res, " %s%d,%d\r\n " , CMD_WRITE (_SSLCLIENTSETPKEY), _sock, size);
74+ if (!modem.passthrough ((uint8_t *)_private_key, size)) {
75+ return 0 ;
76+ }
6577 }
6678
6779 if (_connectionTimeout) {
@@ -88,6 +100,9 @@ void WiFiSSLClient::setEccSlot(int ecc508KeySlot, const byte cert[], int certLen
88100 _ecc_slot = ecc508KeySlot;
89101 _ecc_cert = cert;
90102 _ecc_cert_len = certLength;
103+
104+ _client_cert = nullptr ;
105+ _private_key = nullptr ;
91106}
92107
93108/* -------------------------------------------------------------------------- */
@@ -283,3 +298,21 @@ uint16_t WiFiSSLClient::remotePort(){
283298 }
284299 return rv;
285300}
301+
302+ /* -------------------------------------------------------------------------- */
303+ void WiFiSSLClient::setCertificate (const char * clientCert){
304+ /* -------------------------------------------------------------------------- */
305+ _client_cert = clientCert;
306+ _ecc_slot = -1 ;
307+ _ecc_cert = nullptr ;
308+ _ecc_cert_len = 0 ;
309+ }
310+
311+ /* -------------------------------------------------------------------------- */
312+ void WiFiSSLClient::setPrivateKey (const char * privateKey){
313+ /* -------------------------------------------------------------------------- */
314+ _private_key = privateKey;
315+ _ecc_slot = -1 ;
316+ _ecc_cert = nullptr ;
317+ _ecc_cert_len = 0 ;
318+ }
0 commit comments