Skip to content

Commit 4c23e66

Browse files
SSL server DEBUG, code cleanup fixes (#4280)
The server needs to load an X509 and RSA key, but instead of using the existing loadObject() calls implemented its own. Remove them and use the standard ones instead. The DEBUG_OUTPUT macro was undefined in the SSL Web server. Add it in do that when you compile with DEBUG=HTTP_SERVER it actually compiles.
1 parent c8dbfb1 commit 4c23e66

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServerSecure.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
#include "WiFiClient.h"
2828
#include "ESP8266WebServerSecure.h"
2929

30+
//#define DEBUG_ESP_HTTP_SERVER
31+
#ifdef DEBUG_ESP_PORT
32+
#define DEBUG_OUTPUT DEBUG_ESP_PORT
33+
#else
34+
#define DEBUG_OUTPUT Serial
35+
#endif
3036

3137
ESP8266WebServerSecure::ESP8266WebServerSecure(IPAddress addr, int port)
3238
: _serverSecure(addr, port)

libraries/ESP8266WiFi/src/WiFiClientSecure.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,6 @@ class SSLContext
329329
return reinterpret_cast<SSLContext*>(fd)->io_ctx;
330330
}
331331

332-
int loadServerX509Cert(const uint8_t *cert, int len) {
333-
return ssl_obj_memory_load(SSLContext::_ssl_ctx, SSL_OBJ_X509_CERT, cert, len, NULL);
334-
}
335-
336-
int loadServerRSAKey(const uint8_t *rsakey, int len) {
337-
return ssl_obj_memory_load(SSLContext::_ssl_ctx, SSL_OBJ_RSA_KEY, rsakey, len, NULL);
338-
}
339-
340332
protected:
341333
int _readAll()
342334
{
@@ -471,23 +463,18 @@ WiFiClientSecure::WiFiClientSecure(ClientContext* client, bool usePMEM, const ui
471463
_ssl->ref();
472464

473465
if (usePMEM) {
474-
// When using PMEM based certs, allocate stack and copy from flash to DRAM, call SSL functions to avoid
475-
// heap fragmentation that would happen w/malloc()
476-
uint8_t *stackData = (uint8_t*)alloca(max(certLen, rsakeyLen));
477466
if (rsakey && rsakeyLen) {
478-
memcpy_P(stackData, rsakey, rsakeyLen);
479-
_ssl->loadServerRSAKey(stackData, rsakeyLen);
467+
_ssl->loadObject_P(SSL_OBJ_RSA_KEY, rsakey, rsakeyLen);
480468
}
481469
if (cert && certLen) {
482-
memcpy_P(stackData, cert, certLen);
483-
_ssl->loadServerX509Cert(stackData, certLen);
470+
_ssl->loadObject_P(SSL_OBJ_X509_CERT, cert, certLen);
484471
}
485472
} else {
486473
if (rsakey && rsakeyLen) {
487-
_ssl->loadServerRSAKey(rsakey, rsakeyLen);
474+
_ssl->loadObject(SSL_OBJ_RSA_KEY, rsakey, rsakeyLen);
488475
}
489476
if (cert && certLen) {
490-
_ssl->loadServerX509Cert(cert, certLen);
477+
_ssl->loadObject(SSL_OBJ_X509_CERT, cert, certLen);
491478
}
492479
}
493480
_client->ref();

0 commit comments

Comments
 (0)