Short HOWTO for getting data out of a client certificate via an SSL enabled iPlanet (Netscape Enterprise or Sun ONE) web server.
The iPlanet server sets $_SERVER["CLIENT_CERT"] whenever a client authenticates with a certificate. This variable contains an encoded representation of the certificate presented by the client. This in itself is useless to scripts or applications, we need to extract the actual information from the encoding. It turns out that we are in luck, the encoding is NEARLY a standard PEM encoding which can be read by the openssl_x509_read() function. A standard PEM has a begin line, an end line and inbetween is a base64 encoding of the DER representation of the certificate. PEM requires that linefeeds be present every 64 characters, however this is already the case with our CLIENT_CERT variable. For some reason the iPlanet server neglects to attach the begin and end headers, all that is required to allow access to the certificate is replacing these headers. Here is a small code excerpt for doing just that and printing out the raw certificate data.
$beginpem = "-----BEGIN CERTIFICATE-----\n";
$endpem = "-----END CERTIFICATE-----\n";
function print_element($item, $key)
if( is_array( $item ) )
echo "$key is Array:\n";
array_walk( $item, 'print_element' );
echo "$key done\n";
echo "$key = $item\n";
$pemdata = $beginpem.$_SERVER["CLIENT_CERT"]."\n".$endpem;
$cert = openssl_x509_read( $pemdata );
$cert_data = openssl_x509_parse( $cert );
array_walk( $cert_data, 'print_element' );
openssl_x509_free( $cert );