Skip to content

Commit 8c3bb69

Browse files
committed
WiFiClientSecure: don’t send close alert when opening new session
When WiFiClientSecure::connect was called, it would first tear down and existing and set up new TCP session, then tear down existing TLS session (using ssl_free), and then set up a new one. This caused TLS close- notify alert to be sent to the new TCP session, preventing new session from being established. This change postpones setting IO ctx to the new TCP connection, fixing this issue. Ref esp8266#3330
1 parent e39a46f commit 8c3bb69

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

libraries/ESP8266WiFi/src/WiFiClientSecure.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ class SSLContext
9393
SSL_EXTENSIONS* ext = ssl_ext_new();
9494
ssl_ext_set_host_name(ext, hostName);
9595
ssl_ext_set_max_fragment_size(ext, 4096);
96-
s_io_ctx = ctx;
9796
if (_ssl) {
97+
/* Creating a new TLS session on top of a new TCP connection.
98+
ssl_free will want to send a close notify alert, but the old TCP connection
99+
is already gone at this point, so reset s_io_ctx. */
100+
s_io_ctx = nullptr;
98101
ssl_free(_ssl);
102+
_available = 0;
103+
_read_ptr = nullptr;
99104
}
105+
s_io_ctx = ctx;
100106
_ssl = ssl_client_new(_ssl_ctx, 0, nullptr, 0, ext);
101107
uint32_t t = millis();
102108

0 commit comments

Comments
 (0)