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)

This commit is contained in:
Jason K 2017-12-19 08:06:45 -05:00 committed by Me No Dev
parent 75bc1e648b
commit cfbb7300b7
4 changed files with 8 additions and 8 deletions

View File

@ -203,6 +203,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer
if (strlen(CAcert) == 0) { if (strlen(CAcert) == 0) {
return false; return false;
} }
_secure = true;
_transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert));
return true; return true;
} }
@ -217,6 +218,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer
if (strlen(CAcert) == 0) { if (strlen(CAcert) == 0) {
return false; return false;
} }
_secure = true;
_transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key)); _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key));
return true; return true;
} }
@ -561,18 +563,18 @@ int HTTPClient::getSize(void)
*/ */
WiFiClient& HTTPClient::getStream(void) WiFiClient& HTTPClient::getStream(void)
{ {
if(connected()) { if (connected() && !_secure) {
return *_tcp; return *_tcp;
} }
log_d("getStream: not connected"); log_w("getStream: not connected");
static WiFiClient empty; static WiFiClient empty;
return empty; return empty;
} }
/** /**
* returns the stream of the tcp connection * returns a pointer to the stream of the tcp connection
* @return WiFiClient * * @return WiFiClient*
*/ */
WiFiClient* HTTPClient::getStreamPtr(void) WiFiClient* HTTPClient::getStreamPtr(void)
{ {
@ -580,7 +582,7 @@ WiFiClient* HTTPClient::getStreamPtr(void)
return _tcp.get(); return _tcp.get();
} }
log_d("getStreamPtr: not connected"); log_w("getStreamPtr: not connected");
return nullptr; return nullptr;
} }

View File

@ -30,6 +30,7 @@
#include <memory> #include <memory>
#include <Arduino.h> #include <Arduino.h>
#include <WiFiClient.h> #include <WiFiClient.h>
#include <WiFiClientSecure.h>
#define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000) #define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000)

View File

@ -134,7 +134,6 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
} }
int res = send_ssl_data(sslclient, buf, size); int res = send_ssl_data(sslclient, buf, size);
if (res < 0) { if (res < 0) {
stop(); stop();
res = 0; res = 0;
} }
@ -148,7 +147,6 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
} }
int res = get_ssl_receive(sslclient, buf, size); int res = get_ssl_receive(sslclient, buf, size);
if (res < 0) { if (res < 0) {
stop(); stop();
} }
return res; return res;

View File

@ -28,7 +28,6 @@
class WiFiClientSecure : public WiFiClient class WiFiClientSecure : public WiFiClient
{ {
protected: protected:
bool _connected;
sslclient_context *sslclient; sslclient_context *sslclient;
const char *_CA_cert; const char *_CA_cert;