1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

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.
This commit is contained in:
Earle F. Philhower, III 2018-02-06 07:33:26 -08:00 committed by GitHub
parent c8dbfb160b
commit 4c23e66bba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 17 deletions

View File

@ -27,6 +27,12 @@
#include "WiFiClient.h" #include "WiFiClient.h"
#include "ESP8266WebServerSecure.h" #include "ESP8266WebServerSecure.h"
//#define DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
#define DEBUG_OUTPUT DEBUG_ESP_PORT
#else
#define DEBUG_OUTPUT Serial
#endif
ESP8266WebServerSecure::ESP8266WebServerSecure(IPAddress addr, int port) ESP8266WebServerSecure::ESP8266WebServerSecure(IPAddress addr, int port)
: _serverSecure(addr, port) : _serverSecure(addr, port)

View File

@ -329,14 +329,6 @@ public:
return reinterpret_cast<SSLContext*>(fd)->io_ctx; return reinterpret_cast<SSLContext*>(fd)->io_ctx;
} }
int loadServerX509Cert(const uint8_t *cert, int len) {
return ssl_obj_memory_load(SSLContext::_ssl_ctx, SSL_OBJ_X509_CERT, cert, len, NULL);
}
int loadServerRSAKey(const uint8_t *rsakey, int len) {
return ssl_obj_memory_load(SSLContext::_ssl_ctx, SSL_OBJ_RSA_KEY, rsakey, len, NULL);
}
protected: protected:
int _readAll() int _readAll()
{ {
@ -471,23 +463,18 @@ WiFiClientSecure::WiFiClientSecure(ClientContext* client, bool usePMEM, const ui
_ssl->ref(); _ssl->ref();
if (usePMEM) { if (usePMEM) {
// When using PMEM based certs, allocate stack and copy from flash to DRAM, call SSL functions to avoid
// heap fragmentation that would happen w/malloc()
uint8_t *stackData = (uint8_t*)alloca(max(certLen, rsakeyLen));
if (rsakey && rsakeyLen) { if (rsakey && rsakeyLen) {
memcpy_P(stackData, rsakey, rsakeyLen); _ssl->loadObject_P(SSL_OBJ_RSA_KEY, rsakey, rsakeyLen);
_ssl->loadServerRSAKey(stackData, rsakeyLen);
} }
if (cert && certLen) { if (cert && certLen) {
memcpy_P(stackData, cert, certLen); _ssl->loadObject_P(SSL_OBJ_X509_CERT, cert, certLen);
_ssl->loadServerX509Cert(stackData, certLen);
} }
} else { } else {
if (rsakey && rsakeyLen) { if (rsakey && rsakeyLen) {
_ssl->loadServerRSAKey(rsakey, rsakeyLen); _ssl->loadObject(SSL_OBJ_RSA_KEY, rsakey, rsakeyLen);
} }
if (cert && certLen) { if (cert && certLen) {
_ssl->loadServerX509Cert(cert, certLen); _ssl->loadObject(SSL_OBJ_X509_CERT, cert, certLen);
} }
} }
_client->ref(); _client->ref();