From cfbb7300b768a1ecd7f1300ecac044268153e78b Mon Sep 17 00:00:00 2001 From: Jason K Date: Tue, 19 Dec 2017 08:06:45 -0500 Subject: [PATCH] Update to make use of SSL a bit less confusing by ensuring errors are generated if the wrong method is called to retrieve the data stream. (#934) --- libraries/HTTPClient/src/HTTPClient.cpp | 12 +++++++----- libraries/HTTPClient/src/HTTPClient.h | 1 + libraries/WiFiClientSecure/src/WiFiClientSecure.cpp | 2 -- libraries/WiFiClientSecure/src/WiFiClientSecure.h | 1 - 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index 120cb9af..1c604d56 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -203,6 +203,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer if (strlen(CAcert) == 0) { return false; } + _secure = true; _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); return true; } @@ -217,6 +218,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer if (strlen(CAcert) == 0) { return false; } + _secure = true; _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key)); return true; } @@ -561,18 +563,18 @@ int HTTPClient::getSize(void) */ WiFiClient& HTTPClient::getStream(void) { - if(connected()) { + if (connected() && !_secure) { return *_tcp; } - log_d("getStream: not connected"); + log_w("getStream: not connected"); static WiFiClient empty; return empty; } /** - * returns the stream of the tcp connection - * @return WiFiClient * + * returns a pointer to the stream of the tcp connection + * @return WiFiClient* */ WiFiClient* HTTPClient::getStreamPtr(void) { @@ -580,7 +582,7 @@ WiFiClient* HTTPClient::getStreamPtr(void) return _tcp.get(); } - log_d("getStreamPtr: not connected"); + log_w("getStreamPtr: not connected"); return nullptr; } diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index d51abca9..b1570e1d 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -30,6 +30,7 @@ #include #include #include +#include #define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000) diff --git a/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp b/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp index f1716c69..46c69af3 100644 --- a/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp +++ b/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp @@ -134,7 +134,6 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size) } int res = send_ssl_data(sslclient, buf, size); if (res < 0) { - stop(); res = 0; } @@ -148,7 +147,6 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size) } int res = get_ssl_receive(sslclient, buf, size); if (res < 0) { - stop(); } return res; diff --git a/libraries/WiFiClientSecure/src/WiFiClientSecure.h b/libraries/WiFiClientSecure/src/WiFiClientSecure.h index 102bd49f..d5ce9268 100644 --- a/libraries/WiFiClientSecure/src/WiFiClientSecure.h +++ b/libraries/WiFiClientSecure/src/WiFiClientSecure.h @@ -28,7 +28,6 @@ class WiFiClientSecure : public WiFiClient { protected: - bool _connected; sslclient_context *sslclient; const char *_CA_cert;