I tried so many things but nothing worked. I dont know what to do now.

Hi Kaleb, See-

WOLFSSL *ssl_cmd,  *ssl_data;
WOLFSSL_CTX* ctx=NULL, *ctx1=NULL;

int start_TLS()
{
  
    /// create and other code and using ssl_cmd
   
    // print(value of ssl_cmd= %p,ssl_cmd);
    // values of ssl_cmd=  @00027dfc 
}
int createFtpSocket(char *ipAddress, int portNr)
{

        int status = start_TLS();
        // print(value of ssl_cmd= %p,ssl_cmd);
       // value of ssl_cmd here = @00033170
       // though I am not using this here... but still printing
 
}

bool pmoPosFtpProc(char* result)
{
    int sock = createFtpSocket(g_ftpHost, 21);
    wolfSSL_free(ssl_cmd);
 // value of ssl_cmd here =@0001ebb4
}

Hi Kaleb,
I tried with that also. I made a global variable and used that in all functions. Still getting the problem.
I'll post the pointer values tomorrow.
Thanks

Hi Kaleb,
I tried the same way and still the same problem. I don't know why I am getting this-
See the code in a minimal way this time-

WOLFSSL *ssl_cmd,  *ssl_data;
WOLFSSL_CTX* ctx=NULL, *ctx1=NULL;

int start_TLS(  WOLFSSL **ssl1)
{
    WOLFSSL *ssl;
    /// create and other code
    *ssl1 = ssl;
    // print(value of *ssl1 = %p and ssl = %p", *ssl1, ssl);
    // values of *ssl1= @00026d68 and ssl= @00026d68 
}
int createFtpSocket(char *ipAddress, int portNr)
{
        int status = start_TLS(&ssl_cmd);
       // value of ssl_cmd after start_tls = @00033564
}
bool pmoPosFtpProc(char* result)
{
    int sock = createFtpSocket(g_ftpHost, 21);
    wolfSSL_free(ssl_cmd);
 // value of ssl_cmd here = @0001d938
}

I exactly copied the method given there and fully understood that too and executed on machine also. Some other ways I also tried where the pointers are sync. But here failing.

Hi Kaleb,
I tried that too but could not make it right. Still, I am getting the same error.
I am posting my relevant code. Please check.

WOLFSSL *ssl_cmd=NULL,  *ssl_data=NULL;
WOLFSSL_CTX* ctx=NULL, *ctx1=NULL;
int sock1, sock3;

