---
Hi everyone!
I'm trying to write a very simple SSL/TLS server. I can connect to it and send and receive data, but when the client closes the connection, discon_cb is not called. Instead I get the following message on the UART: "server's data invalid protocol"
Can anyone tell me what this message means and how I can fix it? Any help would be appreciated.
Here's some more details (sorry it's a bit long):
I'm trying to put a very simple HTTPS server together. For now, all it does is set up a listener, read the incoming data and send a minimal HTTP reply (something like "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-type: text/html\r\nContent-length: 30\r\n\r\n<html><body>Test</body></html>"). Everything works fine when SSL is off.
Now I turn on SSL by doing the following:
- Change all calls of espconn_send to espconn_secure_send.
- Replace espconn_accept with:
Code: Select all
espconn_secure_set_size(0x02, 8192);
espconn_secure_ca_disable(0x02); // Not sure if this is needed, but it shouldn't hurt, right? I'm assuming
// this means "Don't try to authenicate the client".
espconn_secure_accept(&listenConn); - Create a key and a certificate for the ESP, convert it into cert.h and private_key.h as described in the documentation, and include those headers. (By the way, this is a bit odd. I think there should be an API call to set the cert&key. Maybe one which takes a flash sector like espconn_secure_ca_enable does?) I tried a 2048 bit key but that made the ESP crash right away. So I chose a 1024 bit one instead. I pretty much followed the SSL guide PDF except I signed the certificate with my existing CA rather than a newly created one.
This is what happens when I run the thing:
- After espconn_secure_accept I have 36880 free bytes on the heap.
- Connect from a client (Firefox in my case).
- UART prints "server handshake start." and "server handshake ok!"
- connect_cb is called. 17376 free heap. Everything seems fine, IP address etc is correct.
- recv_cb is called. 16976 free heap. Still everything's fine, the received data is exactly what the client sent.
- Calling espconn_secure_send with the HTTP response.
- sent_cb is called. 13712 free heap.
- UART prints "server's data invalid protocol"
The client does receive the data correctly but after that nothing happens. In particular, discon_cb is not called. The ESP seems to hang in a weird limbo state. It does occasionally respond to data sent via UART, but any major operation will make it crash. I assume memory is leaking both internally and in my code since I don't get the discon_cb to free it up.
Another thing I've tried is using sslscan on the ESP. I'm getting this:
Testing SSL server Node001 on port 443
Supported Server Cipher(s):
Failed SSLv3 256 bits ECDHE-RSA-AES256-GCM-SHA384
Failed SSLv3 256 bits ECDHE-ECDSA-AES256-GCM-SHA384
and then the ESP crashes.