CURL giving me an error( SSH error ?)

ey guys

I'm playing around with CURL,trying to download an image from a url but I am getting an error, the error I get is as follows,

 error SSL peer certificate or SSH remote key was not OK 


anybody ever experience this type of error before when using CURL?

I'm using the 32 bit mingw windows version of CURL and was downloaded here - https://curl.haxx.se/windows/ if that helps.

thanks


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#include <iostream>
#include <stdio.h>
#include "include/curl.h"

using namespace std;

int main()
{
    CURL* curl;
    FILE* fp;

    fp = fopen("photo.jpg","wb");



    curl = curl_easy_init();
    curl_easy_setopt(curl,CURLOPT_URL,"https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/Nilgai_%28Boselaphus_tragocamelus%29_male.jpg/1024px-Nilgai_%28Boselaphus_tragocamelus%29_male.jpg");
    curl_easy_setopt(curl,CURLOPT_WRITEDATA,fp);
    curl_easy_setopt(curl,CURLOPT_FAILONERROR,1L);
    int result = curl_easy_perform(curl);

    if(result == CURLE_OK)
        cout << "success!" << endl;
    else
        printf("error %s\n ", curl_easy_strerror((CURLcode)result));


    fclose(fp);
    curl_easy_cleanup(curl);

    return 0;
}


by adding the verbose option to the code

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

I get



*   Trying 31.13.73.174:443...
* TCP_NODELAY set
* Connected to www.instagram.com (31.13.73.174) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
error SSL peer certificate or SSH remote key was not OK



*note I changed the url to - https://www.instagram.com/static/images/ico/favicon-192.png/68d99ba29cc8.png BUT this didn't seem to help :/
Last edited on
I'm not familiar with how CURL + SSL (TLS) works, so this is a guess, but try setting CURLOPT_SSL_VERIFYPEER off.

https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

__________________________________

The better solution would be to actually verify the certificate, but I don't know how to do that, so if you just want to get something working, and you're not doing banking, entering passwords, or something important like that, just ignore the certificate.
Last edited on
Thanks Ganado that worked :)

The better solution would be to actually verify the certificate, but I don't know how to do that, so if you just want to get something working, and you're not doing banking, entering passwords, or something important like that, just ignore the certificate.


Oh ok so the transfer of data failed because my computer had no way of essentially verifying the digital certificate from that website ( all websites in my case )?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#include <iostream>
#include <stdio.h>
#include "include/curl.h"

using namespace std;

int main()
{
    CURL* curl;
    FILE* fp;

    fp = fopen("photo.jpg","wb");

    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); // this line
    curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0); // and this line fixed the issue 
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl,CURLOPT_URL,"https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/Nilgai_%28Boselaphus_tragocamelus%29_male.jpg/1024px-Nilgai_%28Boselaphus_tragocamelus%29_male.jpg");
    curl_easy_setopt(curl,CURLOPT_WRITEDATA,fp);
    curl_easy_setopt(curl,CURLOPT_FAILONERROR,1L);
    int result = curl_easy_perform(curl);

    if(result == CURLE_OK)
        cout << "sucess! spelled wrong" << endl;
    else
        printf("error %s\n ", curl_easy_strerror((CURLcode)result));


    fclose(fp);
    curl_easy_cleanup(curl);

    return 0;
}
Right, the certificate is needed for actually making a secure HTTPS connection.

If you tried to download a picture from http://cplusplus.com, you probably wouldn't run into your original problem.
Last edited on
Topic archived. No new replies allowed.