void exitApp(WOLFSSL_CTX* ctx)
{
    if (ctx != NULL)
    {
        wolfSSL_CTX_free(ctx);
        wolfSSL_Cleanup();
    }
    // BIOS_exit(-1);
}
int start_TLS(  WOLFSSL **ssl)
{
    int ret, valread;
 //   WOLFSSL *ssl;

    Error_Block eb;
    int nbytes;
    char *buffer;
    char msg[50] = { };
    char buff[512];
    memset(buff, 0, 512);

    //   fdOpenSession(TaskSelf());
    Error_init(&eb);
    wolfSSL_Init();
    ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
    if (ctx == 0)
    {
        logg("****Error****: WolfSSL_CTX error", "");

        exitApp(ctx);
        return -1;
    }
    // cert
    uint8_t *der = NULL;
    uint32_t len, ret1;

    ret1 = CertConv_pem2der(ca_cert, sizeof_ca_cert, &der, &len);
    if (ret1 != 0)
    {
        logg("***Error***: cert conversion to .der fail", "");
        return -1;
    }
    int status = wolfSSL_CTX_load_verify_buffer(ctx, der, len,
                                                SSL_FILETYPE_ASN1);
    if (status != SSL_SUCCESS)
    {
        logg("tcpHandler: Error loading ca_cert_der_2048\n", "");
        exitApp(ctx);
        return -1;
    }

    strcpy(msg, "AUTH TLS\r\n");
    ret = send(sock1, msg, strlen(msg), 0);
    valread = recv(sock1, buff, sizeof(buff) - 1, 0);

    *ssl = wolfSSL_new(ctx);
    if (*ssl == NULL)
    {
        logg("tcpHandler: wolfSSL_new error.\n", "");
        exitApp(ctx);
        return -1;
    }

    wolfSSL_set_fd(*ssl, sock1);
    ret = wolfSSL_connect(*ssl);
    int err;
    char err_buffer[80];
    err = wolfSSL_get_error(*ssl, 0);

    if (ret == SSL_SUCCESS)
    {
        logg("TLS successful", "");
        sock1 = wolfSSL_get_fd(*ssl);

        /* Get a buffer to receive incoming packets. Use the default heap. */
        buffer = Memory_alloc(NULL, 512, 0, &eb);

        if (buffer == NULL)
        {
            logg("tcpWorker: failed to alloc memory\n", "");
            exitApp(ctx);
            return -1;
        }

        strcpy(msg, "PBSZ 0\r\n");
        if (wolfSSL_send(*ssl, msg, strlen(msg), 0) != strlen(msg))
        {
            ret = wolfSSL_get_error(*ssl, 0);
            logInt("Write error: %i.\n", "", ret);
        }

        nbytes = wolfSSL_recv(*ssl, (char *) buffer, 512, 0);
        if (nbytes <= 0)
        {
            logg("***error: Reading failed", "");
            return -1;
        }
        else
            logStr("PBSZ 0 is successfull %s", "", buffer);

        strcpy(msg, "PROT P\r\n");
        if (wolfSSL_write(*ssl, msg, strlen(msg)) != strlen(msg))
        {
            ret = wolfSSL_get_error(*ssl, 0);
            logInt("Write error: %i.\n", "", ret);
            return -1;
        }

        nbytes = wolfSSL_read(*ssl, (char *) buffer, 512);
        if (nbytes <= 0)
        {
            logg("***error: Reading failed", "");
            return -1;
        }
        else
            logStr("PROT P is successfull %s", "", buffer);

     //   ssl_cmd = ssl;

        logInt("local ssl for command is %p ", *ssl,"");
        logInt("ssl_data is %p ", ssl_cmd,"");
        logInt("ctx is %p ", ctx,"");


        Memory_free(NULL, buffer, 512);
    }

    // wolfSSL_free(ssl_cmd);
    // fdClose((SOCKET) sockfd);
    // flag = false;

    else
    {
        wolfSSL_free(*ssl);
        //  fdClose((SOCKET) sockfd);
        logg("wolfSSL_connect failed.\n", "");
        //         fdCloseSession(TaskSelf());
        close(sock1);
        exitApp(ctx);
        return -1;
    }

    return 0;
}
int check = 0;

