ESP8266 SSL server breaks the connection after several seconds

jj2497
Posts: 6
Joined: Wed Oct 18, 2017 6:55 pm

ESP8266 SSL server breaks the connection after several seconds

Postby jj2497 » Wed Oct 18, 2017 7:11 pm

Hello,

I encountered one issue related to SSL server on ESP8266 device. (ESP8266_NONOS_SDK-2.1.0)
I create a self-certified certificate (of course, a private key). And I started SSL server as the following code.

Code: Select all

    espconn_secure_set_default_certificate (default_certificate, default_certificate_len);
    espconn_secure_set_default_private_key (default_private_key, default_private_key_len);
    espconn_secure_accept (&esp_conn);

Connections from Android device or PC seem all right. But, after a few seconds, my ESP8266 device will break those connections automatically.

Code: Select all

server handshake start.
server handshake ok!
[Callback] Client 172.16.1.126:51689 disconnect

I got the same result when execute command in SDK environment:

Code: Select all

openssl s_client -connect 172.16.1.164:11830 -state -debug

Partial output is

Code: Select all

SSL-Session:
    Protocol  : TLSv1.1
    Cipher    : AES256-SHA
    Session-ID: D2A7812E5CCF18A24E90C1619BBC677BD1870469A84BACADF7ABC1039384CE71
    Session-ID-ctx:
    Master-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1508323128
    Timeout   : 300 (sec)
    Verify return code: 21 (unable to verify the first certificate)
---
read:errno=0
SSL3 alert write:warning:close notify
read from 0x9f4d250 [0x9f52a83] (5 bytes => 0 (0x0))
write to 0x9f4d250 [0x9f56fd3] (53 bytes => 53 (0x35))
0000 - 15 03 02 00 30 42 a6 7a-8b 14 b3 e0 5f 2b 4d 56   ....0B.z...._+MV
0010 - 1b 29 77 9f d7 80 4e cf-07 fd 29 17 69 c6 bf 6c   .)w...N...).i..l
0020 - f7 ed 74 0c 9a 66 99 f2-d6 73 ee e6 71 13 9f c4   ..t..f...s..q...
0030 - c8 93 ac f1 32                                    ....2


Can anyone help me?

Junhao
Posts: 1
Joined: Thu Oct 19, 2017 9:44 am

Re: ESP8266 SSL server breaks the connection after several seconds

Postby Junhao » Thu Oct 19, 2017 10:14 am

Hi,

It's normal when ESP8266 as server will break those connections automatically after timeout.
You should use espconn_regist_time API to set None SSL connect timeout.
ESP8266 do not have API to modify SSL server disconnect time.
You can modify the follow code to change disconnect time:
pserver->pcommon.timeout = 0x0a;
in function espconn_ssl_server(third_party\mbedtls\app\espconn_mbedtls.c)

jj2497
Posts: 6
Joined: Wed Oct 18, 2017 6:55 pm

Re: ESP8266 SSL server breaks the connection after several seconds

Postby jj2497 » Thu Oct 19, 2017 1:36 pm

Hi JunHao,

Thanks!! I'll modify espconn_mbedtls.c to have a try. :D
I'll post result here after done.

Regards

EDIT: The result is quite good. I changed to "0". Server will keep the connection all the time (at least quite long time for my trial). Thanks again.

Who is online

Users browsing this forum: No registered users and 2 guests