note 68796 added to function.openssl-x509-read
| From: | GabeMartin-Dempesy at mudbugmedia dot com | Date: | Thu, 10 Aug 2006 22:04:32 +0000 |
| Subject: | note 68796 added to function.openssl-x509-read | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115779@lists.php.net to get a copy of this message | ||
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);
/**
* Convert a timestamp from openssl_x509_parse to a unix timestamp
* @param string $in openssl timestamp
* @return integer unix timestamp
*/
function openssl_to_timestamp ($in) {
$year = substr($in, 0, 2); /* NOTE: Yes, this returns a two digit year */
$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
----
Server IP: 64.71.164.2
Probable Submitter: 69.17.126.74
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.openssl-x509-read.php
Edit -- https://master.php.net/note/edit/68796
Del: integrated -- https://master.php.net/note/delete/68796/integrated
Del: useless -- https://master.php.net/note/delete/68796/useless
Del: bad code -- https://master.php.net/note/delete/68796/bad+code
Del: spam -- https://master.php.net/note/delete/68796/spam
Del: non-english -- https://master.php.net/note/delete/68796/non-english
Del: in docs -- https://master.php.net/note/delete/68796/in+docs
Del: other reasons-- https://master.php.net/note/delete/68796
Reject -- https://master.php.net/note/reject/68796
Search -- https://master.php.net/manage/user-notes.php