Skip to content

Commit e9d5f89

Browse files
committed
Fixed bug with casting to Secure client on not secured one (causing
crash)
1 parent c163148 commit e9d5f89

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

src/supla/network/esp_wifi.h

+9-27
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class ESPWifi : public Supla::Network {
5151
setSsid(wifiSsid);
5252
setPassword(wifiPassword);
5353
#ifdef ARDUINO_ARCH_ESP32
54-
enableSSL(
55-
false); // current ESP32 WiFiClientSecure does not suport "setInsecure"
54+
enableSSL(false); // ESP32 WiFiClientSecure does not suport "setInsecure"
5655
#endif
5756
}
5857

@@ -96,22 +95,19 @@ class ESPWifi : public Supla::Network {
9695
if (client == NULL) {
9796
if (isSecured) {
9897
message = "Secured connection";
99-
client = new WiFiClientSecure();
98+
auto clientSec = new WiFiClientSecure();
99+
client = clientSec;
100+
101+
#ifdef ARDUINO_ARCH_ESP8266
102+
clientSec->setBufferSizes(2048, 512); // EXPERIMENTAL
100103
if (fingerprint.length() > 0) {
101104
message += " with certificate matching";
102-
#ifdef ARDUINO_ARCH_ESP8266
103-
((WiFiClientSecure *)client)->setFingerprint(fingerprint.c_str());
104-
#else
105-
message += " - NOT SUPPORTED ON ESP32 implmentation";
106-
#endif
105+
clientSec->setFingerprint(fingerprint.c_str());
107106
} else {
108107
message += " without certificate matching";
109-
#ifdef ARDUINO_ARCH_ESP8266
110-
((WiFiClientSecure *)client)->setInsecure();
111-
#else
112-
message += " - NOT SUPPORTED ON ESP32 implmentation";
113-
#endif
108+
clientSec->setInsecure();
114109
}
110+
#endif
115111
} else {
116112
message = "unsecured connection";
117113
client = new WiFiClient();
@@ -129,22 +125,8 @@ class ESPWifi : public Supla::Network {
129125
server,
130126
connectionPort);
131127

132-
#ifdef ARDUINO_ARCH_ESP8266
133-
static_cast<WiFiClientSecure*>(client)->setBufferSizes(2048, 512); // EXPERIMENTAL
134-
#endif
135-
136128
bool result = client->connect(server, connectionPort);
137129

138-
// ESP8266 boards 3.0.0 onward do fingerprint check in connect() method.
139-
/*if (result && isSecured) {
140-
if (!((WiFiClientSecure *)client)->verify(fingerprint.c_str(), server)) {
141-
supla_log(LOG_DEBUG, "Provided certificates doesn't match!");
142-
client->stop();
143-
return false;
144-
}
145-
};
146-
*/
147-
148130
return result;
149131
}
150132

0 commit comments

Comments
 (0)