Skip to content

Minor cleanup of SSL server methods, missing macros #4280

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

Merged
merged 3 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions libraries/ESP8266WebServer/src/ESP8266WebServerSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
#include "WiFiClient.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)
: _serverSecure(addr, port)
Expand Down
21 changes: 4 additions & 17 deletions libraries/ESP8266WiFi/src/WiFiClientSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,6 @@ class SSLContext
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:
int _readAll()
{
Expand Down Expand Up @@ -471,23 +463,18 @@ WiFiClientSecure::WiFiClientSecure(ClientContext* client, bool usePMEM, const ui
_ssl->ref();

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) {
memcpy_P(stackData, rsakey, rsakeyLen);
_ssl->loadServerRSAKey(stackData, rsakeyLen);
_ssl->loadObject_P(SSL_OBJ_RSA_KEY, rsakey, rsakeyLen);
}
if (cert && certLen) {
memcpy_P(stackData, cert, certLen);
_ssl->loadServerX509Cert(stackData, certLen);
_ssl->loadObject_P(SSL_OBJ_X509_CERT, cert, certLen);
}
} else {
if (rsakey && rsakeyLen) {
_ssl->loadServerRSAKey(rsakey, rsakeyLen);
_ssl->loadObject(SSL_OBJ_RSA_KEY, rsakey, rsakeyLen);
}
if (cert && certLen) {
_ssl->loadServerX509Cert(cert, certLen);
_ssl->loadObject(SSL_OBJ_X509_CERT, cert, certLen);
}
}
_client->ref();
Expand Down