Skip to content

ESP8266WebServerSecure BearSSL handshakes failing frequently #6247

Closed
@thekurtovic

Description

@thekurtovic

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-WROOM-02
  • Core Version: 2.5.2-47-g5a47cab7
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: dout
  • Flash Size: 2MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: ck
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

I am trying to migrate from ESP8266WebServer to ESP8266WebServerSecure, and have been able to successfully connect to a soft-AP created by the ESP via HTTPS. I expected the performance to be noticeably slower compared HTTP, but getting a webpage served up to my smartphone seems like it can take quite a while sometimes. I enabled debug messages to the Serial port, with debug level SSL, and noticed I was seeing this message below very often.
BSSL:_wait_for_handshake: failed
This message shows up somewhat regularly after I connect to the AP and request https://192.168.4.1 on my smartphone's browser. I've tried changing the CPU frequency to 160 MHz, and although it does result in pages being served more often, doesn't seem to impact the handshake process. I noticed this while on 2.5.2, but have installed the latest git version as outlined here.

In the MCVE, the page served by the web server contains javascript which refreshes the page to start another request. The "Served root (millis)" messages help roughly calculate how long it took to serve the page, when compared to the previous value.

Am I misunderstanding the context of the "BSSL:_wait_for_handshake: failed" messages? Based on the debug messages, it appears as if the ESP has occasional moments where the handshakes occur seamlessly.

MCVE Sketch

#include <ESP8266WiFi.h>
#include <ESP8266WebServerSecure.h>
#include <DNSServer.h>

ESP8266WebServerSecure server(443);
DNSServer dnsServer;
#define DNS_PORT    53
#define AP_NAME     "AP_HTTPS_TEST"
#define AP_PASS     ""
#define AP_IP       192,168,4,1
#define AP_SUBNET   255,255,255,0
#define AP_PAGE     "<script>setTimeout(function(){ location.reload();}, 1000);</script><h1>%u</h1>"

uint16_t count = 0;

static const char serverCert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
MIIDSzCCAjMCCQD2ahcfZAwXxDANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC
VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU9yYW5nZSBDb3VudHkx
EDAOBgNVBAoMB1ByaXZhZG8xGjAYBgNVBAMMEXNlcnZlci56bGFiZWwuY29tMR8w
HQYJKoZIhvcNAQkBFhBlYXJsZUB6bGFiZWwuY29tMB4XDTE4MDMwNjA1NDg0NFoX
DTE5MDMwNjA1NDg0NFowRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3Rh
dGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBAPVKBwbZ+KDSl40YCDkP6y8Sv4iNGvEOZg8Y
X7sGvf/xZH7UiCBWPFIRpNmDSaZ3yjsmFqm6sLiYSGSdrBCFqdt9NTp2r7hga6Sj
oASSZY4B9pf+GblDy5m10KDx90BFKXdPMCLT+o76Nx9PpCvw13A848wHNG3bpBgI
t+w/vJCX3bkRn8yEYAU6GdMbYe7v446hX3kY5UmgeJFr9xz1kq6AzYrMt/UHhNzO
S+QckJaY0OGWvmTNspY3xCbbFtIDkCdBS8CZAw+itnofvnWWKQEXlt6otPh5njwy
+O1t/Q+Z7OMDYQaH02IQx3188/kW3FzOY32knER1uzjmRO+jhA8CAwEAATANBgkq
hkiG9w0BAQsFAAOCAQEAnDrROGRETB0woIcI1+acY1yRq4yAcH2/hdq2MoM+DCyM
E8CJaOznGR9ND0ImWpTZqomHOUkOBpvu7u315blQZcLbL1LfHJGRTCHVhvVrcyEb
fWTnRtAQdlirUm/obwXIitoz64VSbIVzcqqfg9C6ZREB9JbEX98/9Wp2gVY+31oC
JfUvYadSYxh3nblv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kIAarxQcTGsZaSqra3gXOJCMz9h2P5dxpdU+0yeMmOEnAqgQ8qtNBfAoGBAPim
RAtnrd0WSlCgqVGYFCvDh1kD5QTNbZc+1PcBHbVV45EmJ2fLXnlDeplIZJdYxmzu
DMOxZBYgfeLY9exje00eZJNSj/csjJQqiRftrbvYY7m5njX1kM5K8x4HlynQTDkg
rtKO0YZJxxmjRTbFGMegh1SLlFLRIMtehNhOgipRAoGBAPnEEpJGCS9GGLfaX0HW
YqwiEK8Il12q57mqgsq7ag7NPwWOymHesxHV5mMh/Dw+NyBi4xAGWRh9mtrUmeqK
iyICik773Gxo0RIqnPgd4jJWN3N3YWeynzulOIkJnSNx5BforOCTc3uCD2s2YB5X
jx1LKoNQxLeLRN8cmpIWicf/AoGBANjRSsZTKwV9WWIDJoHyxav/vPb+8WYFp8lZ
zaRxQbGM6nn4NiZI7OF62N3uhWB/1c7IqTK/bVHqFTuJCrCNcsgld3gLZ2QWYaMV
kCPgaj1BjHw4AmB0+EcajfKilcqtSroJ6MfMJ6IclVOizkjbByeTsE4lxDmPCDSt
/9MKanBxAoGAY9xo741Pn9WUxDyRplww606ccdNf/ksHWNc/Y2B5SPwxxSnIq8nO
j01SmsCUYVFAgZVOTiiycakjYLzxlc6p8BxSVqy6LlJqn95N8OXoQ+bkwUux/ekg
gz5JWYhbD6c38khSzJb0pNXCo3EuYAVa36kDM96k1BtWuhRS10Q1VXk=
-----END RSA PRIVATE KEY-----
)EOF";

void setup(void) {
    Serial.begin(115200);
    Serial.println("\n\nConfiguring AP");
    IPAddress ip(AP_IP);
    IPAddress subnet(AP_SUBNET);
    WiFi.softAP(AP_NAME, AP_PASS);
    WiFi.softAPConfig(ip, ip, subnet);

    dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
    dnsServer.start(DNS_PORT, "*", ip); 
  
    server.setRSACert(new X509List(serverCert), new PrivateKey(serverKey));
    server.on("/", []() {
        char buf[256];
        sprintf(buf, AP_PAGE, ++count);
        server.send(200, "text/html", buf);
        Serial.printf("Served root (%lu)\n", millis());
    });
    server.begin();
    Serial.println("HTTPS server started");
}

void loop() {
    server.handleClient();
    dnsServer.processNextRequest();
}

Debug Messages

@80 MHz
Configuring AP
HTTPS server started
add 1
aid 1
station: 24:92:0e:2c:c6:aa join, AID = 1
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (44541)
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (54183)
Served root (60111)
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (94620)
Served root (99540)
Served root (102922)
Served root (106318)
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (129950)


@160 MHz
Configuring AP
HTTPS server started
add 1
aid 1
station: 24:92:0e:2c:c6:aa join, AID = 1
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (54877)
BSSL:_wait_for_handshake: failed
Served root (60116)
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (75023)
Served root (76767)
Served root (78498)
Served root (80312)
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (94369)
Served root (96113)
Served root (97853)
Served root (101338)
BSSL:_wait_for_handshake: failed
Served root (104597)
Served root (106353)
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
BSSL:_wait_for_handshake: failed
Served root (120473)

Metadata

Metadata

Labels

waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions