"SSL connect error" connecting to Proxies using libcurl and C ++, a little help?

2

I wanted to buy a huge list of proxies that I have because I'm only interested in those who use the https (SSL) protocol and those that are not in China. Looking for a quick way to do it I found this function.

string proxyWorks(string ip, int port, string proxytype="")
{

    CURL *ch;
    CURLcode res;
    ch = curl_easy_init();

    if(!ch)
    return "chfail";


    curl_easy_setopt(ch, CURLOPT_URL, "http://google.com/");
    curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, true);
    curl_easy_setopt(ch, CURLOPT_TIMEOUT, 15);
    curl_easy_setopt(ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)2011-09-08 13:55:49");


    if(proxytype=="http")
        curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);

    if(proxytype=="socks4")
        curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);

    if(proxytype=="socks4a")
        curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A);

    if(proxytype=="socks5")
        curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

    if(proxytype=="https")
        curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTPS);



    curl_easy_setopt(ch, CURLOPT_PROXY, ip.c_str());
    curl_easy_setopt(ch, CURLOPT_PROXYPORT, port);
    curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, writer);
    curl_easy_setopt(ch, CURLOPT_WRITEDATA, &buffer);


    res = curl_easy_perform(ch);
    curl_easy_cleanup(ch);

    if(res == CURLE_OK)
    {
        if(sizeof(buffer)>0)
            return "ok";
        else return "fail";
    }
    else
    return curl_easy_strerror(res);

}

First I tried a couple of IPs on a website to check the result I would have to give. This website ( link ), which by the way if you ask why I do not do everything on that website is because I have a couple of thousands of proxies and that web only lets me put 100 maximum at each time.

Returning to the topic, it turns out that:

If proxytype="" and in all cases I have a positive validation (OK)

If proxytype="http" I also have a positive validation (OK)

But if proxytype="https" I have a valid negative, to be more precise the curl_easy_strerror (res) function returns me the following message SSL connect error . (According to the web that proxy if it accepts the HTTPS protocol).

The rest of the cases do not interest me, so I have not tried them.

I've tried putting " link " instead of " link / a> "but it works worse, that is, I do not get any positive cases.

I must add that it is the first time I use libcurl so that is my level right now with this library (Rookie): -)

Well, that, actually I have two questions:

1st - Does anyone know why it is failing with HTTPS connections?

2nd - Could you also use this library to filter IPs by country and eliminate Chinese ones?

    
asked by Iván Rodríguez 20.04.2018 в 20:30
source

1 answer

1

Since nobody has answered me, I am going to answer myself since I have found a solution and maybe another is useful. Well that to know those that support the HTTPS protocol and with certificate can be done with this function.

string proxyWorks(string ip, int port)
{
    CURLcode res;
    CURL *curl = curl_easy_init();
    if(!curl)
    return "chfail";


    curl_easy_setopt(curl, CURLOPT_URL, "https://google.com");    
    curl_easy_setopt(curl, CURLOPT_PROXY, ip.c_str());
    curl_easy_setopt(curl, CURLOPT_PROXYPORT, port);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);


    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
    curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0L);


    res = curl_easy_perform(curl);

    if(res == CURLE_OK)
    {
        if(sizeof(buffer)>0)
            return "ok";
        else return "fail";
    }
    else
    return curl_easy_strerror(res);

}

Does anyone help me filter China's proxy? : -)

Also another problem has arisen and that is that some proxies have filters (fortinet) that do not allow you to connect to some webs ... I would like to be able to discard the proxies that use those filters as well. Basically it would be to check if you can connect to that web through that proxy. Does anyone know how to do it?

    
answered by 24.04.2018 / 18:34
source