Skip to content

Commit 8c65f2f

Browse files
committed
Update axTLS to fe4518d, SNI support in WiFiClientSecure (#1285)
Fixes #1933
1 parent b7c23c7 commit 8c65f2f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

libraries/ESP8266WiFi/src/WiFiClientSecure.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class SSLContext {
9393
}
9494
}
9595

96-
void connect(ClientContext* ctx, uint32_t timeout_ms) {
97-
_ssl = ssl_client_new(_ssl_ctx, reinterpret_cast<int>(ctx), nullptr, 0);
96+
void connect(ClientContext* ctx, const char* hostName, uint32_t timeout_ms) {
97+
_ssl = ssl_client_new(_ssl_ctx, reinterpret_cast<int>(ctx), nullptr, 0, hostName);
9898
uint32_t t = millis();
9999

100100
while (millis() - t < timeout_ms && ssl_handshake_status(_ssl) != SSL_OK) {
@@ -242,24 +242,29 @@ int WiFiClientSecure::connect(IPAddress ip, uint16_t port) {
242242
if (!WiFiClient::connect(ip, port))
243243
return 0;
244244

245-
return _connectSSL();
245+
return _connectSSL(nullptr);
246246
}
247247

248248
int WiFiClientSecure::connect(const char* name, uint16_t port) {
249-
if (!WiFiClient::connect(name, port))
249+
IPAddress remote_addr;
250+
if (!WiFi.hostByName(name, remote_addr)) {
250251
return 0;
251-
return 1;
252+
}
253+
if (!WiFiClient::connect(remote_addr, port)) {
254+
return 0;
255+
}
256+
return _connectSSL(name);
252257
}
253258

254-
int WiFiClientSecure::_connectSSL() {
259+
int WiFiClientSecure::_connectSSL(const char* hostName) {
255260
if (_ssl) {
256261
_ssl->unref();
257262
_ssl = nullptr;
258263
}
259264

260265
_ssl = new SSLContext;
261266
_ssl->ref();
262-
_ssl->connect(_client, 5000);
267+
_ssl->connect(_client, hostName, 5000);
263268

264269
auto status = ssl_handshake_status(*_ssl);
265270
if (status != SSL_OK) {

libraries/ESP8266WiFi/src/WiFiClientSecure.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class WiFiClientSecure : public WiFiClient {
6666
}
6767

6868
protected:
69-
int _connectSSL();
69+
int _connectSSL(const char* hostName);
7070

7171
SSLContext* _ssl = nullptr;
7272
};

libraries/ESP8266WiFi/src/include/ssl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,11 @@ EXP_FUNC SSL * STDCALL ssl_server_new(SSL_CTX *ssl_ctx, int client_fd);
243243
* can be null if no session resumption is being used or required. This option
244244
* is not used in skeleton mode.
245245
* @param sess_id_size The size of the session id (max 32)
246+
* @param host_name If non-zero, host name to be sent to server for SNI support
246247
* @return An SSL object reference. Use ssl_handshake_status() to check
247248
* if a handshake succeeded.
248249
*/
249-
EXP_FUNC SSL * STDCALL ssl_client_new(SSL_CTX *ssl_ctx, int client_fd, const uint8_t *session_id, uint8_t sess_id_size);
250+
EXP_FUNC SSL * STDCALL ssl_client_new(SSL_CTX *ssl_ctx, int client_fd, const uint8_t *session_id, uint8_t sess_id_size, const char* host_name);
250251

251252
/**
252253
* @brief Free any used resources on this connection.

tools/sdk/lib/libaxtls.a

-634 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)