I'm testing an API that uses curl_exec
php function and a CA certificate but something is going wrong and I'm a little lost.
I have configured SSL on my apache VirtualHost and looks ok ( opening https:://[myVHost]
... works ).
However the API curl call give me back this message:
SSL peer certificate or SSH remote key was not OK
I'm not very experienced with SSL so I have few ideas about the cause of that.
UPDATE:
This is the code I'm using in my cURL request, I have commented 2 lines and changes their value (look at 'TODO' line ) and in this way it is working, however this is just a work arround ...
$opts[CURLOPT_URL] = $url; $opts[CURLOPT_RETURNTRANSFER] = true; $opts[CURLOPT_CONNECTTIMEOUT] = 50; $opts[CURLOPT_TIMEOUT] = 100; $headers = array( 'Accept: application/json', "User-Agent: APIXXX-PHP-Client"); $opts[CURLOPT_HTTPHEADER] = $headers; $opts[CURLOPT_USERPWD] = $env->getApiKey() . ':'; if (certificatePresent()) { // $opts[CURLOPT_SSL_VERIFYPEER] = true; // $opts[CURLOPT_SSL_VERIFYHOST] = 2; // TODO: SET IT BACK $opts[CURLOPT_SSL_VERIFYPEER] = 0; $opts[CURLOPT_SSL_VERIFYHOST] = 0; $opts[CURLOPT_CAINFO] = $path } curl_setopt_array($curl, $opts); $response = curl_exec($curl);
Peer authentication means that the other side of the SSL connection is authenticated based on a trusted certificate installed locally. Alternatively, a Certification Authority (CA) certificate may be installed locally and the peer has a certificate signed by that authority.
An SSL certificate is a bit of code on your web server that provides security for online communications. When a web browser contacts your secured website, the SSL certificate enables an encrypted connection. It's kind of like sealing a letter in an envelope before sending it through the mail.
If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option.
You are probably using self-signed SSL certifiacate, which will not pass when the CURLOPT_SSL_VERIFYPEER options is set.
There are two solutions:
If you disable verification, you can't be sure if you are really communicating with your host. So it depends on level of security you need.
Beside CURLOPT_SSL_VERIFYPEER
there are two other settings which might be changed to false
/0
:
CURLOPT_SSL_VERIFYHOST CURLOPT_SSL_VERIFYSTATUS
Beware that you should fix your SSL certificates & settings instead of disable security!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With