int createFtpDataSocket(WOLFSSL **ssl, char *ipAddress, int portNr)
{

    int sockfd;
    struct sockaddr_in servAddr;
    int ret, valread;
    unsigned char cert[sizeof_ca_cert];
    strcpy(cert, ca_cert);

   // WOLFSSL *ssl;

    Error_Block eb;
    bool flag = true;
    bool internal_flag = true;
    int nbytes;
    char *buffer;
    char msg[50] = { };
    char buff[512];
    memset(buff, 0, 512);

//   fdOpenSession(TaskSelf());
    Error_init(&eb);
    wolfSSL_Init();
//WOLFSSL_CTX* ctx = NULL;

    ctx1 = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
    if (ctx1 == 0)
    {
        logg("****Error****: WolfSSL_CTX error", "");

        exitApp(ctx1);
        return -1;
    }
//SSL_FILETYPE_PEM
    uint8_t *der = NULL;
    uint32_t len, ret1;

    ret1 = CertConv_pem2der(ca_cert, sizeof_ca_cert, &der, &len);
    if (ret1 != 0)
    {
        logg("***Error***: cert conversion to .der fail", "");
        return -1;
    }
    int status = wolfSSL_CTX_load_verify_buffer(ctx1, der, len,
                                                SSL_FILETYPE_ASN1);
    if (status != SSL_SUCCESS)
    {
        logg("tcpHandler: Error loading ca_cert_der_2048\n", "");
        exitApp(ctx1);
        return -1;
    }
    *ssl = wolfSSL_new(ctx1);
    if (*ssl == NULL)
    {
        logg("tcpHandler: wolfSSL_new error.\n", "");
        exitApp(ctx1);
        return -1;
    }

    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0)
    {
        logInt("***Error***: ftp socket creation failed val is %d", "", sockfd);
    }

    memset((char *) &servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = AF_INET;
    servAddr.sin_port = htons(portNr);

    if (HTTPCli_initSockAddr((struct sockaddr *) &servAddr, ipAddress, 0) < 0)
    {
        logg("ftp: ***ERROR*** - address not resolved.", "");
        sockfd = 0;
        return -1;
    }
//   if(cmd_channel)
    ret = connect(sockfd, (struct sockaddr *) &servAddr, sizeof(servAddr));
    wolfSSL_set_fd(*ssl, sockfd);
    ret = wolfSSL_connect(*ssl);
    int err;
    char err_buffer[80];
    err = wolfSSL_get_error(*ssl, 0);

    if (ret == SSL_SUCCESS)
    {
        logg("TLS successful", "");
        sockfd = wolfSSL_get_fd(*ssl);

        /* Get a buffer to receive incoming packets. Use the default heap. */
        buffer = Memory_alloc(NULL, 512, 0, &eb);

        if (buffer == NULL)
        {
            logg("tcpWorker: failed to alloc memory\n", "");
            exitApp(ctx1);
            return -1;
        }

      //  ssl_data = ssl;
        sock3 = sockfd;

        logInt("local *ssl for data is %p ", *ssl,"");
        logInt("ssl_data is %p ", ssl_data,"");
        logInt("ctx1 is %p ", ctx1,"");

        Memory_free(NULL, buffer, 512);

    }
    else
    {
        wolfSSL_free(*ssl);
        close(sock3);
        //  fdClose((SOCKET) sockfd);
        logg("***Error***: Data connection failed failed.\n", "");
        //         fdCloseSession(TaskSelf());
        exitApp(ctx1);
        return -1;
    }

    return 0;

}

int createFtpSocket(char *ipAddress, int portNr)
{

    int sockfd;
    struct sockaddr_in servAddr;
    int ret, valread;

    Error_Block eb;

    char buff[512];
    memset(buff, 0, 512);

//   fdOpenSession(TaskSelf());
    Error_init(&eb);

    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0)
    {
        logInt("***Error***: ftp socket creation failed val is %d", "", sockfd);
    }

    memset((char *) &servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = AF_INET;
    servAddr.sin_port = htons(portNr);

    if (HTTPCli_initSockAddr((struct sockaddr *) &servAddr, ipAddress, 0) < 0)
    {
        logg("ftp: ***ERROR*** - address not resolved.", "");
        sockfd = 0;
        return -1;
    }
//   if(cmd_channel)
    ret = connect(sockfd, (struct sockaddr *) &servAddr, sizeof(servAddr));

    if (ret < 0)
    {
        logStrInt("ftp: ***ERROR*** - connect failed ip %s port %d - quitting.",
                  "", ipAddress, portNr);
        logInt(" \nreturn value is %d ", "", ret);
        return ret;
    }
    else
    {
        //if(cmd_channel)
        valread = recv(sockfd, buff, sizeof(buff) - 1, 0);
        logStr("received buffer : %s", "", buff);
        sock1 = sockfd;
        memset(buff, 0, 512);
    }

/////////////////////////////////
    if (g_ftps)
    {
        int status = start_TLS(&ssl_cmd);
        if (status)
        {
            logg("***error*** tls failed:", "");
            return -1;
        }
    }

    return 0;

}

