Extend HTTPClient to allow connecting with a client certificate (#788)
* Forward client certificate to wificlient secure * remove comment
This commit is contained in:
parent
0768590332
commit
36dba996c1
@ -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<WiFiClientSecure&>(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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user