Curl: Fix CURL (51) SSL error: no alternative certificate subject name matches
The common name in the certicate for api.evercam.io
is for *.herokuapp.com
and there are no alternative subject names in the certificate. This means, that the certificate for api.evercam.io
does not match the hostname and therefore the certificate verification fails.
Same as true for www.evercam.io
, e.g. try https://www.evercam.io with a browser and you get the error message, that the name in the certificate does not match the hostname.
So it is a problem which needs to be fixed by evercam.io. If you don't care about security, man-in-the-middle attacks etc you might disable verification of the certificate (curl --insecure
), but then you should ask yourself why you use https instead of http at all.
It usually happens when the certificate does not match with the host name.
The solution would be to contact the host and ask it to fix its certificate.
Otherwise you can turn off cURL's verification of the certificate, use the -k
(or --insecure
) option.
Please note that as the option said, it is insecure. You shouldn't use this option because it allows man-in-the-middle attacks and defeats the purpose of HTTPS.
More can be found in here: http://curl.haxx.se/docs/sslcerts.html
it might save some time to somebody.
If you use GuzzleHttp and you face with this error message cURL error 60: SSL: no alternative certificate subject name matches target host name and you are fine with the 'insecure' solution (not recommended on production) then you have to add
\GuzzleHttp\RequestOptions::VERIFY => false
to the client configuration:
$this->client = new \GuzzleHttp\Client([
'base_uri' => 'someAccessPoint',
\GuzzleHttp\RequestOptions::HEADERS => [
'User-Agent' => 'some-special-agent',
],
'defaults' => [
\GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 5,
\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => true,
],
\GuzzleHttp\RequestOptions::VERIFY => false,
]);
which sets CURLOPT_SSL_VERIFYHOST
to 0 and CURLOPT_SSL_VERIFYPEER
to false in the CurlFactory::applyHandlerOptions()
method
$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = false;
From the GuzzleHttp documentation
verify
Describes the SSL certificate verification behavior of a request.
- Set to true to enable SSL certificate verification and use the default CA bundle > provided by operating system.
- Set to false to disable certificate verification (this is insecure!).
- Set to a string to provide the path to a CA bundle to enable verification using a custom certificate.
Editor's note: this is a very dangerous approach, if you are using a version of PHP old enough to use it. It opens your code to man-in-the-middle attacks and removes one of the primary purposes of an encrypted connection. The ability to do this has been removed from modern versions of PHP because it is so dangerous. The only reason this has been upvoted 70 time is because people are lazy. DO NOT DO THIS.
I know it's a (very) old question and it's about command line, but when I searched Google for "SSL: no alternative certificate subject name matches target host name", this was the first hit.
It took me a good while to figure out the answer so hope this saves someone a lot of time! In PHP add this to your cUrl setopts:
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
p.s: this should be a temporary solution. Since this is a certificate error, best thing is to have the certificate fixed ofcourse!