bool executeFtpCmd(char *ftpCmd, char* result, int size)
{
//logStr("executing ftp cmd %s","",ftpCmd);

    bool answer = true;

// strcpy(ftpCmd,ftpCmd1);
    int sent = wolfSSL_write(ssl_cmd, ftpCmd, strlen(ftpCmd));
    int ret = wolfSSL_get_error(ssl_cmd, 0);
//send(sock, ftpCmd, strlen(ftpCmd), 0);
    int valread = wolfSSL_read(ssl_cmd, (char *) result, size);
//recv(sock, result, size, 0);

    if (valread > 0)
    {
        result[valread - 2] = 0;
    }
    else
    {
        result[0] = 0;
        answer = false;
        char cmd[5] = { 0 };
        strncat(cmd, ftpCmd, 4);
        logStr("***ERROR*** - ftp: cmd %s failed - continuing", "", cmd);
    }
    return answer;
}
//
bool processFtpData(char* inFtpCmd, char* outBuff, bool push)
{
   / * //////////// some code *//////////////
    strcpy(ftpCmd, "PASV\r\n");
    if (!executeFtpCmd(ftpCmd, ftpResp, sizeof(ftpResp) - 1))
    {
        return false;
    }
///////////////   some code to extract ip and port no ///////////////////////

    int sock2 = createFtpDataSocket(&ssl_data, ftpDataIpAdr, ftpDataPortNr); ////////////////// data connection

///// do some processing related to data connection /////////////////////

            wolfSSL_free(ssl_data); ///////// freeing data socket
            close(sock3); //////////////closing data socket
            exitApp(ctx1);//////////////ctx1 related to data connection
   
    return answer;
}

bool pmoPosFtpProc(char* result)
{
   

    int sock = createFtpSocket(g_ftpHost, 21);

    if (sock < 0)
        return false;
    //////////////////////////// do login and other commands////////////////
    
    processFtpData("LIST /abc.txt\r\n", result, false);////////////////////////////////



    ftpCleanup: strcpy(ftpCmd, "QUIT\r\n");
    logg(" ******Closing socket******",__FUNCTION__);
    executeFtpCmd(ftpCmd, ftpResp, sizeof(ftpResp) - 1);

    logg("before freeing cmd pointers:","");
    logInt("ssl_cmd is %p", ssl_cmd,"");
    logInt("ctx is %p ", ctx,"");


    wolfSSL_free(ssl_cmd); ///////////// closing command channel related stuffs
    close(sock1);
    exitApp(ctx);
    
    return (answer);
}

I am getting the same behavior, different pointer values.
Thanks

HI Kaleb,
Please see. I tried what you said.

local ssl_cmd for command is @00027ddc
ssl_cmd is @00027ddc
ctx is @00027ddc

before freeing cmd pointers:
ssl_cmd is @0001ebb4
ctx is @0001ebb4


local ssl_data for data is @000296c0
ssl_data is @000296c0
ctx1 is @000296c0

before freeing the data pointers, values are :
ssl_data is @00025948
ctx1 is @00025948

Before freeing, the values are changed. Same behavior. Please check.

Hi Kaleb,
Thanks for the information. I am trying explicit ftps where I am creating a command channel and data channel. There is a local variable WOLFSSL * ssl which is creating the tls and after creating, I am assigning this to a global variable WOLFSSL * ssl_cmd
in this way-
ssl_cmd = ssl;
In the same way, while creating the data channel, I am doing - ssl_data=ssl;
There are two different functions for command and data. WOLFSSL * ssl is the local variable to that function and WOLFSSL *ssl_cmd, *ssl_data are two global variable.
The values are-
            print("local ssl for data is %d ", ssl,"");
            print("ssl_data is %d ", ssl_data,"");
            print("ctx1 is %d: ", ctx1,"");
