Added loadCert methods to WiFiClientSecure (#1959)
This commit is contained in:
parent
f6a71da378
commit
65c861ad4c
@ -230,6 +230,51 @@ bool WiFiClientSecure::verify(const char* fp, const char* 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)
|
||||
{
|
||||
if (!_lastError) {
|
||||
|
@ -58,6 +58,9 @@ public:
|
||||
void setCACert(const char *rootCA);
|
||||
void setCertificate(const char *client_ca);
|
||||
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);
|
||||
|
||||
operator bool()
|
||||
@ -84,6 +87,9 @@ public:
|
||||
return sslclient->socket = -1;
|
||||
}
|
||||
|
||||
private:
|
||||
char *_streamLoad(Stream& stream, size_t size);
|
||||
|
||||
//friend class WiFiServer;
|
||||
using Print::write;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user