Skip to content

Commit 7ac3296

Browse files
authored
Set TLS cert options before calling connect on client, so verify works
When connecting using transportTraits, the CA and client certificates are ignored after the initial _client->connect() is called. This is because on connect, WiFiClientSecure will call start_ssl_client with _CA_Cert and other cert options set to null unless setCACert, setCertificate etc. are called before connect. Running _transportTraits->verify after connect therefore does exactly nothing. It's easy to verify that this is the case by passing a CACert to HTTPClient with verbose logging enabled - the logs will say "WARNING: Use certificates for a more secure communication!" which is only present when both PSK and CA are null. This change fixes the issue.
1 parent 13e0206 commit 7ac3296

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

libraries/HTTPClient/src/HTTPClient.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,13 @@ bool HTTPClient::connect(void)
10121012
log_d("HTTPClient::begin was not called or returned error");
10131013
return false;
10141014
}
1015-
1015+
#ifdef HTTPCLIENT_1_1_COMPATIBLE
1016+
if (_tcpDeprecated && !_transportTraits->verify(*_client, _host.c_str())) {
1017+
log_d("transport level verify failed");
1018+
_client->stop();
1019+
return false;
1020+
}
1021+
#endif
10161022
if(!_client->connect(_host.c_str(), _port, _connectTimeout)) {
10171023
log_d("failed connect to %s:%u", _host.c_str(), _port);
10181024
return false;
@@ -1023,14 +1029,6 @@ bool HTTPClient::connect(void)
10231029

10241030
log_d(" connected to %s:%u", _host.c_str(), _port);
10251031

1026-
#ifdef HTTPCLIENT_1_1_COMPATIBLE
1027-
if (_tcpDeprecated && !_transportTraits->verify(*_client, _host.c_str())) {
1028-
log_d("transport level verify failed");
1029-
_client->stop();
1030-
return false;
1031-
}
1032-
#endif
1033-
10341032

10351033
/*
10361034
#ifdef ESP8266

0 commit comments

Comments
 (0)