Skip to content

Commit

Permalink
Add OOM check and debug message in CertStore (esp8266#5820)
Browse files Browse the repository at this point in the history
  • Loading branch information
earlephilhower authored Feb 26, 2019
1 parent d507c79 commit 95cf925
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
#include "CertStoreBearSSL.h"
#include <memory>


#ifdef DEBUG_ESP_SSL
#define DEBUG_BSSL(fmt, ...) DEBUG_ESP_PORT.printf_P((PGM_P)PSTR( "BSSL:" fmt), ## __VA_ARGS__)
#else
#define DEBUG_BSSL(...)
#endif

namespace BearSSL {

extern "C" {
Expand All @@ -39,6 +46,11 @@ CertStore::CertInfo CertStore::_preprocessCert(uint32_t length, uint32_t offset,
// Process it using SHA256, same as the hashed_dn
br_x509_decoder_context *ctx = new br_x509_decoder_context;
br_sha256_context *sha256 = new br_sha256_context;
if (!ctx || !sha256) {
DEBUG_BSSL("CertStore::_preprocessCert: OOM\n");
return ci;
}

br_sha256_init(sha256);
br_x509_decoder_init(ctx, dn_append, sha256, nullptr, nullptr);
br_x509_decoder_push(ctx, (const void*)raw, length);
Expand Down Expand Up @@ -172,6 +184,10 @@ const br_x509_trust_anchor *CertStore::findHashedTA(void *ctx, void *hashed_dn,
cs->_data->close();
cs->_x509 = new X509List(der, ci.length);
free(der);
if (!cs->_x509) {
DEBUG_BSSL("CertStore::findHashedTA: OOM\n");
return nullptr;
}

br_x509_trust_anchor *ta = (br_x509_trust_anchor*)cs->_x509->getTrustAnchors();
memcpy(ta->dn.data, ci.sha256, sizeof(ci.sha256));
Expand Down

0 comments on commit 95cf925

Please sign in to comment.