0
votes

I have four files provided from client side.

  • test.jks
  • test.pem
  • key.pub
  • test.p12

I have to send json array on this url using curl. so i'm confused what is the use of other files ? like .p12 , .jks. what is the key from above files ? I started with .pem file included using this link : How to send a curl request with pem certificate via PHP?

So , I got following errors.

Error :

Curl Error: could not load PEM client certificate, OpenSSL error error:0906D06C:PEM routines:PEM_read_bio:no start line, (no key found, wrong pass phrase, or wrong file format?)No HTTP code was returned

Code :

$url = "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

$pemFile = tmpfile();
fwrite($pemFile, "test.pem");//the path for the pem file
$tempPemPath = stream_get_meta_data($pemFile);
$tempPemPath = $tempPemPath['uri'];
curl_setopt($ch, CURLOPT_SSLCERT, $tempPemPath); 

//curl_setopt($ch, CURLOPT_SSLCERT, "test.pem" );
curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_VERBOSE, true);

$result = curl_exec($ch);

if(!$result)
{
    echo "Curl Error: " . curl_error($ch);
}
else
{
    echo "Success: ". $result;
}

  $info = curl_getinfo($ch);

  curl_close($ch); // close cURL handler

  if (empty($info['http_code'])) {
          die("No HTTP code was returned"); 
  } else {
      // load the HTTP codes
      $http_codes = parse_ini_file("path/to/the/ini/file/I/pasted/above");

      // echo results
      echo "The server responded: <br />";
      echo $info['http_code'] . " " . $http_codes[$info['http_code']];
  }
1
Check this query. Maybe it could help you. - James
@James i tried with this code also brother but same error. - Bhavin
@james i have one question that i have to include Passphrase in code or not ? because when i try it using curl command line then this certificate is working fine with passphrase - Bhavin
I'm not a SSL specialist and my previous scripts worked fine without it, but i think you can try to set it using curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'pass'); . - James
@James. ohk thank you so..much brother for your precious time it was a error in pem file generation - Bhavin

1 Answers

0
votes

Since you are using the filename - Try an absolute path.

e.g

curl_setopt($ch, CURLOPT_SSLCERT, 'c:/wamp64/www/bit-tool/www/testcert.pem');