Skip to content

Commit

Permalink
Allow usage of byte arrays to set RootCAs (esp8266#2968)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauttefk authored and igrr committed Feb 15, 2017
1 parent f30c03b commit af58a74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
20 changes: 14 additions & 6 deletions libraries/ESP8266WiFi/src/WiFiClientSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,20 +547,28 @@ bool WiFiClientSecure::verifyCertChain(const char* domain_name)
return _verifyDN(domain_name);
}

void WiFiClientSecure::setCertificate(const uint8_t* cert_data, size_t size)
bool WiFiClientSecure::setCACert(const uint8_t* pk, size_t size)
{
if (!_ssl) {
return;
return false;
}
return _ssl->loadObject(SSL_OBJ_X509_CACERT, pk, size);
}

bool WiFiClientSecure::setCertificate(const uint8_t* pk, size_t size)
{
if (!_ssl) {
return false;
}
_ssl->loadObject(SSL_OBJ_X509_CERT, cert_data, size);
return _ssl->loadObject(SSL_OBJ_X509_CERT, pk, size);
}

void WiFiClientSecure::setPrivateKey(const uint8_t* pk, size_t size)
bool WiFiClientSecure::setPrivateKey(const uint8_t* pk, size_t size)
{
if (!_ssl) {
return;
return false;
}
_ssl->loadObject(SSL_OBJ_RSA_KEY, pk, size);
return _ssl->loadObject(SSL_OBJ_RSA_KEY, pk, size);
}

bool WiFiClientSecure::loadCACert(Stream& stream, size_t size)
Expand Down
7 changes: 4 additions & 3 deletions libraries/ESP8266WiFi/src/WiFiClientSecure.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class WiFiClientSecure : public WiFiClient {
size_t peekBytes(uint8_t *buffer, size_t length) override;
void stop() override;

void setCertificate(const uint8_t* cert_data, size_t size);
void setPrivateKey(const uint8_t* pk, size_t size);
bool setCACert(const uint8_t* pk, size_t size);
bool setCertificate(const uint8_t* pk, size_t size);
bool setPrivateKey(const uint8_t* pk, size_t size);

bool loadCACert(Stream& stream, size_t size);
bool loadCertificate(Stream& stream, size_t size);
bool loadPrivateKey(Stream& stream, size_t size);
bool loadCACert(Stream& stream, size_t size);

template<typename TFile>
bool loadCertificate(TFile& file) {
Expand Down

0 comments on commit af58a74

Please sign in to comment.