diff --git a/README.md b/README.md index b5930eb..f0b8ea9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -WebSocket Server and Client for Arduino [![Build Status](https://github.com/Links2004/arduinoWebSockets/workflows/CI/badge.svg?branch=master)](https://github.com/Links2004/arduinoWebSockets/actions?query=workflow%3ACI+branch%3Amaster) +WebSocket Server and Client for Arduino [![Build Status](https://github.com/Links2004/arduinoWebSockets/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/Links2004/arduinoWebSockets/actions?query=branch%3Amaster) =========================================== a WebSocket Server and Client for Arduino based on RFC6455. @@ -74,19 +74,19 @@ The mode can be activated in the ```WebSockets.h``` (see WEBSOCKETS_NETWORK_TYPE ```c++ void begin(const char *host, uint16_t port, const char * url = "/", const char * protocol = "arduino"); void begin(String host, uint16_t port, String url = "/", String protocol = "arduino"); - ``` +``` - `onEvent`: Callback to handle for websocket events - ```c++ +```c++ void onEvent(WebSocketClientEvent cbEvent); - ``` +``` - `WebSocketClientEvent`: Handler for websocket events - ```c++ +```c++ void (*WebSocketClientEvent)(WStype_t type, uint8_t * payload, size_t length) - ``` +``` Where `WStype_t type` is defined as: - ```c++ +```c++ typedef enum { WStype_ERROR, WStype_DISCONNECTED, @@ -100,13 +100,11 @@ Where `WStype_t type` is defined as: WStype_PING, WStype_PONG, } WStype_t; - ``` +``` ### Issues ### Submit issues to: https://github.com/Links2004/arduinoWebSockets/issues -[![Join the chat at https://gitter.im/Links2004/arduinoWebSockets](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Links2004/arduinoWebSockets?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - ### License and credits ### The library is licensed under [LGPLv2.1](https://github.com/Links2004/arduinoWebSockets/blob/master/LICENSE) diff --git a/examples/esp32/WebSocketClientSSLBundle/WebSocketClientSSLBundle.ino b/examples/esp32/WebSocketClientSSLBundle/WebSocketClientSSLBundle.ino index b9385a7..f64cc58 100644 --- a/examples/esp32/WebSocketClientSSLBundle/WebSocketClientSSLBundle.ino +++ b/examples/esp32/WebSocketClientSSLBundle/WebSocketClientSSLBundle.ino @@ -112,7 +112,13 @@ void setup() { // server address, port and URL. This server can be flakey. // Expected response: Request served by 0123456789abcdef // webSocket.beginSslWithBundle("echo.websocket.org", 443, "/", rootca_crt_bundle_start, ""); + // ESP32 3.0.4 or higher needs the size of the bundle + // webSocket.beginSslWithBundle("echo.websocket.org", 443, "/", rootca_crt_bundle_start, sizeof(rootca_crt_bundle_start), ""); +#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4) + webSocket.beginSslWithBundle("echo.websocket.org", 443, "/", NULL, 0, ""); +#else webSocket.beginSslWithBundle("echo.websocket.org", 443, "/", NULL, ""); +#endif // event handler webSocket.onEvent(webSocketEvent); diff --git a/library.json b/library.json index d51149f..6869b8c 100644 --- a/library.json +++ b/library.json @@ -21,5 +21,5 @@ "type": "git", "url": "https://github.com/Links2004/arduinoWebSockets.git" }, - "version": "2.5.1" -} + "version": "2.5.2" +} \ No newline at end of file diff --git a/library.properties b/library.properties index 462efc5..ceb4a3f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WebSockets -version=2.5.1 +version=2.5.2 author=Markus Sattler maintainer=Markus Sattler sentence=WebSockets for Arduino (Server + Client) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 8578f4b..78512e3 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -50,6 +50,9 @@ void WebSocketsClient::begin(const char * host, uint16_t port, const char * url, _CA_cert = NULL; #ifdef ESP32 _CA_bundle = NULL; +#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4) + _CA_bundle_size = 0; +#endif #endif #endif @@ -124,6 +127,17 @@ void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const ch _CA_cert = CA_cert; _CA_bundle = NULL; } + +#if defined(ESP32) && ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4) +void WebSocketsClient::beginSslWithBundle(const char * host, uint16_t port, const char * url, const uint8_t * CA_bundle, size_t CA_bundle_size, const char * protocol) { + begin(host, port, url, protocol); + _client.isSSL = true; + _fingerprint = SSL_FINGERPRINT_NULL; + _CA_cert = NULL; + _CA_bundle = CA_bundle; + _CA_bundle_size = CA_bundle_size; +} +#else void WebSocketsClient::beginSslWithBundle(const char * host, uint16_t port, const char * url, const uint8_t * CA_bundle, const char * protocol) { begin(host, port, url, protocol); _client.isSSL = true; @@ -131,6 +145,7 @@ void WebSocketsClient::beginSslWithBundle(const char * host, uint16_t port, cons _CA_cert = NULL; _CA_bundle = CA_bundle; } +#endif #else void WebSocketsClient::beginSSL(const char * host, uint16_t port, const char * url, const uint8_t * fingerprint, const char * protocol) { @@ -247,9 +262,11 @@ void WebSocketsClient::loop(void) { #if defined(ESP32) } else if(_CA_bundle) { DEBUG_WEBSOCKETS("[WS-Client] setting CA bundle"); +#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4) + _client.ssl->setCACertBundle(_CA_bundle, _CA_bundle_size); +#else _client.ssl->setCACertBundle(_CA_bundle); #endif -#if defined(ESP32) } else if(!SSL_FINGERPRINT_IS_SET) { _client.ssl->setInsecure(); #elif defined(SSL_BARESSL) diff --git a/src/WebSocketsClient.h b/src/WebSocketsClient.h index 081e37e..c2a6b92 100644 --- a/src/WebSocketsClient.h +++ b/src/WebSocketsClient.h @@ -54,8 +54,12 @@ class WebSocketsClient : protected WebSockets { #endif void beginSslWithCA(const char * host, uint16_t port, const char * url = "/", const char * CA_cert = NULL, const char * protocol = "arduino"); #ifdef ESP32 +#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4) + void beginSslWithBundle(const char * host, uint16_t port, const char * url = "/", const uint8_t * CA_bundle = NULL, size_t CA_bundle_size = 0, const char * protocol = "arduino"); +#else void beginSslWithBundle(const char * host, uint16_t port, const char * url = "/", const uint8_t * CA_bundle = NULL, const char * protocol = "arduino"); #endif +#endif #endif void beginSocketIO(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); @@ -116,6 +120,11 @@ class WebSocketsClient : protected WebSockets { String _fingerprint; const char * _CA_cert; const uint8_t * _CA_bundle; +#if defined(ESP32) +#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4) + size_t _CA_bundle_size; +#endif +#endif #define SSL_FINGERPRINT_IS_SET (_fingerprint.length()) #define SSL_FINGERPRINT_NULL "" #else diff --git a/src/WebSocketsVersion.h b/src/WebSocketsVersion.h index 9c69078..76bacef 100644 --- a/src/WebSocketsVersion.h +++ b/src/WebSocketsVersion.h @@ -1,6 +1,6 @@ /** * @file WebSocketsVersion.h - * @date 17.06.2024 + * @date 29.07.2024 * @author Markus Sattler * * Copyright (c) 2015 Markus Sattler. All rights reserved. @@ -25,12 +25,12 @@ #ifndef WEBSOCKETSVERSION_H_ #define WEBSOCKETSVERSION_H_ -#define WEBSOCKETS_VERSION "2.5.1" +#define WEBSOCKETS_VERSION "2.5.2" #define WEBSOCKETS_VERSION_MAJOR 2 #define WEBSOCKETS_VERSION_MINOR 5 -#define WEBSOCKETS_VERSION_PATCH 1 +#define WEBSOCKETS_VERSION_PATCH 2 -#define WEBSOCKETS_VERSION_INT 2005001 +#define WEBSOCKETS_VERSION_INT 2005002 #endif /* WEBSOCKETSVERSION_H_ */