ESP32 MQTT over TLS 1.3 not working

Chozmao
Posts: 4
Joined: Wed Mar 30, 2022 4:35 pm

ESP32 MQTT over TLS 1.3 not working

Postby Chozmao » Sat Apr 02, 2022 3:10 pm

Hi,
anyone tried new TLS 1.3 feature?
I upgraded esp-idf to 5.0 and mbedtls in component to the branch mbedtls-3.1.0-idf
After the TLS handshake is over, the client receives "MBEDTLS_SSL_HS_NEW_SESSION_TICKET" packet.
And then post_handshake function directly returns with "UNEXPECTED_MESSAGE".
TLS connection is then break up.
in source code:

Code: Select all

static int ssl_handle_hs_message_post_handshake( mbedtls_ssl_context *ssl )
{
    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;

    /*
     * - For client-side, expect SERVER_HELLO_REQUEST.
     * - For server-side, expect CLIENT_HELLO.
     * - Fail (TLS) or silently drop record (DTLS) in other cases.
     */

#if defined(MBEDTLS_SSL_CLI_C)
    if( ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT &&
        ( ssl->in_msg[0] != MBEDTLS_SSL_HS_HELLO_REQUEST ||
          ssl->in_hslen  != mbedtls_ssl_hs_hdr_len( ssl ) ) )
    {
        MBEDTLS_SSL_DEBUG_MSG( 1, ( "handshake received (not HelloRequest)" ) );

        /* With DTLS, drop the packet (probably from last handshake) */
#if defined(MBEDTLS_SSL_PROTO_DTLS)
        if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
        {
            return( 0 );
        }
#endif
        MBEDTLS_SSL_DEBUG_MSG( 1, ("my debug msg: post ssl handshake '%d'", ssl->in_msg[0]));
            return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
    }
#endif /* MBEDTLS_SSL_CLI_C */
my debug log:

Code: Select all

I (3606) mbedtls: ssl_tls13_client.c:1723 tls13 client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP(15)

W (3616) mbedtls: ssl_tls13_client.c:1705 Switch to application keys for inbound traffic

W (3626) mbedtls: ssl_tls13_client.c:1708 Switch to application keys for outbound traffic

I (3636) mbedtls: ssl_tls.c:5323 <= handshake

I (3646) mbedtls: ssl_msg.c:5348 => write

I (3646) mbedtls: ssl_msg.c:2369 => write record

I (3656) mbedtls: ssl_msg.c:546 => encrypt buf

I (3656) mbedtls: ssl_msg.c:990 <= encrypt buf

I (3666) mbedtls: ssl_msg.c:1789 => flush output

I (3666) mbedtls: ssl_msg.c:1809 message length: 53, out_left: 53

I (3676) mbedtls: ssl_msg.c:1814 ssl->f_send() returned 53 (-0xffffffcb)

I (3686) mbedtls: ssl_msg.c:1842 <= flush output

I (3686) mbedtls: ssl_msg.c:2514 <= write record

I (3696) mbedtls: ssl_msg.c:5372 <= write

I (3696) mbedtls: ssl_msg.c:5067 => read

I (3706) mbedtls: ssl_msg.c:3546 => read record

I (3706) mbedtls: ssl_msg.c:1573 => fetch input

I (3716) mbedtls: ssl_msg.c:1730 in_left: 0, nb_want: 5

I (3716) mbedtls: ssl_msg.c:1755 in_left: 0, nb_want: 5

I (3726) mbedtls: ssl_msg.c:1756 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (3736) mbedtls: ssl_msg.c:1776 <= fetch input

I (3736) mbedtls: ssl_msg.c:1573 => fetch input

I (3746) mbedtls: ssl_msg.c:1730 in_left: 5, nb_want: 255

I (3756) mbedtls: ssl_msg.c:1755 in_left: 5, nb_want: 255

I (3756) mbedtls: ssl_msg.c:1756 ssl->f_recv(_timeout)() returned 250 (-0xffffff06)

I (3766) mbedtls: ssl_msg.c:1776 <= fetch input

I (3776) mbedtls: ssl_msg.c:1014 => decrypt buf

I (3776) mbedtls: ssl_msg.c:1539 <= decrypt buf

I (3786) mbedtls: ssl_msg.c:3620 <= read record

W (3786) mbedtls: ssl_msg.c:4967 handshake received (not HelloRequest)

W (3796) mbedtls: ssl_msg.c:4976 my debug msg: post ssl handshake '4'

Chozmao
Posts: 4
Joined: Wed Mar 30, 2022 4:35 pm

Re: ESP32 MQTT over TLS 1.3 not working

Postby Chozmao » Mon Apr 04, 2022 9:22 pm


Who is online

Users browsing this forum: No registered users and 74 guests