<?php
##even having this page is rather silly but we do.  It used to be a login with a capcha.
#This is where we return with the stub or provisional identity certificate.
#All we do is insert the stub into the certificate table and create a row in the enrollee table.
$newby=1;
require("includes/.htconfig.php");

##If we return alive from .htconfig, the certificate is not in the database.
			$lusk=openssl_x509_parse($_SERVER["SSL_CLIENT_CERT"]);
      $start=substr($lusk["validFrom"],0,12);
      $end=substr($lusk["validTo"],0,12);

$query="insert into certificate set "
      ."certificate_type_code='pro'"
      .",serial_number=$serial"
      .",date_issued='$start'"
      .",valid_until='$end'"
      .",certificate_provider='".$_SERVER["SSL_CLIENT_I_DN_CN"]."'"
      .",certificate='".trim($_SERVER["SSL_CLIENT_CERT"])."'";
if (mysql_query($query))
{
  $certificate_id=mysql_insert_id();
  $query="insert into enrollee set "
        ."certificate_id=$certificate_id"
        .",activFlag=1";
  if (mysql_query($query))
  {
    $enrollee_id=mysql_insert_id();
    advancePage($enrollee_id,$newby);
  }
  else
  {
    reporterror("inserting a row into enrollee for certificate $certificate_id",$query);
    echo "Something went terribly wrong, we shall look into it for you.";
  }
}
else
{
  reporterror("inserting a new certificate",$query);
  echo "Something went terribly wrong, we shall investigate this forthwith.";
}
?>
