C程序卷曲:(35)错误:14077410:SSL例程:SSL23_GET_SERVER_HELLO:sslv3警报握手失败

时间:2016-12-29 21:56:08

标签: c ssl curl

我试图制作一个可以下载给定网址的图像的C程序。 但是,我似乎无法使用libcurl-7.52.1从特定网站下载。 在此网址上使用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

如何解决此问题并下载文件?

1 个答案:

答案 0 :(得分:0)

您的TLS库可能有问题。对于使用GnuTLS / 3.5.7或OpenSSL / 1.1.0c的curl版本,相同的URL对我来说很好用– Daniel Stenberg

我重新编译了curl以使用GnuTLS-3.4.17,它的运行非常出色。我想这对都不起作用