diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index 8b82bbe0..fea672fc 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -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) { } @@ -67,12 +67,16 @@ public: bool verify(WiFiClient& client, const char* host) override { WiFiClientSecure& wcs = static_cast(client); - wcs.setCACert(_cacert); + 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 diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 2104fb0c..d51abca9 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -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);