@@ -130,10 +130,19 @@ class SSLContext {
130
130
131
131
protected:
132
132
int _readAll () {
133
+ if (!_ssl)
134
+ return 0 ;
135
+
133
136
uint8_t * data;
134
137
int rc = ssl_read (_ssl, &data);
135
- if (rc <= 0 )
138
+ if (rc <= 0 ) {
139
+ if (rc < SSL_OK && rc != SSL_CLOSE_NOTIFY && rc != SSL_ERROR_CONN_LOST) {
140
+ ssl_free (_ssl);
141
+ _ssl = nullptr ;
142
+ }
136
143
return 0 ;
144
+ }
145
+
137
146
138
147
if (rc > _rxbuf->room ()) {
139
148
DEBUGV (" WiFiClientSecure rx overflow" );
@@ -219,6 +228,9 @@ int WiFiClientSecure::_connectSSL() {
219
228
}
220
229
221
230
size_t WiFiClientSecure::write (const uint8_t *buf, size_t size) {
231
+ if (!_ssl)
232
+ return 0 ;
233
+
222
234
int rc = ssl_write (*_ssl, buf, size);
223
235
if (rc >= 0 )
224
236
return rc;
@@ -227,21 +239,43 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size) {
227
239
}
228
240
229
241
int WiFiClientSecure::read (uint8_t *buf, size_t size) {
242
+ if (!_ssl)
243
+ return 0 ;
244
+
230
245
return _ssl->read (buf, size);
231
246
}
232
247
233
248
int WiFiClientSecure::read () {
249
+ if (!_ssl)
250
+ return -1 ;
251
+
234
252
return _ssl->read ();
235
253
}
236
254
237
255
int WiFiClientSecure::peek () {
256
+ if (!_ssl)
257
+ return -1 ;
258
+
238
259
return _ssl->peek ();
239
260
}
240
261
241
262
int WiFiClientSecure::available () {
263
+ if (!_ssl)
264
+ return 0 ;
265
+
242
266
return _ssl->available ();
243
267
}
244
268
269
+ uint8_t WiFiClientSecure::connected () {
270
+ if (_client->state () == ESTABLISHED)
271
+ return 1 ;
272
+
273
+ if (!_ssl)
274
+ return 0 ;
275
+
276
+ return _ssl->available () > 0 ;
277
+ }
278
+
245
279
void WiFiClientSecure::stop () {
246
280
if (_ssl) {
247
281
_ssl->unref ();
@@ -264,6 +298,9 @@ static bool parseHexNibble(char pb, uint8_t* res) {
264
298
}
265
299
266
300
bool WiFiClientSecure::verify (const char * fp, const char * url) {
301
+ if (!_ssl)
302
+ return false ;
303
+
267
304
uint8_t sha1[20 ];
268
305
int len = strlen (fp);
269
306
int pos = 0 ;
0 commit comments