mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-10-02 01:20:57 +02:00
fix(websocket): Update Remaining Websocket Echo Server (#893)
This commit is contained in:
committed by
GitHub
parent
296123c14e
commit
18faeb3dfa
@@ -15,20 +15,28 @@ idf.py build
|
|||||||
## Example Output
|
## Example Output
|
||||||
|
|
||||||
```
|
```
|
||||||
I (164532) websocket: [APP] Startup..
|
I (76826192) websocket: [APP] Startup..
|
||||||
I (164532) websocket: [APP] Free memory: 4294967295 bytes
|
I (76826193) websocket: [APP] Free memory: 4294967295 bytes
|
||||||
I (164532) websocket: [APP] IDF version: v5.3-dev-1353-gb3f7e2c8a4
|
I (76826193) websocket: [APP] IDF version: v6.0-dev-2414-gab3feab1d13
|
||||||
I (164538) websocket: Connecting to ws://echo.websocket.events...
|
I (76826195) websocket: Connecting to wss://echo.websocket.org...
|
||||||
W (164538) websocket_client: `reconnect_timeout_ms` is not set, or it is less than or equal to zero, using default time out 10000 (milliseconds)
|
W (76826195) websocket_client: `reconnect_timeout_ms` is not set, or it is less than or equal to zero, using default time out 10000 (milliseconds)
|
||||||
W (164538) websocket_client: `network_timeout_ms` is not set, or it is less than or equal to zero, using default time out 10000 (milliseconds)
|
W (76826195) websocket_client: `network_timeout_ms` is not set, or it is less than or equal to zero, using default time out 10000 (milliseconds)
|
||||||
I (165103) websocket: WEBSOCKET_EVENT_CONNECTED
|
I (76826195) websocket: WEBSOCKET_EVENT_BEGIN
|
||||||
I (165539) websocket: Sending hello 0000
|
I (76826196) websocket_client: Started
|
||||||
I (165627) websocket: WEBSOCKET_EVENT_DATA
|
I (76826294) esp-x509-crt-bundle: Certificate validated
|
||||||
I (165627) websocket: Received opcode=1
|
I (76827230) websocket: WEBSOCKET_EVENT_CONNECTED
|
||||||
W (165627) websocket: Received=hello 0000
|
I (76827239) websocket: WEBSOCKET_EVENT_DATA
|
||||||
W (165627) websocket: Total payload length=10, data_len=10, current payload offset=0
|
I (76827239) websocket: Received opcode=1
|
||||||
|
W (76827239) websocket: Received=Request served by 4d896d95b55478
|
||||||
|
W (76827239) websocket: Total payload length=32, data_len=32, current payload offset=0
|
||||||
|
|
||||||
I (166539) websocket: Sending fragmented message
|
I (76828198) websocket: Sending hello 0000
|
||||||
|
I (76828827) websocket: WEBSOCKET_EVENT_DATA
|
||||||
|
I (76828827) websocket: Received opcode=1
|
||||||
|
W (76828827) websocket: Received=hello 0000
|
||||||
|
W (76828827) websocket: Total payload length=10, data_len=10, current payload offset=0
|
||||||
|
|
||||||
|
I (76829207) websocket: Sending fragmented text message
|
||||||
```
|
```
|
||||||
|
|
||||||
## Coverage Reporting
|
## Coverage Reporting
|
||||||
|
@@ -8,8 +8,27 @@ menu "Host-test config"
|
|||||||
|
|
||||||
config WEBSOCKET_URI
|
config WEBSOCKET_URI
|
||||||
string "Websocket endpoint URI"
|
string "Websocket endpoint URI"
|
||||||
default "ws://echo.websocket.events"
|
default "wss://echo.websocket.org"
|
||||||
help
|
help
|
||||||
URL of websocket endpoint this example connects to and sends echo
|
URL of websocket endpoint this example connects to and sends echo
|
||||||
|
|
||||||
|
config WS_OVER_TLS_SERVER_AUTH
|
||||||
|
bool "Enable WebSocket over TLS with Server Certificate Verification Only"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Enables WebSocket connections over TLS (WSS) with server certificate verification.
|
||||||
|
The client verifies the server certificate; the server does not require a client certificate.
|
||||||
|
|
||||||
|
config WS_OVER_TLS_MUTUAL_AUTH
|
||||||
|
bool "Enable WebSocket over TLS with Server Client Mutual Authentification"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Enables WebSocket connections over TLS (WSS) with server and client mutual certificate verification.
|
||||||
|
|
||||||
|
config WS_OVER_TLS_SKIP_COMMON_NAME_CHECK
|
||||||
|
bool "Skip common name(CN) check during TLS authentification"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Skip Common Name (CN) check during TLS (WSS) authentication. Use only for testing.
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
|
#include "esp_crt_bundle.h"
|
||||||
|
|
||||||
static const char *TAG = "websocket";
|
static const char *TAG = "websocket";
|
||||||
|
|
||||||
@@ -75,6 +76,33 @@ static void websocket_app_start(void)
|
|||||||
|
|
||||||
websocket_cfg.uri = CONFIG_WEBSOCKET_URI;
|
websocket_cfg.uri = CONFIG_WEBSOCKET_URI;
|
||||||
|
|
||||||
|
#if CONFIG_WS_OVER_TLS_MUTUAL_AUTH
|
||||||
|
/* Configuring client certificates for mutual authentification */
|
||||||
|
extern const char cacert_start[] asm("_binary_ca_cert_pem_start");
|
||||||
|
extern const char cert_start[] asm("_binary_client_cert_pem_start");
|
||||||
|
extern const char cert_end[] asm("_binary_client_cert_pem_end");
|
||||||
|
extern const char key_start[] asm("_binary_client_key_pem_start");
|
||||||
|
extern const char key_end[] asm("_binary_client_key_pem_end");
|
||||||
|
|
||||||
|
websocket_cfg.cert_pem = cacert_start;
|
||||||
|
websocket_cfg.client_cert = cert_start;
|
||||||
|
websocket_cfg.client_cert_len = cert_end - cert_start;
|
||||||
|
websocket_cfg.client_key = key_start;
|
||||||
|
websocket_cfg.client_key_len = key_end - key_start;
|
||||||
|
#elif CONFIG_WS_OVER_TLS_SERVER_AUTH
|
||||||
|
// Using certificate bundle as default server certificate source
|
||||||
|
websocket_cfg.crt_bundle_attach = esp_crt_bundle_attach;
|
||||||
|
// If using a custom certificate it could be added to certificate bundle,
|
||||||
|
// added to the build similar to client certificates in this examples,
|
||||||
|
// or read from NVS.
|
||||||
|
/* extern const char cacert_start[] asm("ADDED_CERTIFICATE"); */
|
||||||
|
/* websocket_cfg.cert_pem = cacert_start; */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_WS_OVER_TLS_SKIP_COMMON_NAME_CHECK
|
||||||
|
websocket_cfg.skip_cert_common_name_check = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Connecting to %s...", websocket_cfg.uri);
|
ESP_LOGI(TAG, "Connecting to %s...", websocket_cfg.uri);
|
||||||
|
|
||||||
esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
|
esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
|
||||||
|
@@ -3,4 +3,4 @@ CONFIG_IDF_TARGET="linux"
|
|||||||
CONFIG_IDF_TARGET_LINUX=y
|
CONFIG_IDF_TARGET_LINUX=y
|
||||||
CONFIG_ESP_EVENT_POST_FROM_ISR=n
|
CONFIG_ESP_EVENT_POST_FROM_ISR=n
|
||||||
CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=n
|
CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=n
|
||||||
CONFIG_WEBSOCKET_URI="ws://echo.websocket.events"
|
CONFIG_WEBSOCKET_URI="wss://echo.websocket.org"
|
||||||
|
@@ -2,4 +2,4 @@ CONFIG_IDF_TARGET="linux"
|
|||||||
CONFIG_IDF_TARGET_LINUX=y
|
CONFIG_IDF_TARGET_LINUX=y
|
||||||
CONFIG_ESP_EVENT_POST_FROM_ISR=n
|
CONFIG_ESP_EVENT_POST_FROM_ISR=n
|
||||||
CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=n
|
CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=n
|
||||||
CONFIG_WEBSOCKET_URI="ws://echo.websocket.events"
|
CONFIG_WEBSOCKET_URI="wss://echo.websocket.org"
|
||||||
|
@@ -2,4 +2,4 @@ CONFIG_IDF_TARGET="linux"
|
|||||||
CONFIG_IDF_TARGET_LINUX=y
|
CONFIG_IDF_TARGET_LINUX=y
|
||||||
CONFIG_ESP_EVENT_POST_FROM_ISR=n
|
CONFIG_ESP_EVENT_POST_FROM_ISR=n
|
||||||
CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=n
|
CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=n
|
||||||
CONFIG_WEBSOCKET_URI="ws://echo.websocket.events"
|
CONFIG_WEBSOCKET_URI="wss://echo.websocket.org"
|
||||||
|
@@ -84,7 +84,7 @@ I (4472) tcpip_adapter: eth ip: 192.168.2.137, mask: 255.255.255.0, gw: 192.168.
|
|||||||
I (4472) example_connect: Connected to Ethernet
|
I (4472) example_connect: Connected to Ethernet
|
||||||
I (4472) example_connect: IPv4 address: 192.168.2.137
|
I (4472) example_connect: IPv4 address: 192.168.2.137
|
||||||
I (4472) example_connect: IPv6 address: fe80:0000:0000:0000:bedd:c2ff:fed4:a92b
|
I (4472) example_connect: IPv6 address: fe80:0000:0000:0000:bedd:c2ff:fed4:a92b
|
||||||
I (4482) WEBSOCKET: Connecting to ws://echo.websocket.events...
|
I (4482) WEBSOCKET: Connecting to wss://echo.websocket.org...
|
||||||
I (5012) WEBSOCKET: WEBSOCKET_EVENT_CONNECTED
|
I (5012) WEBSOCKET: WEBSOCKET_EVENT_CONNECTED
|
||||||
I (5492) WEBSOCKET: Sending hello 0000
|
I (5492) WEBSOCKET: Sending hello 0000
|
||||||
I (6052) WEBSOCKET: WEBSOCKET_EVENT_DATA
|
I (6052) WEBSOCKET: WEBSOCKET_EVENT_DATA
|
||||||
@@ -107,7 +107,7 @@ W (9162) WEBSOCKET: Received=hello 0003
|
|||||||
|
|
||||||
## Python Flask echo server
|
## Python Flask echo server
|
||||||
|
|
||||||
By default, the `ws://echo.websocket.events` endpoint is used. You can setup a Python websocket echo server locally and try the `ws://<your-ip>:5000` endpoint. To do this, install Flask-sock Python package
|
By default, the `wss://echo.websocket.org` endpoint is used. You can setup a Python websocket echo server locally and try the `ws://<your-ip>:5000` endpoint. To do this, install Flask-sock Python package
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install flask-sock
|
pip install flask-sock
|
||||||
|
Reference in New Issue
Block a user