Reputation: 1271
I'm having trouble with the openssl library. I'm calling the following function after sending EHLO
and STARTTLS
:
SSL_CTX *ctx = NULL;
SSL *ssl = NULL;
void CreateTLSSession(int sockfd)
{
printf("///////////////creating TLS Session/////////////////////\n");
SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx == NULL)
{
printf("failed to initialize context\n");
return;
}
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
ssl = SSL_new(ctx);
if (!SSL_set_fd(ssl, sockfd))
{
printf("failed to bind to socket fd\n");
return;
}
if (SSL_connect(ssl) < 1)
{
ERR_print_errors_fp(stdout);
fflush(stdout);
printf("SSL_connect failed\n");
return;
}
}
However, SSL_connect
fails but does not print any errors!
Here's the output of my code: (including the replies of the server)
220 mx.google.com ESMTP x3sm39000551eep.17 - gsmtp
//////////////////////////EHLO//////////////////////////
250-mx.google.com at your service, [80.149.109.201]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 CHUNKING
//////////////////////////STARTTLS//////////////////////////
220 2.0.0 Ready to start TLS
///////////////creating TLS Session/////////////////////
SSL_connect failed
so ERR_print_errors_fp(stdout)
is not doing anything!
Any idea why this is happening?
BTW, I'm trying to connect to smtp.gmail.com:587
Upvotes: 1
Views: 637
Reputation: 1271
I managed to finally solve the problem. the underlying socket was non-blocking, so SSL_connect does not connect instantly. Using select
solved the issue
Upvotes: 0
Reputation: 379
I don't see a load of private key file or certificate file. use SSL_CTX_use_certificate_file and SSL_CTX_use_PrivateKey_file.
Upvotes: 1