Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL peer certificate or SSH remote key was not OK

Tags:

php

curl

ssl

apache

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); 
like image 251
WonderLand Avatar asked Jan 07 '13 09:01

WonderLand


People also ask

What is SSL peer certificate?

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.

What is SSL certificate for website?

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.

How do I disable curls verification certificate?

If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option.


2 Answers

You are probably using self-signed SSL certifiacate, which will not pass when the CURLOPT_SSL_VERIFYPEER options is set.

There are two solutions:

  1. Buy valid SSL certificate.
  2. Disable SSL verification in Curl. (add --insecure option)

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.

like image 111
Daniel Milde Avatar answered Sep 17 '22 12:09

Daniel Milde


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!

like image 45
waibelp Avatar answered Sep 20 '22 12:09

waibelp