local ssl for data is 169672  // while creating
ssl_data is 169672
ctx1 is 169672:

values before freeing up-  // another function where ssl_data and ctx1 (global variable) are being used
ssl_data is 153932
ctx1 is 153932

Why these two values are changed in 2nd function? I think this is the cause I am getting the memory error. Also, but each time the memory locations are the same

I also tried to avoid local variable. Only global variable and freeing the same. But same error is occuring.

Hi All,
I am getting this error while using wolfSSL_connect api. The error doesn't come at first. But after reconnecting to 2nd or 3rd time, I am getting this error-
Error:out of memory: handle=0x2003256c, size=1664
error is -353

I am using ret = wolfSSL_connect(ssl); where,
- ssl is a local variable that is assigned to a global variable, wolfssl * ssl_cmd to keep the wolfssl alive for other functions.
- After successfully completing the operations, before reconnecting, I am closing the ssl_cmd in this way-
                                        wolfSSL_free(ssl_cmd);
                                         close(sock1);
                                          exitApp(ctx);
I should not get this error but I dont know why I am getting this.
Please see what can be done.

Thanks

34

(8 replies, posted in wolfSSL)

Hi Kaleb,
I resolved the issue. It was the sequencing problem. Nothing else.
Thanks

35

(8 replies, posted in wolfSSL)

Hi Kaleb,
I am able to resolve this issue. The variable issue was there.
I am getting one more issue which is a bit weird. As I am doing explicit ftps, I am able to open command channel and procedure is as follows-
1. Create a plain socket with ftp server using socket APIs.
2. Upon sending the AUTH TLS command, create the tls using wolfssl to perform the handshake.
3. Things are working and I am able to log in and send commands to ftp server.
But when I am trying to open the data connection, which is 1 more socket to the server but at a different port, using
socket api (sl_connect), I am not able to create it. Even the socket API is not working anymore. Nothing is going to the server.
What can be the issue? Can't I create plain socket anymore if I have used wolfssl?

36

(8 replies, posted in wolfSSL)

Hi Kaleb,
I am getting this error while using wolfSSL_write api-
int sent = wolfSSL_write(ssl_cmd, ftpCmd, strlen(ftpCmd));
// ssl_cmd is the global variable used in other function to initiallize the TLS. In that function, wolfSSL_write function is working fine.
// ftpCmd is the local variable.
I am getting -173 error value. Any reason??
Thanks

37

(8 replies, posted in wolfSSL)

Hi Kaleb,
I resolved this issue. I changed the socket library from ethernet to wifi and these error codes manually I ad to set as these were not in wifi.
Thanks

38

(8 replies, posted in wolfSSL)

Hi All,

I am trying to rebuild the wolfssl library for simplelink but getting errors. After going through the online documentation and checking the ethernet version of wolfssl, I tried to do this-

1. Changing the directory from NDK to Simplelink in the wolfssl>tirtos>products.mak

NDK_INSTALL_DIR= C:\ti\tirtos_tivac_2_16_01_14\products\tidrivers_tivac_2_16_01_13\packages\ti\mw\wifi

and setting the #include<include/socket.h> into wolfio.h but I am getting this error-

clem4f C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c ...
"C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c", line 98: error: identifier "errno" is undefined
"C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c", line 229: error: identifier "ECONNRESET" is undefined
"C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c", line 233: error: identifier "EINTR" is undefined
"C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c", line 237: error: identifier "ECONNABORTED" is undefined
"C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c", line 276: error: identifier "ECONNRESET" is undefined
"C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c", line 280: error: identifier "EINTR" is undefined
"C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c", line 284: error: identifier "EPIPE" is undefined
7 errors detected in the compilation of "C:/Users/Akhilesh/Downloads/wolfssl-4.3.0/tirtos/../src/wolfio.c".

I am not able to figure it out.