Hello,
I want to open a secure connection to httpbin.org using TLSSocket and then send GET requests.
When using TCPSocket and http, everything works, but when I try the same code with TLS Socket, I get trapped in mbed_die().
Here is the code :
SocketAddress address;
wifi.gethostbyname("httpbin.org", &address);
address.set_port(443);
// TLS socket
TLSSocket *socket = new TLSSocket();
socket->open(&wifi);
socket->set_hostname("httpbin.org");
auto ret = socket->set_root_ca_cert(SSL_CA_CERT);
if (ret != NSAPI_ERROR_OK) {
log_info("Error when setting root ca cert : %d", ret);
while (1) ;
}
ret = socket->connect(address);
if (ret != NSAPI_ERROR_OK) {
log_info("Error when connecting : %d", ret);
while (1);
}
// send GET request ...
In the socket->connect
call, the program freezes because of mbed_die().
Here is the trace :
[DBG ][ESPA]: open_udp(): UDP socket 0 opened: true.
[DBG ][ESPA]: _oob_send_ok_received called for socket 0
[DBG ][ESPA]: _oob_socket0_closed(): Socket 0 closed.
[DBG ][ESPA]: close(0): socket close OK with AT+CIPCLOSE OK
[DBG ][TLSW]: mbedtls_ssl_conf_ca_chain()
[DBG ][ESPA]: open_tcp: TCP socket 0 opened: true .
[INFO][TLSW]: Starting TLS handshake with httpbin.org
[DBG ][TLSW]: mbedtls_ssl_setup()
[DBG ][TLSW]: ssl_tls.c:5688: |2| => handshake
[DBG ][TLSW]: ssl_cli.c:4159: |2| client state: 0
[DBG ][TLSW]: ssl_msg.c:2124: |2| => flush output
[DBG ][TLSW]: ssl_msg.c:2136: |2| <= flush output
[DBG ][TLSW]: ssl_cli.c:4159: |2| client state: 1
[DBG ][TLSW]: ssl_msg.c:2124: |2| => flush output
[DBG ][TLSW]: ssl_msg.c:2136: |2| <= flush output
[DBG ][TLSW]: ssl_cli.c:0872: |2| => write client hello
[DBG ][TLSW]: ssl_msg.c:2560: |2| => write handshake message
[DBG ][TLSW]: ssl_msg.c:2719: |2| => write record
[DBG ][TLSW]: ssl_msg.c:2124: |2| => flush output
[DBG ][TLSW]: ssl_msg.c:2142: |2| message length: 150, out_left: 150
[DBG ][TLSW]: ssl_msg.c:2148: |2| ssl->f_send() returned 150 (-0xffffff6a)
[DBG ][TLSW]: ssl_msg.c:2176: |2| <= flush output
[DBG ][TLSW]: ssl_msg.c:2890: |2| <= write record
[DBG ][TLSW]: ssl_msg.c:2696: |2| <= write handshake message
[DBG ][TLSW]: ssl_cli.c:1331: |2| <= write client hello
[DBG ][TLSW]: ssl_cli.c:4159: |2| client state: 2
[DBG ][TLSW]: ssl_msg.c:2124: |2| => flush output
[DBG ][TLSW]: ssl_msg.c:2136: |2| <= flush output
[DBG ][TLSW]: ssl_cli.c:1816: |2| => parse server hello
[DBG ][TLSW]: ssl_msg.c:3922: |2| => read record
[DBG ][TLSW]: ssl_msg.c:1904: |2| => fetch input
[DBG ][TLSW]: ssl_msg.c:2065: |2| in_left: 0, nb_want: 5
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 0, nb_want: 5
[DBG ][TLSW]: ssl_tls.c:5698: |2| <= handshake
[DBG ][TLSW]: ssl_tls.c:5688: |2| => handshake
[DBG ][TLSW]: ssl_cli.c:4159: |2| client state: 2
[DBG ][TLSW]: ssl_msg.c:2124: |2| => flush output
[DBG ][TLSW]: ssl_msg.c:2136: |2| <= flush output
[DBG ][TLSW]: ssl_cli.c:1816: |2| => parse server hello
[DBG ][TLSW]: ssl_msg.c:3922: |2| => read record
[DBG ][TLSW]: ssl_msg.c:1904: |2| => fetch input
[DBG ][TLSW]: ssl_msg.c:2065: |2| in_left: 0, nb_want: 5
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 0, nb_want: 5
[DBG ][TLSW]: ssl_tls.c:5698: |2| <= handshake
[DBG ][TLSW]: ssl_tls.c:5688: |2| => handshake
[DBG ][TLSW]: ssl_cli.c:4159: |2| client state: 2
[DBG ][TLSW]: ssl_msg.c:2124: |2| => flush output
[DBG ][TLSW]: ssl_msg.c:2136: |2| <= flush output
[DBG ][TLSW]: ssl_cli.c:1816: |2| => parse server hello
[DBG ][TLSW]: ssl_msg.c:3922: |2| => read record
[DBG ][TLSW]: ssl_msg.c:1904: |2| => fetch input
[DBG ][TLSW]: ssl_msg.c:2065: |2| in_left: 0, nb_want: 5
[DBG ][ESPA]: _oob_send_ok_received called for socket 0
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 0, nb_want: 5
[DBG ][TLSW]: ssl_msg.c:2091: |2| ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
[DBG ][TLSW]: ssl_msg.c:2111: |2| <= fetch input
[DBG ][TLSW]: ssl_msg.c:1904: |2| => fetch input
[DBG ][TLSW]: ssl_msg.c:2065: |2| in_left: 5, nb_want: 66
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 5, nb_want: 66
[DBG ][TLSW]: ssl_msg.c:2091: |2| ssl->f_recv(_timeout)() returned 61 (-0xffffffc3)
[DBG ][TLSW]: ssl_msg.c:2111: |2| <= fetch input
[DBG ][TLSW]: ssl_msg.c:3996: |2| <= read record
[DBG ][TLSW]: ssl_cli.c:2128: |2| server hello, total extension length: 17
[DBG ][TLSW]: ssl_cli.c:2343: |2| <= parse server hello
[DBG ][TLSW]: ssl_cli.c:4159: |2| client state: 3
[DBG ][TLSW]: ssl_msg.c:2124: |2| => flush output
[DBG ][TLSW]: ssl_msg.c:2136: |2| <= flush output
[DBG ][TLSW]: ssl_tls.c:2725: |2| => parse certificate
[DBG ][TLSW]: ssl_msg.c:3922: |2| => read record
[DBG ][TLSW]: ssl_msg.c:1904: |2| => fetch input
[DBG ][TLSW]: ssl_msg.c:2065: |2| in_left: 0, nb_want: 5
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 0, nb_want: 5
[DBG ][TLSW]: ssl_msg.c:2091: |2| ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
[DBG ][TLSW]: ssl_msg.c:2111: |2| <= fetch input
[DBG ][TLSW]: ssl_msg.c:1904: |2| => fetch input
[DBG ][TLSW]: ssl_msg.c:2065: |2| in_left: 5, nb_want: 4839
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 5, nb_want: 4839
[DBG ][TLSW]: ssl_msg.c:2091: |2| ssl->f_recv(_timeout)() returned 2048 (-0xfffff800)
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 2053, nb_want: 4839
[DBG ][TLSW]: ssl_msg.c:2091: |2| ssl->f_recv(_timeout)() returned 2033 (-0xfffff80f)
[DBG ][TLSW]: ssl_msg.c:2089: |2| in_left: 4086, nb_want: 4839
[DBG ][TLSW]: ssl_msg.c:2091: |2| ssl->f_recv(_timeout)() returned 753 (-0xfffffd0f)
[DBG ][TLSW]: ssl_msg.c:2111: |2| <= fetch input
[DBG ][TLSW]: ssl_msg.c:3996: |2| <= read record
What can be the cause of this behavior ? The certificate I set should be correct (got it from my browser), I have no idea what can be the cause.
Any help is very welcome, thanks !