1 (edited by KamKon 2018-08-28 02:44:07)

Topic: WolfSSL_read does not return

Dear support team,

I am using WolfSSL 3.15.3 library. I am trying to send e-mail via smpt.gmail.com on port 587. After sending "starttls" command I start tls with wolfSSL_read. This function does not return control to the program. Logs from the WolfSSL library are attached and defined as LOG 1 in logs.txt.

When I pause the program I get the following stack:

    MyCallbackIORecv() at main.c:135 0xc524   
    Receive() at internal.c:2 616 0x1e4ac   
    GetInputData() at internal.c:6 225 0x216fa   
    ProcessReply() at internal.c:6 354 0x2199e   
    ReceiveData() at internal.c:7 593 0x22c04   
    wolfSSL_read_internal() at ssl.c:571 0xdb76   
    wolfSSL_read() at ssl.c:595 0xdbba   
    TLSInit() at main.c:767 0xd112   
    pxPortInitialiseStack() at port.c:233 0x262c

The program does not get below GetInputData. MyCallbackIORecv code:

int MyCallbackIORecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
{
    int recvd, ret;
    int sd = *(int*)ctx;

    recvd = (int)FreeRTOS_recv((void *)sd, buf, sz, 0);

    if(recvd == -pdFREERTOS_ERRNO_ENOTCONN)
        ret=WOLFSSL_CBIO_ERR_CONN_CLOSE;
    else if(recvd == -pdFREERTOS_ERRNO_ENOMEM)
        ret=WOLFSSL_CBIO_ERR_GENERAL;
    else if(recvd == -pdFREERTOS_ERRNO_EINVAL)
        ret=WOLFSSL_CBIO_ERR_GENERAL;
    else if(recvd < 0)
        ret=WOLFSSL_CBIO_ERR_GENERAL;
    else
        ret=recvd;

    return ret;
}

I see that FreeRTOS_recv returns 0, so MyCallbackIORecv do the same. FreeRTOS_recv does not block. When I add the following lines

    else if(recvd == 0)
        ret=WOLFSSL_CBIO_ERR_WANT_READ;

or

    else if(recvd == 0)
        ret=WOLFSSL_CBIO_ERR_WANT_READ;

to MyCallbackIORecv I get the log defined as LOG 2 in the attached file.

I dont know why wolfSSL_read function does not return. Could anyone help me with this?

Regards,
Kamil

Post's attachments

logs.txt 5.87 kb, 6 downloads since 2018-08-28 

You don't have the permssions to download the attachments of this post.

Share

Re: WolfSSL_read does not return

Hi Kamil,

I am looking into the issue you reported. Could you also send a packet capture of the two cases?

Best regards,

Eric Blankenhorn
wolfSSL Support

Re: WolfSSL_read does not return

Hi Kamil,

From the FreeRTOS reference for the FreeRTOS_recv() :

If a time out occurred before data could be received then 0 is returned.

The wolfSSL code is expecting more data at this point, but the OS has timed out waiting. You could try increasing the timeout for the TCP socket, or perhaps the server is not responding. The packet capture could provide some more insight.

Thanks,

Eric Blankenhorn
wolfSSL Support

Re: WolfSSL_read does not return

Thanks for reply embhorn,

I managed that problem. I call some FreeRTOS api function that checks if there is data to be read on a socket. If there is some data then I call wolfSSL_read. The program do not get stuck now. I thought that wolfSSL_read do not block as underlying I/O function does. I use non-blocking option for a SSL object but probably I do something wrong becouse wolfSSL_read still blocks.

Thanks,
Kamil

Share

Re: WolfSSL_read does not return

Hi @KamKon,

Great to hear that you have the library working correctly now. Do you have any further questions or issues?

Best regards,

Eric Blankenhorn
wolfSSL Support

Re: WolfSSL_read does not return

Hi embhorn,

Does the library supports non blocking I/O? I set non blocking option for a SSL object but wolfSS_read still does not return. As I wrote above it can be solved by using additional checking but the question remains.

Thanks,
Kamil

Share

Re: WolfSSL_read does not return

KamKon:

The set-non-blocking function is a do-nothing for TLS sessions, it is meant to be used for DTLS. (We have recently renamed it to reflect this.) For TLS connections, you just need to set the socket to be non-blocking. If the socket would block, wolfSSL_read() will return a WANT_READ error.

--John