khoih-prog / EthernetWebServer_SSL

Simple TLS/SSL Ethernet WebServer, HTTP Client and WebSocket Client library for for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, ENC28J60 or Teensy 4.1 NativeEthernet/QNEthernet. It now supports Ethernet TLS/SSL Client. The library supports HTTP/HTTPS GET and POST requests, provides argument parsing, handles one client at a time. It supports Arduino boards (SAM DUE, Atmel SAM3X8E ARM Cortex-M3, SAMD21, SAMD51, ESP8266, ESP32, Adafruit nRF52, Teensy boards) using Wiznet W5x00 or ENC28J60 network shields. Ethernet_Generic library is used as default for W5x00 with custom SPI
GNU General Public License v3.0
46 stars 10 forks source link

(EthernetSSLClient)(SSL_ERROR)(m_print_ssl_error): SSL_BR_WRITE_ERROR #21

Closed malbrook closed 2 years ago

malbrook commented 2 years ago

I am using an ESP32 with WIZNET 5500 Ethernet connection, using the AWS_IOT example to connect to an account at AWS I get the following error. 11:14:59.105 -> Attempting MQTT connection to ...myESP32[ETG] socketBegin, protocol = 2 , port = 1035 11:14:59.105 -> [ETG] socketBegin, socket index = 0 11:14:59.105 -> [ETG] socketBegin, prot = 2 , RX_RD = 0 11:14:59.105 -> [ETG] socketSendUDP, OK 11:14:59.151 -> [ETG] socketBegin, protocol = 1 , port = 0 11:14:59.151 -> [ETG] socketBegin, socket index = 0 11:14:59.151 -> [ETG] socketBegin, prot = 1 , RX_RD = 0 11:14:59.198 -> [ETG] socketRecv, cmd RX_RD received = 2144 , RX_RSR remaining = 3332 11:14:59.246 -> [ETG] socketRecv, cmd RX_RD received = 4187 , RX_RSR remaining = 1289 11:14:59.338 -> [ETG] socketRecv, cmd RX_RD received = 5092 , RX_RSR remaining = 384 11:14:59.338 -> [ETG] socketRecv, cmd RX_RD received = 5430 , RX_RSR remaining = 46 11:14:59.338 -> [ETG] socketRecv, cmd RX_RD received = 5476 , RX_RSR remaining = 0 11:15:29.195 -> (EthernetSSLClient)(SSL_ERROR)(m_run_until): SSL internals timed out! This could be an internal error, bad data sent from the server, or data being discarded due to a buffer overflow. If you are using Ethernet, did you modify the library properly (see README)? 11:15:29.195 -> (EthernetSSLClient)(SSL_ERROR)(connected): Not connected because write error is set 11:15:29.242 -> (EthernetSSLClient)(SSL_ERROR)(m_print_ssl_error): SSL_BR_WRITE_ERROR 11:15:29.242 -> (EthernetSSLClient)(SSL_ERROR)(m_start_ssl): Failed to initlalize the SSL layer 11:15:29.242 -> (EthernetSSLClient)(SSL_ERROR)(m_print_br_error): Unknown error code: 0 11:15:29.242 -> failed, rc=-2 try again in 15 seconds This occurs when using EthernetGeneric library and your AWS_IOT example modified to work with my account on AWS.

I have checked that the certificates and setup at AWS are correct by using an ESP32 with the WIFI connection and can connect to the AWS account so I do not think this is related to certificates or other setting on AWS. DEBUG from WiFi 1:34:38.055 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 11:34:38.055 -> configsip: 0, SPIWP:0xee 11:34:38.055 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 11:34:38.055 -> mode:DIO, clock div:2 11:34:38.055 -> load:0x3fff0018,len:4 11:34:38.055 -> load:0x3fff001c,len:1044 11:34:38.055 -> load:0x40078000,len:10124 11:34:38.055 -> load:0x40080400,len:5828 11:34:38.055 -> entry 0x400806a8 11:34:38.571 -> [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY 11:34:38.571 -> [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START 11:34:38.571 -> Connecting to Wi-Fi 11:34:39.037 -> ....[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 4 - STA_CONNECTED 11:34:40.760 -> [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP 11:34:40.760 -> [D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 192.168.1.46, MASK: 255.255.252.0, GW: 192.168.1.254 11:34:41.036 -> .Connecting to AWS IOT[V][ssl_client.cpp:59] start_ssl_client(): Free internal heap before TLS 279632 11:34:41.036 -> [V][ssl_client.cpp:65] start_ssl_client(): Starting socket 11:34:41.129 -> [V][ssl_client.cpp:104] start_ssl_client(): Seeding the random number generator 11:34:41.129 -> [V][ssl_client.cpp:113] start_ssl_client(): Setting up the SSL/TLS structure... 11:34:41.129 -> [V][ssl_client.cpp:129] start_ssl_client(): Loading CA cert 11:34:41.129 -> [V][ssl_client.cpp:178] start_ssl_client(): Loading CRT cert 11:34:41.129 -> [V][ssl_client.cpp:187] start_ssl_client(): Loading private key 11:34:41.129 -> [V][ssl_client.cpp:197] start_ssl_client(): Setting hostname for TLS session... 11:34:41.129 -> [V][ssl_client.cpp:212] start_ssl_client(): Performing the SSL/TLS handshake... 11:34:43.660 -> [D][ssl_client.cpp:225] start_ssl_client(): Protocol is TLSv1.2 Ciphersuite is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 11:34:43.660 -> [D][ssl_client.cpp:227] start_ssl_client(): Record expansion is 29 11:34:43.660 -> [V][ssl_client.cpp:233] start_ssl_client(): Verifying peer X.509 certificate... 11:34:43.660 -> [V][ssl_client.cpp:242] start_ssl_client(): Certificate verified. 11:34:43.660 -> [V][ssl_client.cpp:257] start_ssl_client(): Free internal heap after TLS 233264 11:34:43.660 -> [V][ssl_client.cpp:295] send_ssl_data(): Writing HTTP request with 21 bytes... 11:34:43.799 -> . 11:34:43.799 -> [V][ssl_client.cpp:295] send_ssl_data(): Writing HTTP request with 16 bytes... 11:34:44.032 -> AWS IoT Connected! 11:34:44.032 -> Publish 11:34:44.032 -> [V][ssl_client.cpp:295] send_ssl_data(): Writing HTTP request with 86 bytes... 11:34:44.032 -> Waiting

A logic analyser shows that the SPI bus is working as expected at 25MHz clock and the Wiznet is connecting to the Internet via the local network also evidenced by the debug output, using DHCP to connect. 11:14:59.105 -> Connected! IP address: 192.168.2.156

khoih-prog commented 2 years ago

11:15:29.195 -> (EthernetSSLClient)(SSL_ERROR)(m_run_until): SSL internals timed out! This could be an internal error, bad data sent from the server, or data being discarded due to a buffer overflow. If you are using Ethernet, did you modify the library properly (see README)?

Sorry, only you can debug and know what's going on there.

Start using the other SSL examples and have some experience and verify the Ethernet hardware / network is OK first.

Remember that ESP32 WiFi uses core's SSL client / CA Certs, where the EthernetSSLClient does not. You have to be sure the CA Certs, etc are correct and up-to-date. Also check if the system time is updated as discussed in Disabled SSL verification? #18

If still not working, try to use the original SSL example EthernetAWSIoT to be sure your Ethernet hardware, CA Certs, etc. are OK. If not, post an issue in OPEnSLab-OSU SSLClient Issues

I'm closing the issue now and won't reopen until you prove this is a bug of this library.

Good Luck,