C程序curl:(35)错误:14077410:SSL例程:SSL23\u GET\u SERVER\u HELLO:sslv3警报握手失败

C程序curl:(35)错误:14077410:SSL例程:SSL23\u GET\u SERVER\u HELLO:sslv3警报握手失败,c,ssl,curl,C,Ssl,Curl,我正在尝试制作一个C程序,在给定url的情况下下载图像。 但是,我似乎无法使用libcurl-7.52.1从特定网站下载。 在这个url上使用curl命令时,我得到: ~ $ curl -v https://files.yande.re/jpeg/ae340a06572fa8f48d63fd418197e1cd/yande.re%20292874%20makise_kurisu%20ninnzinn%20pantyhose%20steins%3Bgate.jpg * Trying 5.39.

我正在尝试制作一个C程序,在给定url的情况下下载图像。 但是,我似乎无法使用libcurl-7.52.1从特定网站下载。 在这个url上使用curl命令时,我得到:

~ $ curl -v https://files.yande.re/jpeg/ae340a06572fa8f48d63fd418197e1cd/yande.re%20292874%20makise_kurisu%20ninnzinn%20pantyhose%20steins%3Bgate.jpg
*   Trying 5.39.10.56...
* TCP_NODELAY set
* Connected to files.yande.re (5.39.10.56) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Unknown (21):
* TLSv1.2 (IN), TLS alert, Server hello (2):
* error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
* Curl_http_done: called premature == 1
* stopped the pause stream!
* Closing connection 0
curl: (35) error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
使用我自己的程序时,如果使用以下代码和curl选项,则会出现相同的错误:

FILE *img_fp;
img_fp = fopen(file_name, "wb");

/* Initialize curl */
CURL *curl_handle = curl_easy_init();
CURLcode res;

if (curl_handle) {
    /* set the working website to this domain */
    /* weburl is the url of the website */
    curl_easy_setopt(curl_handle, CURLOPT_URL, web_url);

    /* ask libcurl to show us the verbose output */
    curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);

    /* Set the user agent to chrome */
    curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "chrome/55.0.2883.75");

    /* Set the data to pass when the function is called */
    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, img_fp);

    res = curl_easy_perform(curl_handle);

    /* Check for errors */
    if (res != CURLE_OK) {
        printf("curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

    }
}
Output:
*   Trying 5.39.10.56...
* TCP_NODELAY set
* Connected to files.yande.re (5.39.10.56) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
* Curl_http_done: called premature == 1
* stopped the pause stream!
* Closing connection 0
curl_easy_perform() failed: SSL connect error

如何修复此问题并下载文件?

可能是您的TLS库有问题。使用GnuTLS/3.5.7或OpenSSL/1.1.0c-danielstenberg的curl版本也可以使用相同的URL


我重新编译了curl以使用GnuTLS-3.4.17,它工作得非常好。我猜它对任何东西都不起作用,这可能是TLS库的问题。对于使用GnuTLS/3.5.7或OpenSSL/1.1.0cWow的curl版本,同样的URL对我来说也很好,谢谢!我重新编译了curl以使用GnuTLS-3.4.17,它工作得非常好。我想它对@Kamiyaa没有任何作用:GnuTLS和OpenSSL是TLS的不同实现,也就是说,curl一次只使用其中一种。因此,成功使用特定的GnuTLS版本并不能说明哪个OpenSSL版本可以工作。您的问题缺少原始curl中使用的GnuTLS或OpenSSL版本的信息(请检查
curl-V
),但我猜这是一个不支持ECDHE的问题,因为该站点需要ECDHE。我的curl以前是用OpenSSL-1.0.2j编译的。但在我使用的发行版的存储库中,OpenSSL-1.1.0目前被标记为不稳定。所以我选择用GnuTLS编译curl。