Skip to content

Commit

Permalink
updated to give a summary Screen, show_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
cuediin committed Aug 9, 2016
1 parent 42c5d33 commit 43fdf96
Show file tree
Hide file tree
Showing 14 changed files with 763 additions and 351 deletions.
14 changes: 7 additions & 7 deletions include/functions_ca.php
@@ -1,20 +1,19 @@
<?PHP
function switch_ca() {
function switch_ca_form() {
session_unset();
include("./include/settings.php");
$config=update_config();
$dh = opendir($config['certstore_path']) or die('Fatal: Unable to opendir Certificate Store.');
?>

<b>Switch to a diff CA<BR></b>
<b>Switch to a different CA<br \></b>
If you wish to create a new Sub-CA please select create CSR and select device type as Sub_CA.

<form action="index.php" method="post">
<input type="hidden" name="menuoption" value="menu"/>
<input type="hidden" name="menuoption" value="switchca"/>
<table style="width: 350px;">
<tr><td>Certificate Authority:<td><select name="ca_name" rows="6">
<option value="">--- Select a CA
<option value="zzCREATEZZnewZZ">Create New Root CA</option>
<?php
<?PHP
while (($file = readdir($dh)) !== false) {
// if (substr($file, -4) == ".csr") {
if ( is_dir($config['certstore_path'].$file) && ($file != '.') && ($file != '..') ) {
Expand All @@ -35,7 +34,7 @@ function delete_ca_form(&$my_errors=array('errors' => FALSE)) {
?>
<h1>PHP-CA Delete CA</h1>
<?PHP
include("./include/settings.php");
$config=update_config();
$dh = opendir($config['certstore_path']) or die('Fatal: Unable to opendir Certificate Store.');
if ($my_errors['errors']) {
if (!$my_errors['valid_text'])
Expand Down Expand Up @@ -220,4 +219,5 @@ function download_crl($this_crl,$crl_ext,$crl_filename) {
}
}


?>
71 changes: 43 additions & 28 deletions include/functions_cert.php
Expand Up @@ -7,7 +7,7 @@
// =================== DOWNLOAD CERT =====================================================================================
// ==================================================================================================================

function download_cert_form(){
function download_cert_form(){
$config=$_SESSION['config'];
?>
<p>
Expand Down Expand Up @@ -86,7 +86,7 @@ function download_cert($this_cert,$cer_ext) {
// =================== CONVERT CERT PKCS12 =====================================================================================
// ==================================================================================================================

function convert_cert_pkcs12_form(){
function convert_cert_pkcs12_form(){
$config=$_SESSION['config'];
?>
<p>
Expand Down Expand Up @@ -184,7 +184,7 @@ function convert_cert_pkcs12($this_cert_name,$my_pkey_pass,$my_pkcs12_pass){
// =================== REVOKE CERT =====================================================================================
// ==================================================================================================================

function revoke_cert_form(){
function revoke_cert_form($my_values=array('cert_serial'=>-99)){
$config=$_SESSION['config'];
?>
<p>
Expand All @@ -201,10 +201,12 @@ function revoke_cert_form(){
$pattern = '/(\D)\t(\d+[Z])\t(\d+[Z])?\t([a-z0-9]+)\t(\D+)\t(.+)/';
while (!feof($my_index_handle)) {
$this_line = rtrim(fgets($my_index_handle));
if (preg_match($pattern,$this_line,$matches))
if (preg_match($pattern,$this_line,$matches)) {
if ($matches[1] == 'V') {
print "<option value=\"".$matches[4]."\">".$matches[4]."<BR>".$matches[6]."</option>\n";
if ( $my_values['cert_serial'] == $matches[4]) $this_selected=" selected=\"selected\""; else $this_selected="";
print "<option value=\"".$matches[4]."\" $this_selected>".$matches[4].$matches[6]."</option>\n";
}
}
}
fclose($my_index_handle);
?>
Expand Down Expand Up @@ -323,11 +325,6 @@ function view_cert_details_form(){

function view_cert($my_certfile) {
$config=$_SESSION['config'];
?>
<h1>Viewing certificate request</h1>

<?php
print "<b>Loading Certificate from file...</b><br/>";
if ($my_certfile == "zzTHISzzCAzz" )
{
$my_cert = openssl_x509_parse(file_get_contents($config['cacert']));
Expand All @@ -340,26 +337,44 @@ function view_cert($my_certfile) {
$my_cert = openssl_x509_parse(file_get_contents($config['cert_path'].$my_base64_certfile));
}

$my_details = $my_cert['subject'];
//print_r($my_cert);

print "Done<br/><br/>\n";
print "<BR><BR><BR>\n\n\n";
?>
<table style="width:500px;" border=1>
<tr><th width=200>Common Name<BR>(eg www.golf.local)</th><td><?PHP print $my_details['CN'];?></td></tr>
<tr><th>Serial Number</th><td><?PHP print $my_cert['serialNumber'];?></td></tr>
<tr><th>Contact Email Address</th><td><?PHP print $my_details['emailAddress'];?></td></tr>
<tr><th>Organizational Unit Name</th><td><?PHP print $my_details['OU'];?></td></tr>
<tr><th>Organization Name</th><td><?PHP print $my_details['O'];?></td></tr>
<tr><th>City</th><td><?PHP print $my_details['L'];?></td></tr>
<tr><th>State</th><td><?PHP print $my_details['ST'];?></td></tr>
<tr><th>Country</th><td><?PHP print $my_details['C'];?></td></tr>
</table>
<?PHP
print "<h1>Viewing certificate request</h1>";
print get_cert_html($my_cert);
print "\n\n<br><br><b>Completed.</b><br/>";
}


function get_cert_html($my_cert) {
$this_html = "";
$this_html .= "<table style='width:500px;' border=1>";
$this_html .= "<tr><td colspan=2 align=center><b>Name</TD></tr>";
$this_html .= "<tr><td colspan=2 align=center>".$my_cert['name']."</tr>";
$this_html .= "<tr><td colspan=2 align=center><b>Subject Details</TD></tr>";
$this_html .= "<tr><th width=200>Common Name</th><td>".$my_cert['subject']['CN']."</td></tr>";
$this_html .= "<tr><th>Contact Email Address</th><td>".$my_cert['subject']['emailAddress']."</td></tr>";
$this_html .= "<tr><th>Organizational Unit Name</th><td>".$my_cert['subject']['OU']."</td></tr>";
$this_html .= "<tr><th>Organization Name</th><td>".$my_cert['subject']['O']."</td></tr>";
$this_html .= "<tr><th>City</th><td>".$my_cert['subject']['L']."</td></tr>";
$this_html .= "<tr><th>State</th><td>".$my_cert['subject']['ST']."</td></tr>";
$this_html .= "<tr><th>Country</th><td>".$my_cert['subject']['C']."</td></tr>";
$this_html .= "<tr><td colspan=2 align=center><b>Issuer Details</TD></tr>";
$this_html .= "<tr><th width=200>Common Name</th><td>".$my_cert['issuer']['CN']."</td></tr>";
$this_html .= "<tr><th>Contact Email Address</th><td>".$my_cert['issuer']['emailAddress']."</td></tr>";
$this_html .= "<tr><th>Organizational Unit Name</th><td>".$my_cert['issuer']['OU']."</td></tr>";
$this_html .= "<tr><th>Organization Name</th><td>".$my_cert['issuer']['O']."</td></tr>";
$this_html .= "<tr><th>City</th><td>".$my_cert['issuer']['L']."</td></tr>";
$this_html .= "<tr><th>State</th><td>".$my_cert['issuer']['ST']."</td></tr>";
$this_html .= "<tr><th>Country</th><td>".$my_cert['issuer']['C']."</td></tr>";
$this_html .= "<tr><td colspan=2 align=center><b>Details</TD></tr>";
$this_html .= "<tr><th>Hash</th><td>".$my_cert['hash']."</td></tr>";
$this_html .= "<tr><th>Serial Number</th><td>".str_pad($my_cert['serialNumber'],4,'0', STR_PAD_LEFT)."</td></tr>";
$this_html .= "<tr><th>Valid From</th><td>".$my_cert['validFrom']."</td></tr>";
$this_html .= "<tr><th>Valid To</th><td>".$my_cert['validTo']."</td></tr>";
$this_html .= "<tr><th>validFrom_time_t</th><td>".date('Y-m-d H:i:s',$my_cert['validFrom_time_t'])."</td></tr>";
$this_html .= "<tr><th>validTo_time_t</th><td>".date('Y-m-d H:i:s',$my_cert['validTo_time_t'])."</td></tr>";
$this_html .= "<tr><th>Signature Type SN</th><td>".$my_cert['signatureTypeSN']."</td></tr>";
$this_html .= "<tr><th>Signature Type LN</th><td>".$my_cert['signatureTypeLN']."</td></tr>";
$this_html .= "<tr><th>Signature Type NID</th><td>".$my_cert['signatureTypeNID']."</td></tr>";
$this_html .= "</table>";
return $this_html;
}

?>
50 changes: 27 additions & 23 deletions include/functions_csr.php
Expand Up @@ -3,7 +3,7 @@
// =================== CREATE CSR =====================================================================================
// ==================================================================================================================

function createCSR_form(){
function createCSR_form(){
$config=$_SESSION['config'];
$my_x509_parse = openssl_x509_parse(file_get_contents($config['cacert']));
?>
Expand Down Expand Up @@ -54,8 +54,8 @@ function create_csr($my_cert_dn,$my_keysize,$my_passphrase,$my_device_type) {
$my_csrfile = $my_csrfile.":";
}
$my_csrfile=substr($my_csrfile,0,strrpos($my_csrfile,':'));
print $my_csrfile;
$filename=base64_encode($my_csrfile);
print $my_csrfile;
if ($my_device_type=='ca_cert') {
$client_keyFile = $config['cakey'];
$client_reqFile = $config['req_path'].$filename.".pem";
Expand Down Expand Up @@ -116,7 +116,7 @@ function create_csr($my_cert_dn,$my_keysize,$my_passphrase,$my_device_type) {
// =================== DOWNLOAD CSR =====================================================================================
// ==================================================================================================================

function download_csr_form(){
function download_csr_form(){
$config=$_SESSION['config'];
?>
<p>
Expand All @@ -133,7 +133,7 @@ function download_csr_form(){
<tr><th>Rename Extension to .pfx</th><td><input type="radio" name="pfx_ext" value="FALSE" checked /> No <input type="radio" name="cer_ext" value="PFX" /> Yes</td></tr>
*/
?>
<tr><td width=100>Name:<td><select name="cert_name" rows="6">
<tr><td width=100>Name:<td><select name="csr_name" rows="6">
<option value="">--- Select a CSR
<?php
$dh = opendir($config['req_path']) or die('Unable to open ' . $config['req_path']);
Expand Down Expand Up @@ -195,7 +195,7 @@ function download_csr($this_cert,$cer_ext) {
// ==================================================================================================================


function import_CSR_form(){
function import_CSR_form(){
$config=$_SESSION['config'];
?>
<p>
Expand Down Expand Up @@ -244,7 +244,7 @@ function import_csr($my_csr) {



function upload_CSR_form(){
function upload_CSR_form(){
$config=$_SESSION['config'];
?>
<p>
Expand Down Expand Up @@ -325,7 +325,7 @@ function upload_csr($uploaded_file) {
// ==================================================================================================================


function view_csr_details_form(){
function view_csr_details_form(){
$config=$_SESSION['config'];
?>

Expand Down Expand Up @@ -388,8 +388,8 @@ function view_csr($my_csrfile) {

<?php
print "<b>Loading CSR from file...</b><br/>";
$fp = fopen($config['req_path'].$my_base64_csrfile, "r") or die('Fatal: Error opening CSR file'.$my_base64_csrfile);
$my_csr = fread($fp, filesize($config['req_path'].$my_base64_csrfile)) or die('Fatal: Error reading CSR file'.$my_base64_csrfile);
$fp = fopen($config['req_path'].$my_base64_csrfile, "r") or die('Fatal: Error opening CSR file '.$my_base64_csrfile);
$my_csr = fread($fp, filesize($config['req_path'].$my_base64_csrfile)) or die('Fatal: Error reading CSR file '.$my_base64_csrfile);
fclose($fp) or die('Fatal: Error closing CSR file '.$my_base64_csrfile);
print "Done<br/><br/>\n";
print $my_csr;
Expand All @@ -398,14 +398,14 @@ function view_csr($my_csrfile) {
$my_public_key_details=openssl_pkey_get_details(openssl_csr_get_public_key($my_csr));
?>
<table style="width: 90%;">
<tr><th width=100>Common Name (eg www.golf.local)</th><td><?PHP print $my_details[CN];?></td></tr>
<tr><th>Contact Email Address</th><td><?PHP print $my_details[emailAddress];?></td></tr>
<tr><th>Organizational Unit Name</th><td><?PHP print $my_details[OU];?></td></tr>
<tr><th>Organization Name</th><td><?PHP print $my_details[O];?></td></tr>
<tr><th>City</th><td><?PHP print $my_details[L];?></td></tr>
<tr><th>State</th><td><?PHP print $my_details[ST];?></td></tr>
<tr><th>Country</th><td><?PHP print $my_details[C];?></td></tr>
<tr><th>Key Size</th><td><?PHP print $my_public_key_details[bits];?></td></tr>
<tr><th width=100>Common Name (eg www.golf.local)</th><td><?PHP print $my_details['CN'];?></td></tr>
<tr><th>Contact Email Address</th><td><?PHP print $my_details['emailAddress'];?></td></tr>
<tr><th>Organizational Unit Name</th><td><?PHP print $my_details['OU'];?></td></tr>
<tr><th>Organization Name</th><td><?PHP print $my_details['O'];?></td></tr>
<tr><th>City</th><td><?PHP print $my_details['L'];?></td></tr>
<tr><th>State</th><td><?PHP print $my_details['ST'];?></td></tr>
<tr><th>Country</th><td><?PHP print $my_details['C'];?></td></tr>
<tr><th>Key Size</th><td><?PHP print $my_public_key_details['bits'];?></td></tr>
</table>
<?PHP
print "\n\n<br><br><b>Completed.</b><br/>";
Expand All @@ -417,7 +417,7 @@ function view_csr($my_csrfile) {
// ==================================================================================================================


function sign_csr_form(){
function sign_csr_form($my_values=array('csr_name'=>'::zz::')){
$config=$_SESSION['config'];
?>
<p>
Expand All @@ -428,7 +428,9 @@ function sign_csr_form(){
$dh = opendir($config['req_path']) or die('Unable to open requests path');
while (($file = readdir($dh)) !== false) {
if ( ($file !== ".htaccess") && is_file($config['req_path'].$file) ) {
if (!is_file($config['cert_path'].$file) ) {
$name = base64_decode(substr($file, 0,strrpos($file,'.')));
$ext = substr($file, strrpos($file,'.'));
if (!is_file($config['cert_path'].$file) or ($my_values['csr_name'] == "$name$ext") ) {
$valid_files++;
}
}
Expand All @@ -446,13 +448,15 @@ function sign_csr_form(){
<tr><td>Name:<td><select name="csr_name" rows="6">
<option value="">--- Select a CSR
<?php

$dh = opendir($config['req_path']) or die('Unable to open requests path');
while (($file = readdir($dh)) !== false) {
if ( ($file !== ".htaccess") && is_file($config['req_path'].$file) ) {
if (!is_file($config['cert_path'].$file) ) {
$name = base64_decode(substr($file, 0,strrpos($file,'.')));
$ext = substr($file, strrpos($file,'.'));
print "<option value=\"$name$ext\">$name$ext</option>\n";
$name = base64_decode(substr($file, 0,strrpos($file,'.')));
$ext = substr($file, strrpos($file,'.'));
if (!is_file($config['cert_path'].$file) or ($my_values['csr_name'] == "$name$ext") ) {
if ( $my_values['csr_name'] == "$name$ext") $this_selected=" selected=\"selected\""; else $this_selected="";
print "<option value=\"$name$ext\"".$this_selected.">$name$ext</option>\n";
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions include/functions_key.php
Expand Up @@ -4,7 +4,7 @@
// =================== CHECK KEY PASSPHRASE =====================================================================================
// ==================================================================================================================

function check_key_passphrase_form(){
function check_key_passphrase_form($my_values=array('key_name'=>'::zz::')){
$config=$_SESSION['config'];
?>
<p>
Expand All @@ -21,9 +21,10 @@ function check_key_passphrase_form(){
$dh = opendir($config['key_path']) or die('Unable to open ' . $config['key_path']);
while (($file = readdir($dh)) !== false) {
if ( ($file !== ".htaccess") && is_file($config['key_path'].$file) ) {
if ( $my_values['key_name'] == "$name$ext") $this_selected=" selected=\"selected\""; else $this_selected="";
$name = base64_decode(substr($file, 0,strrpos($file,'.')));
$ext = substr($file, strrpos($file,'.'));
print "<option value=\"$name$ext\">$name$ext</option>\n";
print "<option value=\"$name$ext\"".$this_selected.">$name$ext</option>\n";
}
}
?>
Expand Down

0 comments on commit 43fdf96

Please sign in to comment.