cURL Error: OpenSSL SSL_connect: SSL_ERROR_SYSCALL - php

I have a system foe my personal use, but in the last days just got the error "cURL Error: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to www.comprasnet.gov.br:443".
Coincidentally the above URL got Unsecure minutes before this error shown up.
[Unsafe/Unsecure website][1]
Im not a programmer, so if anyone could help me out. I tried a lot of things in the internet but with no luck.
Here's the code i'm using: I'm usaing wampp and run this in localhost
$ch = curl_init();
// opcoes
curl_setopt($ch, CURLOPT_URL, "https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//$cookiefile = dirname(__FILE__)."/cookie.php" ;
//curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookiefile);
//curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookiefile);
//executar sessao
$output = curl_exec($ch);
if ($output === FALSE) { // verifica erros no curl
echo "cURL Error: " . curl_error($ch);
}
$output = strtr($output, $conversao); // função de conversão acentuado/não acentuado
//fechar sessao
curl_close($ch);```
[1]: https://i.stack.imgur.com/a3xlA.png

Related

CURL PHP Automatic Login

Im trying to make an application that do a login via CURL, but i cant make this application to work, with the cookie saved after the login. Aparently i can save the cookie, but can use it. I dont know if im doing wrong in the login code or the way to use the cookie saved. This application already work if i get the cookie manually via Chrome after login. I think it generate a primary cookie after the login at this page: https://www.comprasnet.gov.br/seguro/loginPortalFornecedor.asp, that redirects to this one https://www.comprasnet.gov.br/intro.htm, generating the first cookie. After i hit the menu to this page: https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp, it generates the two cookies needed to work.
Code i made to try to do the login:
<?php
$cookieold = __DIR__.DIRECTORY_SEPARATOR.'cookieJar.txt';
$cookieactive = __DIR__.DIRECTORY_SEPARATOR.'cookieactive.txt';
$ch = curl_init();
$url = "https://www.comprasnet.gov.br/seguro/loginPortalFornecedor.asp";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "perfil=Fornecedor&txtLogin=seulogin&txtSenha=suasenha&ambiente=Produção");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieold);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
// Define uma nova URL para ser chamada (após o login)
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieold);
curl_setopt($ch, CURLOPT_URL, 'https://www.comprasnet.gov.br/intro.htm');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Executa a segunda requisição
$content = curl_exec ($ch);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieold);
curl_setopt($ch, CURLOPT_URL, 'https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieactive);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Executa a terceira requisição
$content2 = curl_exec ($ch);
if ($output === FALSE) { // verifica erros no curl
echo "cURL Error: " . curl_error($ch);
}
curl_close($ch);
//echo $content2;
?>
Code that i already use with the cookie a get manually:
// iniciar sessao
$ch = curl_init();
// opcoes
curl_setopt($ch, CURLOPT_URL, "https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIE, 'ASPSESSIONIDQGAADDTC=DDLGMJABKGCABIKENDGOBLJJ;ASPSESSIONIDQGCADASC=LFFGLJABPEAKKIOLNLLCOFIC');
//executar sessao
$output = curl_exec($ch);
if ($output === FALSE) { // verifica erros no curl
echo "cURL Error: " . curl_error($ch);
}
$output = strtr($output, $conversao); // função de conversão acentuado/não acentuado
//fechar sessao
curl_close($ch);
Any help will be aprecciate. Im not a programmer, just a curious guy trying to make my job easier. This application im making id for personnal use only.
my suggestion is to curl_close / curl_init after each output line. You are carrying over settings from the previous curl session like curl_setopt($ch, CURLOPT_COOKIESESSION, true) and CURLOPT_POSTFIELDS
so
$output = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
$content = curl_exec($ch);
curl_close($ch);
$ch = curl_init();

SSL certificate issue unable to get local issuer certificate in cpanel

$fields['username'] = "Pass#1234";
$fields['password'] = "harsha";
// set postfields using what we extracted from the form
$POSTFIELDS = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://website.com');
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/abc.crt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch, CURLOPT_REFERER, "https://website.com");
$page = curl_exec($ch) or die(curl_error($ch));
echo $page;
I have to save .pem file path in PHP ini but still, it shows "SSL certificate problem unable to get local issuer certificate error"

Can`t get JSON data via PHP CURL from URL but browser can

Chrom or FF get json data successfully, but if I put some code below then I get something like:
About to connect() to pager.eudev.bmstu.ru port 80 (#0)
Trying 195.19.33.153... * Timeout
connect() timed out!
Closing connection #0
error_reporting(E_ALL);
ini_set('display_errors', 1);
$cookie_file = fopen("cookies.txt", "c+");
$err_file = fopen("errors.txt", "c+");
$url = 'http://pager.eudev.bmstu.ru/rasp/o/list/';
$ch = curl_init();
$header=array('GET /rasp/o/list/ HTTP/1.1',
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding:gzip, deflate',
'Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Cache-Control:max-age=0',
'Connection:keep-alive',
'Host:pager.eudev.bmstu.ru',
'User-Agent:Mozilla/5.0 (Windows NT 5.1; rv:47.0) Gecko/20100101 Firefox/47.0'
);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_STDERR, $err_file);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result=curl_exec($ch);
var_dump($result);
curl_close($ch);
fclose($cookie_file);
fclose($err_file);
exit;
Your url is not responding, neither from a browser nor from you script.
Curl time out is set to two seconds, and it just what's happening, after two seconds of trying to load an unresponsive url, curl stops.

CURL PHP handshake failure SSL

I have the following code :
<?php
$cookie_file_path = "cookie.txt"; //
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'theurl');
curl_setopt($ch, CURLOPT_POSTFIELDS,'blocPnr_textField_labelNom='.urlencode('www').'&blocPnr_textField_labelPnr='.urlencode('xxx').'&blocPnr_valider=Submit');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch, CURLOPT_REFERER, "theurl");
$page = curl_exec($ch);
var_dump($page);
echo 'error:' . curl_error($ch);
?>
It gives me the following error:
bool(false) error:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
I can't figure out where the pb comes from. I looked for similar error message on Google and S/O but haven't found any solution.
You're trying to use version 3 of the SSL protocol which is either refused or unsupported by the server. The POODLE attack pushed a lot of system administrators to drop support for SSLv3 and its usage is not so widespread anymore (and definitely not recommended).
When you have SSL handshake errors, try different versions of SSL/TLS until one works (preferably the most secure). If you have a doubt, using CURL_SSLVERSION_DEFAULT works in most cases.
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
It seems that formulaire.sncf.com supports TLSv1.0. You could also force use that protocol version:
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0);

Server Error in '/' Application when attempting to cURL

I am trying to download a pdf using cURL and am getting stuck on a "Server Error in '/' Application" page. My code:
$url = "https://some.domain.com/Reports/Report?ReportID=123456"
$ch = curl_init($url);
$header = array ('Host: some.domain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, implode(':', $arrayCiphers));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_COOKIE, "ASP.NET_SessionId=XXXXXXXX; __RequestVerificationToken_XXXXXXX=lots-of-alpha-numeric-characters");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_REFERER, "https://some.domain.com");
$output = curl_exec($ch);
echo $output;
curl_close($ch);
Is there something else I can try or some more debugging I can do?
[edit] Apparently it's caused by one of my parameters. There are several parameters in the URL. &Flag=True seems to be causing the error. If I change it to &Flag=False I get a blank page.
This error was being caused because my curl request header did not include cookies that were required to download the file. Adding those cookies in the header fixed it.

Categories