W
W
WoOPHY2017-10-09 18:14:03
C++ / C#
WoOPHY, 2017-10-09 18:14:03

OpenSSL: Sending and receiving data using the SSL_write and SSL_read functions. What is the problem?

Hello!
I am writing a simple POP3s mail client in c++ using the openssl library.
When writing, I encountered the following problem: after creating an ssl connection to the server (for example, pop.mail.ru or pop.google.com with port 995) and receiving confirmation, it is not possible to send the following command (for example, user ) and receive a response from the server . After sending the data with the SSL_write function, the program exits with code 0 after one minute. What could be the problem?

void communicateWithPOP(const int sock, const argValues* values){

    int bytes;
    string reply ;
    char buf[2048];

    SSL_CTX *ctx;
    SSL* ssl;
    SSL_library_init();
    ctx = InitCTX();
    ssl = SSL_new(ctx);
    SSL_set_fd(ssl, sock);
    SSL_CTX_set_default_verify_paths(ctx);


    if(SSL_connect(ssl) == -1)
        ERR_print_errors_fp(stderr);

    else{

        string nameReq = "user usr";
        bytes = SSL_read(ssl,buf,sizeof(buf));
        buf[bytes] = 0;
        cout << "[CONNECTION] : "<< buf << endl;
        memset(buf,0, sizeof(buf));

        int sslwRet = SSL_write(ssl, nameReq.c_str(), strlen(nameReq.c_str()));
        cout << "SSL_write ret : " << sslwRet << endl;

        bytes = SSL_read(ssl, buf, sizeof(buf));
        cout << "SSL_read ret : " << bytes << endl;

        SSL_free(ssl);

    }

    close(sock);
    SSL_CTX_free(ctx);
}

59db91d8df3ba542611459.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question