mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Remove axTLS from code and documentation (#7437)
This commit is contained in:
committed by
GitHub
parent
1ead157558
commit
70e4457041
@ -24,16 +24,10 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "ESP8266HTTPClient.h"
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClientSecureAxTLS.h>
|
||||
#endif
|
||||
|
||||
#include <StreamString.h>
|
||||
#include <base64.h>
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
class TransportTraits
|
||||
{
|
||||
public:
|
||||
@ -54,31 +48,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class TLSTraits : public TransportTraits
|
||||
{
|
||||
public:
|
||||
TLSTraits(const String& fingerprint) :
|
||||
_fingerprint(fingerprint)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<WiFiClient> create() override
|
||||
{
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return std::unique_ptr<WiFiClient>(new axTLS::WiFiClientSecure());
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
bool verify(WiFiClient& client, const char* host) override
|
||||
{
|
||||
auto wcs = static_cast<axTLS::WiFiClientSecure&>(client);
|
||||
return wcs.verify(_fingerprint.c_str(), host);
|
||||
}
|
||||
|
||||
protected:
|
||||
String _fingerprint;
|
||||
};
|
||||
|
||||
class BearSSLTraits : public TransportTraits
|
||||
{
|
||||
@ -107,7 +76,6 @@ public:
|
||||
protected:
|
||||
uint8_t _fingerprint[20];
|
||||
};
|
||||
#endif // HTTPCLIENT_1_1_COMPATIBLE
|
||||
|
||||
/**
|
||||
* constructor
|
||||
@ -115,9 +83,7 @@ protected:
|
||||
HTTPClient::HTTPClient()
|
||||
: _client(nullptr), _userAgent(F("ESP8266HTTPClient"))
|
||||
{
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
_tcpDeprecated.reset(nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,13 +117,11 @@ void HTTPClient::clear()
|
||||
* @return success bool
|
||||
*/
|
||||
bool HTTPClient::begin(WiFiClient &client, const String& url) {
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
if(_tcpDeprecated) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
|
||||
_canReuse = false;
|
||||
end();
|
||||
}
|
||||
#endif
|
||||
|
||||
_client = &client;
|
||||
|
||||
@ -190,13 +154,11 @@ bool HTTPClient::begin(WiFiClient &client, const String& url) {
|
||||
*/
|
||||
bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, const String& uri, bool https)
|
||||
{
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
if(_tcpDeprecated) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
|
||||
_canReuse = false;
|
||||
end();
|
||||
}
|
||||
#endif
|
||||
|
||||
_client = &client;
|
||||
|
||||
@ -209,32 +171,6 @@ bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, co
|
||||
}
|
||||
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
bool HTTPClient::begin(String url, String httpsFingerprint)
|
||||
{
|
||||
if(_client && !_tcpDeprecated) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
|
||||
_canReuse = false;
|
||||
end();
|
||||
}
|
||||
|
||||
if (httpsFingerprint.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!beginInternal(url, "https")) {
|
||||
return false;
|
||||
}
|
||||
_transportTraits = TransportTraitsPtr(new TLSTraits(httpsFingerprint));
|
||||
if(!_transportTraits) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] could not create transport traits\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] httpsFingerprint: %s\n", httpsFingerprint.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool HTTPClient::begin(String url, const uint8_t httpsFingerprint[20])
|
||||
{
|
||||
if(_client && !_tcpDeprecated) {
|
||||
@ -279,7 +215,7 @@ bool HTTPClient::begin(String url)
|
||||
_transportTraits = TransportTraitsPtr(new TransportTraits());
|
||||
return true;
|
||||
}
|
||||
#endif // HTTPCLIENT_1_1_COMPATIBLE
|
||||
|
||||
|
||||
bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol)
|
||||
{
|
||||
@ -341,7 +277,7 @@ bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol
|
||||
return true;
|
||||
}
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
|
||||
bool HTTPClient::begin(String host, uint16_t port, String uri)
|
||||
{
|
||||
if(_client && !_tcpDeprecated) {
|
||||
@ -359,38 +295,6 @@ bool HTTPClient::begin(String host, uint16_t port, String uri)
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
bool HTTPClient::begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint)
|
||||
{
|
||||
if (https) {
|
||||
return begin(host, port, uri, httpsFingerprint);
|
||||
} else {
|
||||
return begin(host, port, uri);
|
||||
}
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
bool HTTPClient::begin(String host, uint16_t port, String uri, String httpsFingerprint)
|
||||
{
|
||||
if(_client && !_tcpDeprecated) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
|
||||
_canReuse = false;
|
||||
end();
|
||||
}
|
||||
|
||||
clear();
|
||||
_host = host;
|
||||
_port = port;
|
||||
_uri = uri;
|
||||
|
||||
if (httpsFingerprint.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
_transportTraits = TransportTraitsPtr(new TLSTraits(httpsFingerprint));
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s httpsFingerprint: %s\n", host.c_str(), port, uri.c_str(), httpsFingerprint.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HTTPClient::begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20])
|
||||
{
|
||||
@ -413,7 +317,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const uint8_t htt
|
||||
DEBUG_HTTPCLIENT("\n");
|
||||
return true;
|
||||
}
|
||||
#endif // HTTPCLIENT_1_1_COMPATIBLE
|
||||
|
||||
|
||||
/**
|
||||
* end
|
||||
@ -449,12 +353,10 @@ void HTTPClient::disconnect(bool preserveClient)
|
||||
_client = nullptr;
|
||||
}
|
||||
}
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
if(_tcpDeprecated) {
|
||||
_transportTraits.reset(nullptr);
|
||||
_tcpDeprecated.reset(nullptr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
if (!preserveClient && _client) { // Also destroy _client if not connected()
|
||||
@ -1214,7 +1116,6 @@ bool HTTPClient::connect(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
if(!_client && _transportTraits) {
|
||||
_tcpDeprecated = _transportTraits->create();
|
||||
if(!_tcpDeprecated) {
|
||||
@ -1223,7 +1124,6 @@ bool HTTPClient::connect(void)
|
||||
}
|
||||
_client = _tcpDeprecated.get();
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!_client) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] connect: HTTPClient::begin was not called or returned error\n");
|
||||
@ -1239,14 +1139,11 @@ bool HTTPClient::connect(void)
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u\n", _host.c_str(), _port);
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
if (_tcpDeprecated && !_transportTraits->verify(*_tcpDeprecated, _host.c_str())) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] transport level verify failed\n");
|
||||
_client->stop();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ESP8266
|
||||
_client->setNoDelay(true);
|
||||
|
@ -26,10 +26,6 @@
|
||||
#ifndef ESP8266HTTPClient_H_
|
||||
#define ESP8266HTTPClient_H_
|
||||
|
||||
#ifndef HTTPCLIENT_1_1_COMPATIBLE
|
||||
#define HTTPCLIENT_1_1_COMPATIBLE 1
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <Arduino.h>
|
||||
|
||||
@ -149,10 +145,8 @@ typedef enum {
|
||||
HTTPC_FORCE_FOLLOW_REDIRECTS
|
||||
} followRedirects_t;
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
class TransportTraits;
|
||||
typedef std::unique_ptr<TransportTraits> TransportTraitsPtr;
|
||||
#endif
|
||||
|
||||
class StreamString;
|
||||
|
||||
@ -169,19 +163,14 @@ public:
|
||||
bool begin(WiFiClient &client, const String& url);
|
||||
bool begin(WiFiClient &client, const String& host, uint16_t port, const String& uri = "/", bool https = false);
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
// Plain HTTP connection, unencrypted
|
||||
bool begin(String url) __attribute__ ((deprecated));
|
||||
bool begin(String host, uint16_t port, String uri = "/") __attribute__ ((deprecated));
|
||||
// Use axTLS for secure HTTPS connection
|
||||
bool begin(String url, String httpsFingerprint) __attribute__ ((deprecated));
|
||||
bool begin(String host, uint16_t port, String uri, String httpsFingerprint) __attribute__ ((deprecated));
|
||||
// Use BearSSL for secure HTTPS connection
|
||||
bool begin(String url, const uint8_t httpsFingerprint[20]) __attribute__ ((deprecated));
|
||||
bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20]) __attribute__ ((deprecated));
|
||||
// deprecated, use the overload above instead
|
||||
bool begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint) __attribute__ ((deprecated));
|
||||
#endif
|
||||
|
||||
void end(void);
|
||||
|
||||
@ -249,10 +238,8 @@ protected:
|
||||
int writeToStreamDataBlock(Stream * stream, int len);
|
||||
|
||||
|
||||
#if HTTPCLIENT_1_1_COMPATIBLE
|
||||
TransportTraitsPtr _transportTraits;
|
||||
std::unique_ptr<WiFiClient> _tcpDeprecated;
|
||||
#endif
|
||||
WiFiClient* _client;
|
||||
|
||||
/// request handling
|
||||
|
Reference in New Issue
Block a user