0

I'm having trouble with the openssl_x509_parse() function

$parsed_cert = openssl_x509_parse(file_get_contents('/home/my_location/aaa010101aaa__csd_01.cer'));

the function is returning a false and I'm unsure about the reasons. Maybe the certificate file must be in .pem or .crt?

EDIT: the code was ok, but the format of the file was the issue, so i had to transform it into a .crt from the .cer original.

2 Answers2

0

After seeing the example from manual page, your code seems fine. Problem may be in file_get_contents.

Please try the following and check the if file is valid.

$file = file_get_contents('/home/my_location/aaa010101aaa__csd_01.cer');
$parsed_cert = openssl_x509_parse($file);

Now check what is file. Is it exists or a valid certificate file?

doptimusprime
  • 9,115
  • 6
  • 52
  • 90
0

phpseclib's pure PHP X509 implementation is more fault tolerant of X.509 certs than OpenSSL is. Here's an example of how to use it:

<?php
include('File/X509.php');

$x509 = new File_X509();
$cert = $x509->loadX509('...'); // see google.crt

print_r($cert);
?>

As for OpenSSL's being less fault tolerant... an example would be how OpenSSL won't decode keys whose individual lines are longer than 64 bytes whereas phpseclib will.

Community
  • 1
  • 1
neubert
  • 15,947
  • 24
  • 120
  • 212