use String to store fingerprint

(const char * can be invalidate based on which scope it coming from)
move _fingerprint to Client class only (server not need it)
This commit is contained in:
Markus Sattler
2015-12-24 12:58:05 +01:00
parent 167e61823c
commit 848979ecf0
3 changed files with 12 additions and 22 deletions

View File

@ -118,7 +118,6 @@ typedef struct {
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
bool isSSL; ///< run in ssl mode bool isSSL; ///< run in ssl mode
WiFiClientSecure * ssl; WiFiClientSecure * ssl;
const char * fingerprint;
#endif #endif
String cUrl; ///< http url String cUrl; ///< http url

View File

@ -40,6 +40,7 @@ WebSocketsClient::~WebSocketsClient() {
void WebSocketsClient::begin(const char *host, uint16_t port, const char * url) { void WebSocketsClient::begin(const char *host, uint16_t port, const char * url) {
_host = host; _host = host;
_port = port; _port = port;
_fingerprint = "";
_client.num = 0; _client.num = 0;
_client.status = WSC_NOT_CONNECTED; _client.status = WSC_NOT_CONNECTED;
@ -47,7 +48,6 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url)
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
_client.isSSL = false; _client.isSSL = false;
_client.ssl = NULL; _client.ssl = NULL;
_client.fingerprint = NULL;
#endif #endif
_client.cUrl = url; _client.cUrl = url;
_client.cCode = 0; _client.cCode = 0;
@ -72,24 +72,14 @@ void WebSocketsClient::begin(String host, uint16_t port, String url) {
} }
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url) {
begin(host, port, url);
_client.isSSL = true;
}
void WebSocketsClient::beginSSL(String host, uint16_t port, String url) {
beginSSL(host.c_str(), port, url.c_str());
}
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint) { void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint) {
begin(host, port, url); begin(host, port, url);
_client.isSSL = true; _client.isSSL = true;
_client.fingerprint = fingerprint; _fingerprint = fingerprint;
} }
void WebSocketsClient::beginSSL(String host, uint16_t port, String url, const char * fingerprint) { void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String fingerprint) {
beginSSL(host.c_str(), port, url.c_str()); beginSSL(host.c_str(), port, url.c_str(), fingerprint.c_str());
_client.fingerprint = fingerprint;
} }
#endif #endif
@ -136,9 +126,9 @@ void WebSocketsClient::loop(void) {
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
_client.tcp->setNoDelay(true); _client.tcp->setNoDelay(true);
if (_client.isSSL && _client.fingerprint != NULL) { if(_client.isSSL && _fingerprint.length()) {
if (!(((WiFiClientSecure*)_client.tcp)->verify(_client.fingerprint, _host.c_str()))) { if(!_client.ssl->verify(_fingerprint.c_str(), _host.c_str())) {
DEBUG_WEBSOCKETS("[WS-Client] certificate mismatch\n"); DEBUG_WEBSOCKETS("[WS-Client] certificate mismatch\n");
WebSockets::clientDisconnect(&_client, 1000); WebSockets::clientDisconnect(&_client, 1000);
return; return;

View File

@ -40,10 +40,8 @@ class WebSocketsClient: private WebSockets {
void begin(String host, uint16_t port, String url = "/"); void begin(String host, uint16_t port, String url = "/");
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
void beginSSL(const char *host, uint16_t port, const char * url = "/"); void beginSSL(const char *host, uint16_t port, const char * url = "/", const char * = "");
void beginSSL(String host, uint16_t port, String url = "/"); void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "");
void beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint);
void beginSSL(String host, uint16_t port, String url, const char * fingerprint);
#endif #endif
void loop(void); void loop(void);
@ -65,6 +63,9 @@ class WebSocketsClient: private WebSockets {
String _host; String _host;
uint16_t _port; uint16_t _port;
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
String _fingerprint;
#endif
WSclient_t _client; WSclient_t _client;
WebSocketClientEvent _cbEvent; WebSocketClientEvent _cbEvent;