代码之家  ›  专栏  ›  技术社区  ›  Edward Falk

OpenSSL警报编号40

  •  0
  • Edward Falk  · 技术社区  · 7 年前

    当我的提供商更新他们的服务器时,一个我多年来一直用来阅读电子邮件的程序停止了工作。现在,当我运行我的程序时,当我调用 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;
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Edward Falk    7 年前

    好吧,经过反复试验,我可以通过改变 SSLv3_client_method() SSLv23_client_method()