Skip to content

Ensure errors are generated if the wrong method is called to retrieve the SSL data stream. #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions libraries/HTTPClient/src/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -561,26 +563,26 @@ 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)
{
if(connected()) {
return _tcp.get();
}

log_d("getStreamPtr: not connected");
log_w("getStreamPtr: not connected");
return nullptr;
}

Expand Down
1 change: 1 addition & 0 deletions libraries/HTTPClient/src/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <memory>
#include <Arduino.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>

#define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000)

Expand Down
2 changes: 0 additions & 2 deletions libraries/WiFiClientSecure/src/WiFiClientSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion libraries/WiFiClientSecure/src/WiFiClientSecure.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
class WiFiClientSecure : public WiFiClient
{
protected:
bool _connected;
sslclient_context *sslclient;

const char *_CA_cert;
Expand Down