I have this error
SSL peer had some unspecified issue with the certificate it received.
I'm use centos, NSS library.
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
curl_setopt($ch, CURLOPT_SSLCERT, <cert_path>);
curl_setopt($ch, CURLOPT_SSLKEY, <key_path>);
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, 'password');
curl_setopt($ch, CURLOPT_URL, $this ->url_merchant);
Related
Is there a way to add proxies from txt file to php?
Like can it open proxies from text file and choose one randomly and use it ?
$proxy = 'proxy:port';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd().'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/cookie.txt');
I had working code that used my VPN (NordVPN) credentials through their SOCKS5 protocol.
Recently, they have dropped support for SOCKS5 so I have to use their other protocols, however I am unable to get any to work.
All of their available protocols can be seen here
https://nordvpn.com/servers/tools/
- IKEv2/IPSec
- OpenVPN
- Wireguard
- HTTP Proxy (SSL)
Here is my code, attempting to use their "HTTP Proxy (SSL)" protocol
$cookie_file = tempnam("/tmp", "CURLCOOKIE");;
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXYPORT, "443");
curl_setopt($ch, CURLOPT_PROXY, "au643.nordvpn.com");
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyUser . ":" . $proxyPass);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_URL, $Url);
$result = curl_exec($ch);
curl_close($ch);
The error I get is
curl_exec(): supplied resource is not a valid cURL handle resource in ...
I don't really care what protocol it is, just need it to work.
Thanks.
After facing the same issue, I have worked out a solution
$PROXY_HOST = "xxx.xxxxxx.com";
$PROXY_PORT = "89";
$PROXY_USER = "yourproxyusername";
$PROXY_PASS = "yourproxypassword";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_PROXY_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$PROXY_USER:$PROXY_PASS");
curl_setopt($ch, CURLOPT_PROXY, "https://$PROXY_HOST:$PROXY_PORT");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response= curl_exec($ch);
$error = curl_error($ch);
echo $error;
echo $response;
curl_close($ch);
One thing to note is that for NordVPN you have to use the port 89 for HTTP Proxy (SSL) and the username and password is not your account username and password, but your proxy specific credentials that you can find on your account page.
Also dont quote me on this, but I think you need to use PHP 7.3+ for this to work.
we can use it with protonvpn or vpnbook ?
After security changes on Paypal Sandbox, my IPN listener doesn't work.
I have upgraded php to 5.5.32 and curl to 7.47.0 using OpenSSL/1.0.1e
Here are my curls settings:
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__)."/cert/cacert.pem");
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
if ($this->force_ssl_v3) {
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
}
How can I translate the following cURL line to php cURL.
curl -v --cacert [linkToCertificate] -k --ftp-ssl -T "[fileToUpload]" -P - ftp://[user]:[password]#[URL]
What I have tried so far:
curl_setopt($ch, CURLOPT_VERBOSE, TRUE); #-v
curl_setopt($ch, CURLOPT_PORT, '-');
curl_setopt($ch, CURLOPT_URL, $ftp_server . $source_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password);
curl_setopt($ch, CURLOPT_FTP_USE_EPRT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 400);
curl_setopt($ch, CURLOPT_FILE, $file);
//SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_CAINFO, $ftp_certificate);
curl_setopt($ch, CURLOPT_FTP_SSL, CURLPROTO_FTP);
I found and answer to my issue.
The issue was that curl run the ftp connection in passive mode. And I needed it to run in active mode.
My solution was therefore to add this option:
curl_setopt($ch, CURLOPT_FTPPORT, 0);
Full curl solution:
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_FTPPORT, 0);
curl_setopt($ch, CURLOPT_URL, $ftp_server . $destination_file);
curl_setopt($ch, CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 400);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $file);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($source_file));
curl_setopt($ch, CURLOPT_CAINFO, $ftp_certificate);
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_ALL);
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_SSL);
I am getting error "SSL read:errno-12192"
Actually previous my programming was working fine but past 1 week I was getting error:
SSL error: SSL_ERROR_EXPIRED_CERT_ALERT
I then replaced my .pem file with new certificate and after replacing it I am getting 'SSL read: errno -12192'error. My code as below:
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params );
curl_setopt($ch, CURLOPT_CAINFO, getcwd().'/ca.crt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'/apna_generic_json.pem');
curl_easy_setopt(s, CURLOPT_SSLKEY,'/apna.pem');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);