Skip to content

Commit 75f01dc

Browse files
sislakdearlephilhower
authored andcommitted
Drop X509 after connection, avoid hang on TLS broken (#6065)
* Drop X509 context after successful server verification to save heap space After completing handshake in BSSL, server is already verified and X509 context is no longer needed. Depending on verification method it save more or less heap space. * Bugfix: Report not connected if there is no ready data and TLS connection is broken Added the change for reporting not connected if TLS session is broken and there is no more buffered decrypted data. TLS can be broken if message authentication (MAC) cannot be verified. BearSSL enters BR_SSL_CLOSED state when processing invalid encrypted application data fragment. In such situation the current implementation get stuck forever unless user has own timeout mechanism build on top of WiFiClientSecureBearSSL. This change introduce fail fast via connected() returning false. Further it imply return -1 from read methods indicating broken channel upon which user should perform reconnect if needed. Fixes #6005
1 parent 5010224 commit 75f01dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool WiFiClientSecure::_clientConnected() {
255255
}
256256

257257
uint8_t WiFiClientSecure::connected() {
258-
if (available() || (_clientConnected() && _handshake_done)) {
258+
if (available() || (_clientConnected() && _handshake_done && (br_ssl_engine_current_state(_eng) != BR_SSL_CLOSED))) {
259259
return true;
260260
}
261261
return false;
@@ -1003,6 +1003,12 @@ bool WiFiClientSecure::_connectSSL(const char* hostName) {
10031003
DEBUG_BSSL("Connected!\n");
10041004
}
10051005
#endif
1006+
1007+
// Session is already validated here, there is no need to keep following
1008+
_x509_minimal = nullptr;
1009+
_x509_insecure = nullptr;
1010+
_x509_knownkey = nullptr;
1011+
10061012
return ret;
10071013
}
10081014

0 commit comments

Comments
 (0)