Skip to content

Commit cfdcff1

Browse files
Catch and display SSL errors for fatal alerts (#7681)
Partial fix to #7678
1 parent eb7e082 commit cfdcff1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,22 @@ bool WiFiClientSecure::_connectSSLServerEC(const X509List *chain,
12541254
int WiFiClientSecure::getLastSSLError(char *dest, size_t len) {
12551255
int err = 0;
12561256
const char *t = PSTR("OK");
1257+
const char *recv_fatal = "";
1258+
const char *send_fatal = "";
12571259
if (_sc || _sc_svr) {
12581260
err = br_ssl_engine_last_error(_eng);
12591261
}
12601262
if (_oom_err) {
12611263
err = -1000;
1264+
} else {
1265+
if (err & BR_ERR_RECV_FATAL_ALERT) {
1266+
recv_fatal = PSTR("SSL received fatal alert - ");
1267+
err &= ~BR_ERR_RECV_FATAL_ALERT;
1268+
}
1269+
if (err & BR_ERR_SEND_FATAL_ALERT) {
1270+
send_fatal = PSTR("SSL sent fatal alert - ");
1271+
err &= ~BR_ERR_SEND_FATAL_ALERT;
1272+
}
12621273
}
12631274
switch (err) {
12641275
case -1000: t = PSTR("Unable to allocate memory for SSL structures and buffers."); break;
@@ -1323,8 +1334,8 @@ int WiFiClientSecure::getLastSSLError(char *dest, size_t len) {
13231334
default: t = PSTR("Unknown error code."); break;
13241335
}
13251336
if (dest) {
1326-
strncpy_P(dest, t, len);
1327-
dest[len - 1] = 0;
1337+
// snprintf is PSTR safe and guaranteed to 0-terminate
1338+
snprintf(dest, len, "%s%s%s", recv_fatal, send_fatal, t);
13281339
}
13291340
return err;
13301341
}

0 commit comments

Comments
 (0)