I use openssl to create secure smtp connections with gmail.com:25. Therefore, I can successfully connect to the server and send the STARTTLS command (I get 220 2.0.0 ready to start TLS). Then execute the following code without shutting down:
SSL_METHOD* method = NULL;
SSL_library_init();
SSL_load_error_strings();
method = SSLv23_client_method();
ctx = SSL_CTX_new(method);
if (ctx == NULL)
{
ERR_print_errors_fp(stderr);
}
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
ssl = SSL_new(ctx);
if (!SSL_set_fd(ssl, socket))
{
ERR_print_errors_fp(stderr);
return;
}
if (ssl)
{
if (SSL_connect((SSL*)ssl) < 1)
{
ERR_print_errors_fp(stderr);
}
}
But after calling SSL_connect, I get an error message:
24953:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:601:
If I use SSLv3_client_method, I get an error:
18143:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:284.
And if TLSv1_client_method:
21293:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:284:
Why? What am I doing wrong?
source
share