我的提供者更新了服务器后,我多年来一直使用的读取电子邮件的程序停止工作。现在,当我运行程序时,我在调用BIO_do_connect()
时遇到此失败:
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:s3_pkt.c:1086:SSL alert number 40
在MacOS Yosemite和旧的Linux发行版中,故障是相同的。
通过比较,此命令不会不会失败:
openssl s_client -connect mail.example.org:993
作为参考,这是一个演示问题的最小程序(我掩盖了服务器名称)。
我缺少一些参数吗?
/*
* Under MacOS, compile with:
* cc -o tester -I/opt/local/include tester.c -L/opt/local/lib -lssl -lcrypto
*
* Under Linux, compile with:
* cc -o tester tester.c -lssl
*/
#define CERTS_DIR "/etc/ssl/certs/"
#include <stdio.h>
#include <stdlib.h>
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
int
main()
{
BIO *bio, *rbio;
SSL_CTX *ctx;
SSL *ssl;
const char *hostname = "mail.example.org";
int port = 993;
SSL_library_init();
ERR_load_BIO_strings();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
ctx = SSL_CTX_new(SSLv3_client_method());
if (ctx == NULL) {
ERR_print_errors_fp(stderr);
return 3;
}
/* load trusted certs with SSL_CTX_load_verify_locations()? */
if (!SSL_CTX_load_verify_locations(ctx, NULL, CERTS_DIR)) {
fprintf(stderr, "Unable to load trusted SSL certs\n");
}
bio = BIO_new_ssl_connect(ctx);
BIO_get_ssl(bio, &ssl);
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
BIO_set_conn_hostname(bio, hostname);
BIO_set_conn_int_port(bio, &port);
// Here is the call that fails
if (BIO_do_connect(bio) <= 0) {
fprintf(stderr, "cannot connect to %s:%d\n", hostname, port);
ERR_print_errors_fp(stderr);
BIO_free_all(bio);
SSL_CTX_free(ctx);
return 3;
}
printf("Success\n");
return 0;
}
答案 0 :(得分:0)
好吧,经过大量的尝试和错误,我能够通过将SSLv3_client_method()
更改为SSLv23_client_method()