note 81871 added to function.openssl-x509-parse

From: Date: Mon, 17 Mar 2008 13:22:42 +0000
Subject: note 81871 added to function.openssl-x509-parse
Groups: php.notes 
Request: Send a blank email to php-notes+get-137125@lists.php.net to get a copy of this message
Re: the previous note: support for the x509v3 extensions was added in PHP 5.2. Also in PHP5 prior to 5.2.4 the values of the x509v3 extensions were not decoded and were returned in the DER binary representation. Therefore in order to read the contents of the v3 extensions you have to parse the relevant ASN.1 structures yourself. For example if one needs to read an IA5STRING value in a private extension with the OID 1.3.6.1.4.1.7782.3.3 one can do : <?php /* parse a DER encoded representation of a IA5STRING of length < 127 */ function asn1der_ia5string($str) { $len=strlen($str)-2; if ($len < 0 && $len > 127) { return false; } /* check tag and len */ if (22 != (ord($str[$pos++]) & 0x1f) && ord($str[$pos++]) != $len) { /* not a valid DER encoding of an IA5STRING */ return false; } return substr($str, 2, $len); } $cert = openssl_x509_parse($pemcert); print (asn1der_ia5string($cert['extensions']['1.3.6.1.4.1.7782.3.3'])); // prints decoded ascii string ?> In newer versions (>5.2.3) the extensions are returned in a 'readable format'. For example: <?php print_r(openssl_x509_parse(...)); ?> will result in <? Array ( [name] => /C=GR/O=SOMETHING/CN=ME/ ... [extensions] => Array ( [basicConstraints] => CA:FALSE [keyUsage] => Digital Signature, Non Repudiation, Key Encipherment [extendedKeyUsage] => E-mail Protection, TLS Web Client Authentication [nsCertType] => SSL Client, S/MIME .... ?> ---- Server IP: 85.196.20.153 Probable Submitter: 195.134.100.30 ---- Manual Page -- http://www.php.net/manual/en/function.openssl-x509-parse.php Edit -- https://master.php.net/note/edit/81871 Del: integrated -- https://master.php.net/note/delete/81871/integrated Del: useless -- https://master.php.net/note/delete/81871/useless Del: bad code -- https://master.php.net/note/delete/81871/bad+code Del: spam -- https://master.php.net/note/delete/81871/spam Del: non-english -- https://master.php.net/note/delete/81871/non-english Del: in docs -- https://master.php.net/note/delete/81871/in+docs Del: other reasons-- https://master.php.net/note/delete/81871 Reject -- https://master.php.net/note/reject/81871 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137125) next »