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



function asn1der_ia5string ( $str )

{

$len = strlen ( $str )- 2 ;

if ( $len < 0 && $len > 127 ) {

return false ;

}



if ( 22 != ( ord ( $str [ $pos ++]) & 0x1f ) &&

ord ( $str [ $pos ++]) != $len ) {

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' ])); ?>



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

....

?>