2

I'm having a Certificate and I wish to read the SHA 1 Fingerprint and SHA 256 Fingerprint from a file path.

<?php

ini_set("display_startup_errors", 1);
ini_set("display_errors", 1);
error_reporting(-1);

$certificate = "./wwwbbminfocom.crt";
$cert = openssl_x509_read($certificate);
$sha1_hash = openssl_x509_fingerprint($cert); // sha1 hash
$md5_hash = openssl_x509_fingerprint($cert, 'md5'); // md5 hash

?>

Note: I downloaded a SSL Certificate from the website https://www.bbminfo.com/Tutor/php_error_error_log.php

I got an following PHP Warning:

Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in /home/super/public_html/md.php on line 8

Warning: openssl_x509_fingerprint(): cannot get cert from parameter 1 in /home/super/public_html/md.php on line 9

Warning: openssl_x509_fingerprint(): cannot get cert from parameter 1 in /home/super/public_html/md.php on line 10

Kindly assist me how to read the file and get the Fingerprint. I'm using PHP 7.0

B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130

1 Answers1

0

Filepaths passed to OpenSSL functions need to be fully-qualified URLs. When on the local file system, that means them being in file://absolute/path/to/file format.

Or in your case:

$certificate = "file://".realpath("./wwwbbminfocom.crt");

Of course, as suggested in the comments, you could also pass the raw file contents, but that's technically less efficient.

Read up here: https://secure.php.net/manual/en/openssl.certparams.php

Narf
  • 14,600
  • 3
  • 37
  • 66