8000 use String to store fingerprint · lasseod/arduinoWebSockets@848979e · GitHub
[go: up one dir, main page]

Skip to content

Commit 848979e

Browse files
committed
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)
1 parent 167e618 commit 848979e

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

src/WebSockets.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ typedef struct {
118118
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
119119
bool isSSL; ///< run in ssl mode
120120
WiFiClientSecure * ssl;
121-
const char * fingerprint;
122121
#endif
123122

124123
String cUrl; ///< http url

src/WebSocketsClient.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ WebSocketsClient::~WebSocketsClient() {
4040
void WebSocketsClient::begin(const char *host, uint16_t port, const char * url) {
4141
_host = host;
4242
_port = port;
43+
_fingerprint = "";
4344

4445
_client.num = 0;
4546
_client.status = WSC_NOT_CONNECTED;
4647
_client.tcp = NULL;
4748
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
4849
_client.isSSL = false;
4950
_client.ssl = NULL;
50-
_client.fingerprint = NULL;
5151
#endif
5252
_client.cUrl = url;
5353
_client.cCode = 0;
@@ -72,24 +72,14 @@ void WebSocketsClient::begin(String host, uint16_t port, String url) {
7272
}
7373

7474
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
75-
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url) {
76-
begin(host, port, url);
77-
_client.isSSL = true;
78-
}
79-
80-
void WebSocketsClient::beginSSL(String host, uint16_t port, String url) {
81-
beginSSL(host.c_str(), port, url.c_str());
82-
}
83-
8475
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint) {
8576
begin(host, port, url);
8677
_client.isSSL = true;
87-
_client.fingerprint = fingerprint;
78+
_fingerprint = fingerprint;
8879
}
8980

90-
void WebSocketsClient::beginSSL(String host, uint16_t port, String url, const char * fingerprint) {
91-
beginSSL(host.c_str(), port, url.c_str());
92-
_client.fingerprint = fingerprint;
81+
void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String fingerprint) {
82+
beginSSL(host.c_str(), port, url.c_str(), fingerprint.c_str());
9383
}
9484
#endif
9585

@@ -136,9 +126,9 @@ void WebSocketsClient::loop(void) {
136126

137127
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
138128
_client.tcp->setNoDelay(true);
139-
140-
if (_client.isSSL && _client.fingerprint != NULL) {
141-
if (!(((WiFiClientSecure*)_client.tcp)->verify(_client.fingerprint, _host.c_str()))) {
129+
130+
if(_client.isSSL && _fingerprint.length()) {
131+
if(!_client.ssl->verify(_fingerprint.c_str(), _host.c_str())) {
142132
DEBUG_WEBSOCKETS("[WS-Client] certificate mismatch\n");
143133
WebSockets::clientDisconnect(&_client, 1000);
144134
return;

src/WebSocketsClient.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ class WebSocketsClient: private WebSockets {
4040
void begin(String host, uint16_t port, String url = "/");
4141

4242
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
43-
void beginSSL(const char *host, uint16_t port, const char * url = "/");
44-
void beginSSL(String host, uint16_t port, String url = "/");
45-
void beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint);
46-
void beginSSL(String host, uint16_t port, String url, const char * fingerprint);
43+
void beginSSL(const char *host, uint16_t port, const char * url = "/", const char * = "");
44+
void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "");
4745
#endif
4846

4947
void loop(void);
@@ -65,6 +63,9 @@ class WebSocketsClient: private WebSockets {
6563
String _host;
6664
uint16_t _port;
6765

66+
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
67+
String _fingerprint;
68+
#endif
6869
WSclient_t _client;
6970

7071
WebSocketClientEvent _cbEvent;

0 commit comments

Comments
 (0)
0