WiFiClientSecure::lastError() method (#945)
* Added a lastError method to WiFiClientSecure so that a connection error from mbedTLS can be retrieved if connection fails (and then presented to a user). * Changed to dos CRLF * Made buffer size a const\nMore cleanup to match source
This commit is contained in:
parent
81e0250983
commit
d650ac6c3c
@ -103,6 +103,7 @@ int WiFiClientSecure::connect(IPAddress ip, uint16_t port, const char *_CA_cert,
|
|||||||
int WiFiClientSecure::connect(const char *host, uint16_t port, const char *_CA_cert, const char *_cert, const char *_private_key)
|
int WiFiClientSecure::connect(const char *host, uint16_t port, const char *_CA_cert, const char *_cert, const char *_private_key)
|
||||||
{
|
{
|
||||||
int ret = start_ssl_client(sslclient, host, port, _CA_cert, _cert, _private_key);
|
int ret = start_ssl_client(sslclient, host, port, _CA_cert, _cert, _private_key);
|
||||||
|
_lastError = ret;
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
log_e("lwip_connect_r: %d", errno);
|
log_e("lwip_connect_r: %d", errno);
|
||||||
stop();
|
stop();
|
||||||
@ -187,3 +188,13 @@ void WiFiClientSecure::setPrivateKey (const char *private_key)
|
|||||||
_private_key = private_key;
|
_private_key = private_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WiFiClientSecure::lastError(char *buf, const size_t size)
|
||||||
|
{
|
||||||
|
if (!_lastError) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
char error_buf[100];
|
||||||
|
mbedtls_strerror(_lastError, error_buf, 100);
|
||||||
|
snprintf(buf, size, "%s", error_buf);
|
||||||
|
return _lastError;
|
||||||
|
}
|
||||||
|
@ -29,7 +29,8 @@ class WiFiClientSecure : public WiFiClient
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
sslclient_context *sslclient;
|
sslclient_context *sslclient;
|
||||||
|
|
||||||
|
int _lastError = 0;
|
||||||
const char *_CA_cert;
|
const char *_CA_cert;
|
||||||
const char *_cert;
|
const char *_cert;
|
||||||
const char *_private_key;
|
const char *_private_key;
|
||||||
@ -55,7 +56,7 @@ public:
|
|||||||
void flush() {}
|
void flush() {}
|
||||||
void stop();
|
void stop();
|
||||||
uint8_t connected();
|
uint8_t connected();
|
||||||
|
int lastError(char *buf, const size_t size);
|
||||||
void setCACert(const char *rootCA);
|
void setCACert(const char *rootCA);
|
||||||
void setCertificate(const char *client_ca);
|
void setCertificate(const char *client_ca);
|
||||||
void setPrivateKey (const char *private_key);
|
void setPrivateKey (const char *private_key);
|
||||||
|
Loading…
Reference in New Issue
Block a user