For those interested in parsing the timestamps from the certificate, such as the valid to and valid from times, it should be noted that the format returned by this function is: YYMMDDHHMMSS
This code snippet is useful for generating a unix timestamp for this purpose:
<?php
$fp = fopen("/path/to/cert.crt", "r");
$cert = fread($fp, 8192);
fclose($fp);
$data = openssl_x509_parse($cert);
function openssl_to_timestamp ($in) {
$year = substr($in, 0, 2); $month = substr($in, 2, 2);
$day = substr($in, 4, 2);
$hour = substr($in, 6, 2);
$min = substr($in, 8, 2);
$sec = substr($in, 10, 2);
return gmmktime($hour, $min, $sec, $month, $day, $year);
}
var_dump(gmdate('r', openssl_to_timestamp($data['validTo'])));
?>
This will output: string(31) "Fri, 29 Aug 2008 16:45:15 +0000"
Compare this with the output of `openssl x509 -in cert.crt -noout -text`:
Validity
Not After : Aug 29 16:45:15 2008 GMT