0

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']];
  }
Community
  • 1
  • 1
Bhavin
  • 2,070
  • 6
  • 35
  • 54
  • Check this [query](http://stackoverflow.com/questions/20837161/openssl-pem-routinespem-read-biono-start-linepem-lib-c703expecting-truste). Maybe it could help you. – James Sep 26 '16 at 15:00
  • @James i tried with this code also brother but same error. – Bhavin Sep 27 '16 at 07:32
  • @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 Sep 27 '16 at 09:22
  • 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 Sep 27 '16 at 17:29
  • 1
    @James. ohk thank you so..much brother for your precious time it was a error in pem file generation – Bhavin Sep 28 '16 at 07:43

1 Answers1

1

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');
Rickyras
  • 71
  • 4