[Main page x509.w0.dk]

Client Certificate Demo

Error: The server did not receive a PKCS#12 certificate from your browser.

Something went wrong. You have not imported the client certificate correctly.

Go back to https://x509.w0.dk/ and import the client certificate.


Source code

Here is the source code for index.php:

<?php
// vim: ts=4 :
/*  CREATE TABLE users(email TEXT PRIMARY KEY, serial TEXT, cn TEXT, challenge TEXT, end TEXT); */
$email "";
$regex =  "echo \$_SERVER[\"SSL_CLIENT_S_DN\"]";
if (isset(
$_SERVER["SSL_CLIENT_S_DN"])) {
    
$email $_SERVER["SSL_CLIENT_S_DN"];
    if (
preg_match("/([^=]+@[^,]+)/i"$_SERVER["SSL_CLIENT_S_DN"], $m)) {
        
$email $m[1];
        
$regex "if (preg_match(\"/([^=]+@[^,]+)/i\", \$_SERVER[\"SSL_CLIENT_S_DN\"], \$m)) echo \$m[1]";
    }
}
?><!DOCTYPE html><html lang="en"><head>
<title>Client Certificate Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
    body {
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
    BODY {
        margin: 2em;
    }
    TABLE {
        border: 1px solid;
        border-collapse: collapse;
    }
    TH, TD {
        border: 1px solid;
    }
    TH {
        text-align: left;
    }
</style>
</head>
<body>
<p>[Main page <a href="https://x509.w0.dk/">x509.w0.dk</a>]</p>
    <h1>Client Certificate Demo</h1>
<?php if (== strlen($_SERVER["SSL_CLIENT_SERIAL"].$_SERVER["SSL_CLIENT_FINGERPRINT"])) { ?>
<p>Error: The server did not receive a PKCS#12 certificate from your browser.</p>
<p>Something went wrong. You have not imported the client certificate correctly.</p>
<p>Go back to <a href="https://x509.w0.dk/">https://x509.w0.dk/</a> and import the client certificate.</p>
<?php } else { ?>
<h2>Welcome: &lt;<?= $email ?>&gt; '<?= $_SERVER["SSL_CLIENT_SERIAL"?>'.</h2>
<p>Source: <tt>Welcome: &amp;lt;&lt;?php <?= $regex ?> ?&gt;&amp;gt; '&lt;?= $_SERVER["SSL_CLIENT_SERIAL"] ?&gt;'</tt></p>
<p>Welcome <b><?= $email ?></b>.
Currently we have not registered and approved your serial number
'<b><?= $_SERVER["SSL_CLIENT_SERIAL"?></b>'.
This will either be done by our admin or email-confirm blah blah blah (not implemented yet)
</p>
<br />
<hr />
<table summary="Environment">
<caption>Environment variables which match <tt>SSL_*</tt></caption>
<thead><tr><th>Key</th><th>Value</th></tr></thead>
<tbody>
<?php
foreach ($_SERVER as $key => $value) {
    if (
preg_match("/SSL_/"$key)) {
        if (
strlen($value) > 80) {
            
$value substr($value,0,70)."...";
        }
        echo 
"<tr><td>$key</td><td><tt>$value</tt></td></tr>\n";
    }
}
?>
</tbody></table>
<?php /* end-if */ ?>
<?php 
#phpinfo(32);
?>

<!-- pre><?php
$vars 
= array('CCA''FORM''FORMAT''HTTP_ACCEPT_LANGUAGE''HTTP_HOST''HTTP_REFERER'"HTTPS"'HTTP_USER_AGENT''LANG''ORIENTATION'"REMOTE_ADDR"'REMOTE_HOST''SCRIPT_NAME''SERVER_NAME''SSL_CLIENT_I_DN''SSL_CLIENT_SERIAL''SSL_CLIENT_S_DN''SSL_CLIENT_S_DN_CN''SSL_CLIENT_S_DN_G''SSL_CLIENT_S_DN_S''SSL_CLIENT_VERIFY');
foreach (
$vars as $v) {
    echo 
"\$_SERVER['$v'] = ".$_SERVER[$v]."\n";
}
?></pre -->

<!-- hr>
<h2>Javascript</h2>
<p id = "value"> </p>
<script>
document.getElementById("value").innerHTML =
"The full windows href URL of the page is:<br>" 
+ window.location.ssl_foo_email + " "
+ window.location.href;
</script -->

<hr>
<h2>Source code</h2>
<p>Here is the source code for <tt>index.php</tt>:</p>
<?php show_source(__FILE__); ?>

    </body>
</html>