Added loadCert methods to WiFiClientSecure (#1959)

This commit is contained in:
lbernstone 2018-11-19 07:50:08 -08:00 committed by Me No Dev
parent f6a71da378
commit 65c861ad4c
2 changed files with 51 additions and 0 deletions

View File

@ -230,6 +230,51 @@ bool WiFiClientSecure::verify(const char* fp, const char* domain_name)
return verify_ssl_fingerprint(sslclient, fp, domain_name); return verify_ssl_fingerprint(sslclient, fp, domain_name);
} }
char *WiFiClientSecure::_streamLoad(Stream& stream, size_t size) {
char *dest = (char*)malloc(size);
if (!dest) {
return nullptr;
}
if (size != stream.readBytes(dest, size)) {
free(dest);
return nullptr;
}
char ret[size+1];
snprintf(ret, size, "%s", dest);
free(dest);
return ret;
}
bool WiFiClientSecure::loadCACert(Stream& stream, size_t size) {
char *dest = _streamLoad(stream, size);
bool ret = false;
if (dest) {
setCACert(dest);
ret = true;
}
return ret;
}
bool WiFiClientSecure::loadCertificate(Stream& stream, size_t size) {
char *dest = _streamLoad(stream, size);
bool ret = false;
if (dest) {
setCertificate(dest);
ret = true;
}
return ret;
}
bool WiFiClientSecure::loadPrivateKey(Stream& stream, size_t size) {
char *dest = _streamLoad(stream, size);
bool ret = false;
if (dest) {
setPrivateKey(dest);
ret = true;
}
return ret;
}
int WiFiClientSecure::lastError(char *buf, const size_t size) int WiFiClientSecure::lastError(char *buf, const size_t size)
{ {
if (!_lastError) { if (!_lastError) {

View File

@ -58,6 +58,9 @@ public:
void setCACert(const char *rootCA); void setCACert(const char *rootCA);
void setCertificate(const char *client_ca); void setCertificate(const char *client_ca);
void setPrivateKey (const char *private_key); void setPrivateKey (const char *private_key);
bool loadCACert(Stream& stream, size_t size);
bool loadCertificate(Stream& stream, size_t size);
bool loadPrivateKey(Stream& stream, size_t size);
bool verify(const char* fingerprint, const char* domain_name); bool verify(const char* fingerprint, const char* domain_name);
operator bool() operator bool()
@ -84,6 +87,9 @@ public:
return sslclient->socket = -1; return sslclient->socket = -1;
} }
private:
char *_streamLoad(Stream& stream, size_t size);
//friend class WiFiServer; //friend class WiFiServer;
using Print::write; using Print::write;
}; };