Skip to content

Commit 267cae5

Browse files
committed
WiFiSSLClient: configure cusutom root_ca or client credentials on connect
1 parent 9efbd3c commit 267cae5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: libraries/WiFiS3/src/WiFiSSLClient.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ int WiFiSSLClient::connect(IPAddress ip, uint16_t port) {
3636
int WiFiSSLClient::connect(const char* host, uint16_t port) {
3737
/* -------------------------------------------------------------------------- */
3838
getSocket();
39-
if (!_custom_root) {
39+
if (_root_ca != nullptr) {
40+
setCACert(_root_ca);
41+
} else {
4042
setCACert();
4143
}
44+
if ((_ecc_slot != -1) && (_ecc_cert != nullptr) && (_ecc_cert_len != 0)) {
45+
setEccSlot(_ecc_slot, _ecc_cert, _ecc_cert_len);
46+
}
4247
string res = "";
4348
if (_connectionTimeout) {
4449
if(modem.write(string(PROMPT(_SSLCLIENTCONNECT)),res, "%s%d,%s,%d,%d\r\n" , CMD_WRITE(_SSLCLIENTCONNECT), _sock, host,port, _connectionTimeout)) {
@@ -60,7 +65,7 @@ void WiFiSSLClient::setCACert(const char* root_ca, size_t size) {
6065
if(size > 0) {
6166
modem.write_nowait(string(PROMPT(_SETCAROOT)),res, "%s%d,%d\r\n" , CMD_WRITE(_SETCAROOT), _sock, size);
6267
if(modem.passthrough((uint8_t *)root_ca, size)) {
63-
_custom_root = true;
68+
_root_ca = root_ca;
6469
}
6570
} else {
6671
modem.write(string(PROMPT(_SETCAROOT)),res, "%s%d\r\n" , CMD_WRITE(_SETCAROOT), _sock);
@@ -75,6 +80,9 @@ void WiFiSSLClient::setEccSlot(int ecc508KeySlot, const byte cert[], int certLen
7580
if(certLength > 0) {
7681
modem.write_nowait(string(PROMPT(_SETECCSLOT)),res, "%s%d,%d,%d\r\n" , CMD_WRITE(_SETECCSLOT), _sock, ecc508KeySlot, certLength);
7782
modem.passthrough((uint8_t *)cert, certLength);
83+
_ecc_slot = ecc508KeySlot;
84+
_ecc_cert = cert;
85+
_ecc_cert_len = certLength;
7886
}
7987
}
8088

Diff for: libraries/WiFiS3/src/WiFiSSLClient.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ class WiFiSSLClient : public WiFiClient {
6161

6262
private:
6363
int _sock;
64-
bool _custom_root = false;
6564
void getSocket();
6665
int _read();
6766
void read_if_needed(size_t s);
67+
const char* _root_ca = nullptr;
68+
int _ecc_slot = -1;
69+
const byte* _ecc_cert = nullptr;
70+
int _ecc_cert_len = 0;
71+
6872
};
6973

7074
#endif /* WIFISSLCLIENT_H */

0 commit comments

Comments
 (0)