'error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

I'm trying to connect to a service that requires a certificate for authorization, I import certificates on my machine and when I directly hit on the server by my google chrome browser it give's me perfect result but when I call this URL from php curl request it gives me sslv3 alert handshake failure error. (error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure)

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://example.com",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_SSL_CIPHER_LIST => SSLv3,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_SSLVERSION => 7,
  CURLOPT_SSLVERSION => 7,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

var_dump($response);
var_dump($err);


Solution 1:[1]

You need to import your cert to CURL and set any needed options

  $caFile = "ca.pem";
  $keyFile = "key.pem";
  $certFile = "client.pem";
  $certPass = "xxxxxx";

  curl_setopt($ch, CURLOPT_CAINFO, $caFile);
  curl_setopt($ch, CURLOPT_SSLKEY, $keyFile);
  curl_setopt($ch, CURLOPT_SSLCERT, $certFile);
  curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $certPass);

You can check the info for each CURL option from here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1