ESP-TLS (mbedTLS) connection to IMAPS socket stuck in init state.

tschak909
Posts: 36
Joined: Mon Oct 26, 2020 8:17 pm

ESP-TLS (mbedTLS) connection to IMAPS socket stuck in init state.

Postby tschak909 » Wed May 05, 2021 5:50 pm

I am currently trying to implement an IMAP adapter for #FujiNet, and am testing against GMAIL's IMAP adapter.

I have verified that I can connect to GMAIL's IMAP adapter with the openssl s_client, and issue commands, on my development PC.

However, when setting up a connection using ESP-TLS, I am getting a connection that, even though I am using esp_tls_connection_new_sync() I seem to be getting a connection that returns successful, yet the conn_status seems to be stuck in init.

I have set up cfg as a mostly empty struct, with the exception that I am using the embeddable Root CA bundle:

(and yes, the root CA bundle has been enabled in the SDK menuconfig)

Code: Select all

    memset(&cfg, 0, sizeof(esp_tls_cfg_t));
    cfg.crt_bundle_attach = esp_crt_bundle_attach; // ensure we use root CA bundle
    conn = nullptr;
and I am attempting to test the connection with this function:

Code: Select all

/**
 * @brief Open connection to the protocol using URL
 * @param urlParser The URL object passed in to open.
 * @param cmdFrame The command frame to extract aux1/aux2/etc.
 */
bool NetworkProtocolIMAP::open(EdUrlParser *urlParser, cmdFrame_t *cmdFrame)
{
    memset(buf, 0, sizeof(buf));

    Debug_printf("Opening SSL connection to %s\n", urlParser->hostName.c_str());
    conn = esp_tls_init();
    int connStatus = esp_tls_conn_new_sync(urlParser->hostName.c_str(), urlParser->hostName.length(), 993, &cfg, conn);

    if (conn == nullptr)
    {
        Debug_printf("Could not open connection.\n");
        error = NETWORK_ERROR_COULD_NOT_ALLOCATE_BUFFERS;
        return true;
    }
    else if (connStatus == -1)
    {
        Debug_printf("Connection failed\n");
        error = NETWORK_ERROR_COULD_NOT_ALLOCATE_BUFFERS;
        return true;
    }
    else if (connStatus == 1)
    {
        Debug_printf("Connection successful.\n");
    }

    fnSystem.delay(10000);

    Debug_printf("conn state is: ");
    switch (conn->conn_state)
    {
    case ESP_TLS_INIT:
        Debug_printf("init\n");
        break;
    case ESP_TLS_CONNECTING:
        Debug_printf("connecting\n");
        break;
    case ESP_TLS_HANDSHAKE:
        Debug_printf("handshake\n");
        break;
    case ESP_TLS_FAIL:
        Debug_printf("fail\n");
        break;
    case ESP_TLS_DONE:
        Debug_printf("Done\n");
        break;
    }

    ssize_t s = esp_tls_conn_read(conn, buf, sizeof(buf)); // CRASHES HERE
    Debug_printf("Data read: %s\n",buf);

    return false;
}
but I get back:

Code: Select all

CF: 71 4f 0c 00 cc
sioNetwork::sio_process 0x4f 'O': 0x0c, 0x00
sioNetwork::sio_open()

ACK!
<-SIO read 256 bytes
ACK!
sioNetwork::parseURL(N:IMAP://IMAP.GMAIL.COM/)
sioNetwork::parseURL transformed to (N:IMAP://IMAP.GMAIL.COM/, IMAP://IMAP.GMAIL.COM/)
Parse and instantiate protocol: N:IMAP://IMAP.GMAIL.COM/
NetworkProtocol::ctor()
NetworkProtocolIMAP::ctor
sioNetwork::open_protocol() - Protocol IMAP opened.
Opening SSL connection to IMAP.GMAIL.COM
Connection successful.
conn state is: init

Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x00000060  PS      : 0x00060330  A0      : 0x800deb7b  A1      : 0x3fff65a0
A2      : 0x00000060  A3      : 0x61747320  A4      : 0x3fffc008  A5      : 0x3fff6590
A6      : 0x00000008  A7      : 0x00000000  A8      : 0x80213d14  A9      : 0x3fff6550
A10     : 0x3fffc118  A11     : 0x3fffc008  A12     : 0x00000100  A13     : 0x3fffbfc8
A14     : 0x3fffc118  A15     : 0x3fffbe58  SAR     : 0x00000008  EXCCAUSE: 0x00000014
EXCVADDR: 0x00000060  LBEG    : 0x40093232  LEND    : 0x4009323d  LCOUNT  : 0x00000000

Backtrace:0x0000005d:0x3fff65a0 |<-CORRUPTED
  #0  0x0000005d:0x3fff65a0 in ?? ??:0


ELF file SHA256: 768576170599e239

Rebooting...
What could be going on, here?

-Thom

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: ESP-TLS (mbedTLS) connection to IMAPS socket stuck in init state.

Postby ESP_YJM » Thu May 06, 2021 2:52 am

What IDF version you used.

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: ESP-TLS (mbedTLS) connection to IMAPS socket stuck in init state.

Postby ESP_YJM » Thu May 06, 2021 2:54 am

It is not recommend that use esp-tls component directly. You can use tcp_transport component API to create TCP/TLS connection which like esp_http_client component logic.

tschak909
Posts: 36
Joined: Mon Oct 26, 2020 8:17 pm

Re: ESP-TLS (mbedTLS) connection to IMAPS socket stuck in init state.

Postby tschak909 » Thu May 06, 2021 3:05 am

Can you point me in the right direction?

I am using IDF 4.0 .

-Thom

tschak909
Posts: 36
Joined: Mon Oct 26, 2020 8:17 pm

Re: ESP-TLS (mbedTLS) connection to IMAPS socket stuck in init state.

Postby tschak909 » Sat May 29, 2021 11:09 pm

still stuck on this.

-Thom

Who is online

Users browsing this forum: No registered users and 139 guests