Skip to content

Commit

Permalink
More error checks in WiFiClientSecure
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Sep 28, 2015
1 parent 119512d commit ef26c5f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,19 @@ class SSLContext {

protected:
int _readAll() {
if (!_ssl)
return 0;

uint8_t* data;
int rc = ssl_read(_ssl, &data);
if (rc <= 0)
if (rc <= 0) {
if (rc < SSL_OK && rc != SSL_CLOSE_NOTIFY && rc != SSL_ERROR_CONN_LOST) {
ssl_free(_ssl);
_ssl = nullptr;
}
return 0;
}


if (rc > _rxbuf->room()) {
DEBUGV("WiFiClientSecure rx overflow");
Expand Down Expand Up @@ -219,6 +228,9 @@ int WiFiClientSecure::_connectSSL() {
}

size_t WiFiClientSecure::write(const uint8_t *buf, size_t size) {
if (!_ssl)
return 0;

int rc = ssl_write(*_ssl, buf, size);
if (rc >= 0)
return rc;
Expand All @@ -227,21 +239,43 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size) {
}

int WiFiClientSecure::read(uint8_t *buf, size_t size) {
if (!_ssl)
return 0;

return _ssl->read(buf, size);
}

int WiFiClientSecure::read() {
if (!_ssl)
return -1;

return _ssl->read();
}

int WiFiClientSecure::peek() {
if (!_ssl)
return -1;

return _ssl->peek();
}

int WiFiClientSecure::available() {
if (!_ssl)
return 0;

return _ssl->available();
}

uint8_t WiFiClientSecure::connected() {
if (_client->state() == ESTABLISHED)
return 1;

if (!_ssl)
return 0;

return _ssl->available() > 0;
}

void WiFiClientSecure::stop() {
if (_ssl) {
_ssl->unref();
Expand All @@ -264,6 +298,9 @@ static bool parseHexNibble(char pb, uint8_t* res) {
}

bool WiFiClientSecure::verify(const char* fp, const char* url) {
if (!_ssl)
return false;

uint8_t sha1[20];
int len = strlen(fp);
int pos = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WiFiClientSecure : public WiFiClient {

bool verify(const char* fingerprint, const char* url);

uint8_t connected() override;
size_t write(const uint8_t *buf, size_t size) override;
int read(uint8_t *buf, size_t size) override;
int available() override;
Expand Down

0 comments on commit ef26c5f

Please sign in to comment.