Extend HTTPClient to allow connecting with a client certificate (#788)

* Forward client certificate to wificlient secure

* remove comment
This commit is contained in:
Andreas Pokorny 2017-10-30 09:37:33 +01:00 committed by Me No Dev
parent 0768590332
commit 36dba996c1
2 changed files with 22 additions and 3 deletions

View File

@ -54,8 +54,8 @@ public:
class TLSTraits : public TransportTraits
{
public:
TLSTraits(const char* CAcert) :
_cacert(CAcert)
TLSTraits(const char* CAcert, const char* clicert = nullptr, const char* clikey = nullptr) :
_cacert(CAcert), _clicert(clicert), _clikey(clikey)
{
}
@ -68,11 +68,15 @@ public:
{
WiFiClientSecure& wcs = static_cast<WiFiClientSecure&>(client);
wcs.setCACert(_cacert);
wcs.setCertificate(_clicert);
wcs.setPrivateKey(_clikey);
return true;
}
protected:
const char* _cacert;
const char* _clicert;
const char* _clikey;
};
/**
@ -203,6 +207,20 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer
return true;
}
bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcert, const char* cli_cert, const char* cli_key)
{
clear();
_host = host;
_port = port;
_uri = uri;
if (strlen(CAcert) == 0) {
return false;
}
_transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key));
return true;
}
/**
* end
* called after the payload is handled

View File

@ -129,6 +129,7 @@ public:
bool begin(String url, const char* CAcert);
bool begin(String host, uint16_t port, String uri = "/");
bool begin(String host, uint16_t port, String uri, const char* CAcert);
bool begin(String host, uint16_t port, String uri, const char* CAcert, const char* cli_cert, const char* cli_key);
void end(void);