@@ -67,7 +67,7 @@ extern "C" {
67
67
68
68
namespace BearSSL {
69
69
70
- void WiFiClientSecure ::_clear () {
70
+ void WiFiClientSecureCtx ::_clear () {
71
71
// TLS handshake may take more than the 5 second default timeout
72
72
_timeout = 15000 ;
73
73
@@ -91,7 +91,7 @@ void WiFiClientSecure::_clear() {
91
91
_cipher_cnt = 0 ;
92
92
}
93
93
94
- void WiFiClientSecure ::_clearAuthenticationSettings () {
94
+ void WiFiClientSecureCtx ::_clearAuthenticationSettings () {
95
95
_use_insecure = false ;
96
96
_use_fingerprint = false ;
97
97
_use_self_signed = false ;
@@ -100,20 +100,15 @@ void WiFiClientSecure::_clearAuthenticationSettings() {
100
100
}
101
101
102
102
103
- WiFiClientSecure::WiFiClientSecure () : WiFiClient() {
103
+ WiFiClientSecureCtx::WiFiClientSecureCtx () : WiFiClient() {
104
104
_clear ();
105
105
_clearAuthenticationSettings ();
106
106
_certStore = nullptr ; // Don't want to remove cert store on a clear, should be long lived
107
107
_sk = nullptr ;
108
108
stack_thunk_add_ref ();
109
109
}
110
110
111
- WiFiClientSecure::WiFiClientSecure (const WiFiClientSecure &rhs) : WiFiClient(rhs) {
112
- *this = rhs;
113
- stack_thunk_add_ref ();
114
- }
115
-
116
- WiFiClientSecure::~WiFiClientSecure () {
111
+ WiFiClientSecureCtx::~WiFiClientSecureCtx () {
117
112
if (_client) {
118
113
_client->unref ();
119
114
_client = nullptr ;
@@ -123,7 +118,7 @@ WiFiClientSecure::~WiFiClientSecure() {
123
118
stack_thunk_del_ref ();
124
119
}
125
120
126
- WiFiClientSecure::WiFiClientSecure (ClientContext* client,
121
+ WiFiClientSecureCtx::WiFiClientSecureCtx (ClientContext* client,
127
122
const X509List *chain, const PrivateKey *sk,
128
123
int iobuf_in_size, int iobuf_out_size, const X509List *client_CA_ta) {
129
124
_clear ();
@@ -140,7 +135,7 @@ WiFiClientSecure::WiFiClientSecure(ClientContext* client,
140
135
}
141
136
}
142
137
143
- WiFiClientSecure::WiFiClientSecure (ClientContext *client,
138
+ WiFiClientSecureCtx::WiFiClientSecureCtx (ClientContext *client,
144
139
const X509List *chain,
145
140
unsigned cert_issuer_key_type, const PrivateKey *sk,
146
141
int iobuf_in_size, int iobuf_out_size, const X509List *client_CA_ta) {
@@ -158,20 +153,20 @@ WiFiClientSecure::WiFiClientSecure(ClientContext *client,
158
153
}
159
154
}
160
155
161
- void WiFiClientSecure ::setClientRSACert (const X509List *chain, const PrivateKey *sk) {
156
+ void WiFiClientSecureCtx ::setClientRSACert (const X509List *chain, const PrivateKey *sk) {
162
157
_chain = chain;
163
158
_sk = sk;
164
159
}
165
160
166
- void WiFiClientSecure ::setClientECCert (const X509List *chain,
161
+ void WiFiClientSecureCtx ::setClientECCert (const X509List *chain,
167
162
const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type) {
168
163
_chain = chain;
169
164
_sk = sk;
170
165
_allowed_usages = allowed_usages;
171
166
_cert_issuer_key_type = cert_issuer_key_type;
172
167
}
173
168
174
- void WiFiClientSecure ::setBufferSizes (int recv, int xmit) {
169
+ void WiFiClientSecureCtx ::setBufferSizes (int recv, int xmit) {
175
170
// Following constants taken from bearssl/src/ssl/ssl_engine.c (not exported unfortunately)
176
171
const int MAX_OUT_OVERHEAD = 85 ;
177
172
const int MAX_IN_OVERHEAD = 325 ;
@@ -187,7 +182,7 @@ void WiFiClientSecure::setBufferSizes(int recv, int xmit) {
187
182
_iobuf_out_size = xmit;
188
183
}
189
184
190
- bool WiFiClientSecure ::stop (unsigned int maxWaitMs) {
185
+ bool WiFiClientSecureCtx ::stop (unsigned int maxWaitMs) {
191
186
bool ret = WiFiClient::stop (maxWaitMs); // calls our virtual flush()
192
187
// Only if we've already connected, store session params and clear the connection options
193
188
if (_handshake_done) {
@@ -199,19 +194,19 @@ bool WiFiClientSecure::stop(unsigned int maxWaitMs) {
199
194
return ret;
200
195
}
201
196
202
- bool WiFiClientSecure ::flush (unsigned int maxWaitMs) {
197
+ bool WiFiClientSecureCtx ::flush (unsigned int maxWaitMs) {
203
198
(void ) _run_until (BR_SSL_SENDAPP);
204
199
return WiFiClient::flush (maxWaitMs);
205
200
}
206
201
207
- int WiFiClientSecure ::connect (IPAddress ip, uint16_t port) {
202
+ int WiFiClientSecureCtx ::connect (IPAddress ip, uint16_t port) {
208
203
if (!WiFiClient::connect (ip, port)) {
209
204
return 0 ;
210
205
}
211
206
return _connectSSL (nullptr );
212
207
}
213
208
214
- int WiFiClientSecure ::connect (const char * name, uint16_t port) {
209
+ int WiFiClientSecureCtx ::connect (const char * name, uint16_t port) {
215
210
IPAddress remote_addr;
216
211
if (!WiFi.hostByName (name, remote_addr)) {
217
212
DEBUG_BSSL (" connect: Name lookup failure\n " );
@@ -224,11 +219,11 @@ int WiFiClientSecure::connect(const char* name, uint16_t port) {
224
219
return _connectSSL (name);
225
220
}
226
221
227
- int WiFiClientSecure ::connect (const String& host, uint16_t port) {
222
+ int WiFiClientSecureCtx ::connect (const String& host, uint16_t port) {
228
223
return connect (host.c_str (), port);
229
224
}
230
225
231
- void WiFiClientSecure ::_freeSSL () {
226
+ void WiFiClientSecureCtx ::_freeSSL () {
232
227
// These are smart pointers and will free if refcnt==0
233
228
_sc = nullptr ;
234
229
_sc_svr = nullptr ;
@@ -245,18 +240,18 @@ void WiFiClientSecure::_freeSSL() {
245
240
_timeout = 15000 ;
246
241
}
247
242
248
- bool WiFiClientSecure ::_clientConnected () {
243
+ bool WiFiClientSecureCtx ::_clientConnected () {
249
244
return (_client && _client->state () == ESTABLISHED);
250
245
}
251
246
252
- uint8_t WiFiClientSecure ::connected () {
247
+ uint8_t WiFiClientSecureCtx ::connected () {
253
248
if (available () || (_clientConnected () && _handshake_done && (br_ssl_engine_current_state (_eng) != BR_SSL_CLOSED))) {
254
249
return true ;
255
250
}
256
251
return false ;
257
252
}
258
253
259
- size_t WiFiClientSecure ::_write (const uint8_t *buf, size_t size, bool pmem) {
254
+ size_t WiFiClientSecureCtx ::_write (const uint8_t *buf, size_t size, bool pmem) {
260
255
size_t sent_bytes = 0 ;
261
256
262
257
if (!connected () || !size || !_handshake_done) {
@@ -297,16 +292,16 @@ size_t WiFiClientSecure::_write(const uint8_t *buf, size_t size, bool pmem) {
297
292
return sent_bytes;
298
293
}
299
294
300
- size_t WiFiClientSecure ::write (const uint8_t *buf, size_t size) {
295
+ size_t WiFiClientSecureCtx ::write (const uint8_t *buf, size_t size) {
301
296
return _write (buf, size, false );
302
297
}
303
298
304
- size_t WiFiClientSecure ::write_P (PGM_P buf, size_t size) {
299
+ size_t WiFiClientSecureCtx ::write_P (PGM_P buf, size_t size) {
305
300
return _write ((const uint8_t *)buf, size, true );
306
301
}
307
302
308
303
// We have to manually read and send individual chunks.
309
- size_t WiFiClientSecure ::write (Stream& stream) {
304
+ size_t WiFiClientSecureCtx ::write (Stream& stream) {
310
305
size_t totalSent = 0 ;
311
306
size_t countRead;
312
307
size_t countSent;
@@ -329,7 +324,7 @@ size_t WiFiClientSecure::write(Stream& stream) {
329
324
return totalSent;
330
325
}
331
326
332
- int WiFiClientSecure ::read (uint8_t *buf, size_t size) {
327
+ int WiFiClientSecureCtx ::read (uint8_t *buf, size_t size) {
333
328
if (!ctx_present () || !_handshake_done) {
334
329
return -1 ;
335
330
}
@@ -361,7 +356,7 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size) {
361
356
return 0 ; // If we're connected, no error but no read.
362
357
}
363
358
364
- int WiFiClientSecure ::read () {
359
+ int WiFiClientSecureCtx ::read () {
365
360
uint8_t c;
366
361
if (1 == read (&c, 1 )) {
367
362
return c;
@@ -370,7 +365,7 @@ int WiFiClientSecure::read() {
370
365
return -1 ;
371
366
}
372
367
373
- int WiFiClientSecure ::available () {
368
+ int WiFiClientSecureCtx ::available () {
374
369
if (_recvapp_buf) {
375
370
return _recvapp_len; // Anything from last call?
376
371
}
@@ -391,7 +386,7 @@ int WiFiClientSecure::available() {
391
386
return 0 ;
392
387
}
393
388
394
- int WiFiClientSecure ::peek () {
389
+ int WiFiClientSecureCtx ::peek () {
395
390
if (!ctx_present () || !available ()) {
396
391
DEBUG_BSSL (" peek: Not connected, none left available\n " );
397
392
return -1 ;
@@ -403,7 +398,7 @@ int WiFiClientSecure::peek() {
403
398
return -1 ;
404
399
}
405
400
406
- size_t WiFiClientSecure ::peekBytes (uint8_t *buffer, size_t length) {
401
+ size_t WiFiClientSecureCtx ::peekBytes (uint8_t *buffer, size_t length) {
407
402
size_t to_copy = 0 ;
408
403
if (!ctx_present ()) {
409
404
DEBUG_BSSL (" peekBytes: Not connected\n " );
@@ -426,7 +421,7 @@ size_t WiFiClientSecure::peekBytes(uint8_t *buffer, size_t length) {
426
421
combination of both (the combination matches either). When a match is
427
422
achieved, this function returns 0. On error, it returns -1.
428
423
*/
429
- int WiFiClientSecure ::_run_until (unsigned target, bool blocking) {
424
+ int WiFiClientSecureCtx ::_run_until (unsigned target, bool blocking) {
430
425
if (!ctx_present ()) {
431
426
DEBUG_BSSL (" _run_until: Not connected\n " );
432
427
return -1 ;
@@ -550,7 +545,7 @@ int WiFiClientSecure::_run_until(unsigned target, bool blocking) {
550
545
return -1 ;
551
546
}
552
547
553
- bool WiFiClientSecure ::_wait_for_handshake () {
548
+ bool WiFiClientSecureCtx ::_wait_for_handshake () {
554
549
_handshake_done = false ;
555
550
while (!_handshake_done && _clientConnected ()) {
556
551
int ret = _run_until (BR_SSL_SENDAPP);
@@ -575,7 +570,7 @@ static uint8_t htoi (unsigned char c)
575
570
}
576
571
577
572
// Set a fingerprint by parsing an ASCII string
578
- bool WiFiClientSecure ::setFingerprint (const char *fpStr) {
573
+ bool WiFiClientSecureCtx ::setFingerprint (const char *fpStr) {
579
574
int idx = 0 ;
580
575
uint8_t c, d;
581
576
uint8_t fp[20 ];
@@ -968,7 +963,7 @@ extern "C" {
968
963
}
969
964
970
965
// Set custom list of ciphers
971
- bool WiFiClientSecure ::setCiphers (const uint16_t *cipherAry, int cipherCount) {
966
+ bool WiFiClientSecureCtx ::setCiphers (const uint16_t *cipherAry, int cipherCount) {
972
967
_cipher_list = nullptr ;
973
968
_cipher_list = std::shared_ptr<uint16_t >(new (std::nothrow) uint16_t [cipherCount], std::default_delete<uint16_t []>());
974
969
if (!_cipher_list.get ()) {
@@ -980,16 +975,16 @@ bool WiFiClientSecure::setCiphers(const uint16_t *cipherAry, int cipherCount) {
980
975
return true ;
981
976
}
982
977
983
- bool WiFiClientSecure ::setCiphersLessSecure () {
978
+ bool WiFiClientSecureCtx ::setCiphersLessSecure () {
984
979
return setCiphers (faster_suites_P, sizeof (faster_suites_P)/sizeof (faster_suites_P[0 ]));
985
980
}
986
981
987
- bool WiFiClientSecure ::setCiphers (std::vector<uint16_t > list) {
982
+ bool WiFiClientSecureCtx ::setCiphers (const std::vector<uint16_t >& list) {
988
983
return setCiphers (&list[0 ], list.size ());
989
984
}
990
985
991
986
// Installs the appropriate X509 cert validation method for a client connection
992
- bool WiFiClientSecure ::_installClientX509Validator () {
987
+ bool WiFiClientSecureCtx ::_installClientX509Validator () {
993
988
if (_use_insecure || _use_fingerprint || _use_self_signed) {
994
989
// Use common insecure x509 authenticator
995
990
_x509_insecure = std::make_shared<struct br_x509_insecure_context >();
@@ -1046,7 +1041,7 @@ bool WiFiClientSecure::_installClientX509Validator() {
1046
1041
1047
1042
// Called by connect() to do the actual SSL setup and handshake.
1048
1043
// Returns if the SSL handshake succeeded.
1049
- bool WiFiClientSecure ::_connectSSL (const char * hostName) {
1044
+ bool WiFiClientSecureCtx ::_connectSSL (const char * hostName) {
1050
1045
DEBUG_BSSL (" _connectSSL: start connection\n " );
1051
1046
_freeSSL ();
1052
1047
_oom_err = false ;
@@ -1136,7 +1131,7 @@ bool WiFiClientSecure::_connectSSL(const char* hostName) {
1136
1131
1137
1132
// Slightly different X509 setup for servers who want to validate client
1138
1133
// certificates, so factor it out as it's used in RSA and EC servers.
1139
- bool WiFiClientSecure ::_installServerX509Validator (const X509List *client_CA_ta) {
1134
+ bool WiFiClientSecureCtx ::_installServerX509Validator (const X509List *client_CA_ta) {
1140
1135
if (client_CA_ta) {
1141
1136
_ta = client_CA_ta;
1142
1137
// X509 minimal validator. Checks dates, cert chain for trusted CA, etc.
@@ -1169,7 +1164,7 @@ bool WiFiClientSecure::_installServerX509Validator(const X509List *client_CA_ta)
1169
1164
1170
1165
1171
1166
// Called by WiFiServerBearSSL when an RSA cert/key is specified.
1172
- bool WiFiClientSecure ::_connectSSLServerRSA (const X509List *chain,
1167
+ bool WiFiClientSecureCtx ::_connectSSLServerRSA (const X509List *chain,
1173
1168
const PrivateKey *sk,
1174
1169
const X509List *client_CA_ta) {
1175
1170
_freeSSL ();
@@ -1205,7 +1200,7 @@ bool WiFiClientSecure::_connectSSLServerRSA(const X509List *chain,
1205
1200
}
1206
1201
1207
1202
// Called by WiFiServerBearSSL when an elliptic curve cert/key is specified.
1208
- bool WiFiClientSecure ::_connectSSLServerEC (const X509List *chain,
1203
+ bool WiFiClientSecureCtx ::_connectSSLServerEC (const X509List *chain,
1209
1204
unsigned cert_issuer_key_type, const PrivateKey *sk,
1210
1205
const X509List *client_CA_ta) {
1211
1206
#ifndef BEARSSL_SSL_BASIC
@@ -1251,7 +1246,7 @@ bool WiFiClientSecure::_connectSSLServerEC(const X509List *chain,
1251
1246
1252
1247
// Returns an error ID and possibly a string (if dest != null) of the last
1253
1248
// BearSSL reported error.
1254
- int WiFiClientSecure ::getLastSSLError (char *dest, size_t len) {
1249
+ int WiFiClientSecureCtx ::getLastSSLError (char *dest, size_t len) {
1255
1250
int err = 0 ;
1256
1251
const char *t = PSTR (" OK" );
1257
1252
const char *recv_fatal = " " ;
0 commit comments