Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch and display SSL errors for fatal alerts #7681

Merged
merged 2 commits into from
Oct 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,11 +1254,22 @@ bool WiFiClientSecure::_connectSSLServerEC(const X509List *chain,
int WiFiClientSecure::getLastSSLError(char *dest, size_t len) {
int err = 0;
const char *t = PSTR("OK");
const char *recv_fatal = "";
const char *send_fatal = "";
if (_sc || _sc_svr) {
err = br_ssl_engine_last_error(_eng);
}
if (_oom_err) {
err = -1000;
} else {
if (err & BR_ERR_RECV_FATAL_ALERT) {
recv_fatal = PSTR("SSL received fatal alert - ");
err &= ~BR_ERR_RECV_FATAL_ALERT;
}
if (err & BR_ERR_SEND_FATAL_ALERT) {
send_fatal = PSTR("SSL sent fatal alert - ");
err &= ~BR_ERR_SEND_FATAL_ALERT;
}
}
switch (err) {
case -1000: t = PSTR("Unable to allocate memory for SSL structures and buffers."); break;
Expand Down Expand Up @@ -1323,8 +1334,8 @@ int WiFiClientSecure::getLastSSLError(char *dest, size_t len) {
default: t = PSTR("Unknown error code."); break;
}
if (dest) {
strncpy_P(dest, t, len);
dest[len - 1] = 0;
// snprintf is PSTR safe and guaranteed to 0-terminate
snprintf(dest, len, "%s%s%s", recv_fatal, send_fatal, t);
}
return err;
}
Expand Down