Skip to content

Commit bb8937d

Browse files
authored
Merge pull request #254 from pennam/ecc_slot
WiFiSSLClient: add setEccSlot method to configure client private key and certificate
2 parents 00ed928 + 267cae5 commit bb8937d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

+21-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,13 +65,27 @@ 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);
6772
}
6873
}
6974

75+
/* -------------------------------------------------------------------------- */
76+
void WiFiSSLClient::setEccSlot(int ecc508KeySlot, const byte cert[], int certLength) {
77+
/* -------------------------------------------------------------------------- */
78+
getSocket();
79+
string res = "";
80+
if(certLength > 0) {
81+
modem.write_nowait(string(PROMPT(_SETECCSLOT)),res, "%s%d,%d,%d\r\n" , CMD_WRITE(_SETECCSLOT), _sock, ecc508KeySlot, certLength);
82+
modem.passthrough((uint8_t *)cert, certLength);
83+
_ecc_slot = ecc508KeySlot;
84+
_ecc_cert = cert;
85+
_ecc_cert_len = certLength;
86+
}
87+
}
88+
7089
/* -------------------------------------------------------------------------- */
7190
size_t WiFiSSLClient::write(uint8_t b){
7291
/* -------------------------------------------------------------------------- */

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class WiFiSSLClient : public WiFiClient {
3434
virtual int connect(IPAddress ip, uint16_t port);
3535
virtual int connect(const char* host, uint16_t port);
3636
void setCACert(const char* root_ca = NULL, size_t size = 0);
37+
void setEccSlot(int ecc508KeySlot, const byte cert[], int certLength);
3738
virtual size_t write(uint8_t);
3839
virtual size_t write(const uint8_t *buf, size_t size);
3940
virtual int available();
@@ -60,10 +61,14 @@ class WiFiSSLClient : public WiFiClient {
6061

6162
private:
6263
int _sock;
63-
bool _custom_root = false;
6464
void getSocket();
6565
int _read();
6666
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+
6772
};
6873

6974
#endif /* WIFISSLCLIENT_H */

0 commit comments

Comments
 (0)