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 class TLSTraits : public TransportTraits
{ {
public: public:
TLSTraits(const char* CAcert) : TLSTraits(const char* CAcert, const char* clicert = nullptr, const char* clikey = nullptr) :
_cacert(CAcert) _cacert(CAcert), _clicert(clicert), _clikey(clikey)
{ {
} }
@ -67,12 +67,16 @@ public:
bool verify(WiFiClient& client, const char* host) override bool verify(WiFiClient& client, const char* host) override
{ {
WiFiClientSecure& wcs = static_cast<WiFiClientSecure&>(client); WiFiClientSecure& wcs = static_cast<WiFiClientSecure&>(client);
wcs.setCACert(_cacert); wcs.setCACert(_cacert);
wcs.setCertificate(_clicert);
wcs.setPrivateKey(_clikey);
return true; return true;
} }
protected: protected:
const char* _cacert; 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; 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 * end
* called after the payload is handled * called after the payload is handled

View File

@ -129,6 +129,7 @@ public:
bool begin(String url, const char* CAcert); 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 = "/");
bool begin(String host, uint16_t port, String uri, const char* CAcert); 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); void end(void);