From 6703d98ec9d2a6a0166e3357bdab4efa2adbb63a Mon Sep 17 00:00:00 2001 From: John Crisp Date: Wed, 3 Mar 2021 17:15:01 +0100 Subject: [PATCH] Format with CodeSniffer --standard=PSR2 --- about.php | 11 +- admin/index.php | 201 +++--- ca/index.php | 1 - ca/main.php | 308 +++++---- ca/manage_certs.php | 757 +++++++++++---------- ca/policy.html | 78 +-- ca/request_cert.php | 738 ++++++++++---------- config.php | 1 - css/style.css | 206 +++--- gen_crl.php | 2 - help.php | 11 +- help/PKI_basics.html | 68 +- help/cacert_install_ie.html | 64 +- help/glossary.html | 305 +++++---- help/usercert_install_ie.html | 79 ++- include/common.php | 236 +++---- include/my_functions.php | 273 ++++---- include/openssl_functions.php | 1196 +++++++++++++++++---------------- main.php | 110 ++- ns_revoke_query.php | 14 +- policy.html | 17 +- readme.php | 1 - search.php | 221 +++--- 23 files changed, 2494 insertions(+), 2404 deletions(-) diff --git a/about.php b/about.php index 3b02606..267ae99 100644 --- a/about.php +++ b/about.php @@ -1,31 +1,32 @@ +

PHPki is an Open Source Web application for managing a help/glossary.html#PKI target=help/glossary> Public Key Infrastructure within a small organizations. PHPki acts as a mechanism for the centralized creation and management of digital certificates. PHPki is capable of managing certificates for multiple organizations or user -accounts. +accounts.

PHPki requires the Apache Web Server, the PHP Scripting Language, and OpenSSL, all of which are included with any major Linux Operating System distribution. +

This software may be freely redistributed under the terms of the GNU Public License provided this page and all copyright notices remain completely intact. +

+

Copyright: 2003, William E. Roadcap

@@ -36,7 +37,7 @@
-

+

Contents of '.htvar($config['passwd_file']).' file:

';
         readfile($config['passwd_file'])
 
-	?>
-	
-
- -
- + +
+ +
+ - -
- - - - - -

Add User or Change Password

User ID
Password
Verify Password
- - -
- + +
+ + + + + +

Add User or Change Password

User ID
Password
Verify Password
+ + +
+

Missing or invalid password or password and password verification do not match.

" + case 'add_user': + printHeader('admin'); + if (! $passwd || ! $passwdv || $passwd != $passwdv || strlen($passwd) < 8) { + print "

Missing or invalid password or password and password verification do not match.

" - ?> -

-
- - - -
- +

+
+ + + +
+ '; - system("htpasswd -bm $pwdfile $login $passwd 2>&1") - ?> -

-

- -
- '; + system("htpasswd -bm $pwdfile $login $passwd 2>&1") + ?> +

+

+ +
+ - -
- - - -

Remove User

User ID
- - -
- + +
+ + + +

Remove User

User ID
+ + +
+ '; - system("htpasswd -D $pwdfile $login 2>&1") - ?> -

-

- -
- '; + system("htpasswd -D $pwdfile $login 2>&1") + ?> +

+

+ +
+ -
-
-
- - - -
-

- +
+
+
+ + + +
+

+ diff --git a/ca/index.php b/ca/index.php index ed365f3..5c6e24f 100644 --- a/ca/index.php +++ b/ca/index.php @@ -1,3 +1,2 @@ diff --git a/ca/main.php b/ca/main.php index 1b7e743..e18455e 100644 --- a/ca/main.php +++ b/ca/main.php @@ -8,161 +8,159 @@ $stage = gpvar('stage'); -switch($stage) { - -case 'dl_takey': - upload($config['private_dir'] . '/takey.pem', $config['ca_prefix'] . 'takey.pem', 'application/octet-stream'); - break; - -case 'dl_dhparam': - upload($config['private_dir'] . '/dhparam2048.pem', $config['ca_prefix'] . 'dhparam2048.pem', 'application/octet-stream'); - break; - -case 'dl_root': - upload($config['cacert_pem'], $config['ca_prefix'] . 'cacert.crt', 'application/x-x509-ca-cert'); - break; - -case 'dl_crl': - upload($config['cacrl_der'], $config['ca_prefix'] . 'cacrl.crl', 'application/pkix-crl'); - break; - -case 'dl_crl_pem': - upload($config['cacrl_pem'], $config['ca_prefix'] . 'cacrl.crl', 'application/octet-stream'); - break; - -case 'gen_crl': - list($ret,$errtxt) = CA_generate_crl(); - - printHeader(false); - - if ($ret) { - ?> -

Certificate Revocation List Updated

-
-
- -
- '.CA_crl_text().''; - } - else { - ?> - -

There was an error updating the Certificate Revocation List.


-
-

Debug Info:

-
-
-
-
- -
-
- -

OpenVPN pre-shared Key

-
-
- -
- '.ta_key_text().''; - break; - -case 'display_dhparam': - printHeader(false); - - ?> -

OpenVPN Diffie-Helman parameters

-
-
- -
- '.dhparam_text().''; - break; - -case 'display_root_pem': - printHeader(false); - - ?> -

Root certificate file (PEM Encoded)

-
-
- -
- '.root_pem_text().''; - break; - - -default: - printHeader('ca'); - ?> -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
-

- +

Certificate Revocation List Updated

+
+
+ +
+ '.CA_crl_text().''; + } else { + ?> + +

There was an error updating the Certificate Revocation List.


+
+

Debug Info:

+
+
+
+
+ +
+
+ +

OpenVPN pre-shared Key

+
+
+ +
+ '.ta_key_text().''; + break; + + case 'display_dhparam': + printHeader(false); + + ?> +

OpenVPN Diffie-Helman parameters

+
+
+ +
+ '.dhparam_text().''; + break; + + case 'display_root_pem': + printHeader(false); + + ?> +

Root certificate file (PEM Encoded)

+
+
+ +
+ '.root_pem_text().''; + break; + + + default: + printHeader('ca'); + ?> +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ diff --git a/ca/manage_certs.php b/ca/manage_certs.php index 06704f0..ea2f33b 100644 --- a/ca/manage_certs.php +++ b/ca/manage_certs.php @@ -22,404 +22,403 @@ # Prevent handling certs that don't belong to user -if ($serial && CAdb_issuer($serial) != $PHPki_user && ! in_array($PHPki_user, $PHPki_admins)) { - $stage = 'goaway'; +if ($serial && CAdb_issuer($serial) != $PHPki_user && ! in_array($PHPki_user, $PHPki_admins)) { + $stage = 'goaway'; } -if ( !($show_valid.$show_revoked.$show_expired) ) { - $show_valid = 'V'; - $show_revoked = 'R'; - $show_expired = 'E'; +if (!($show_valid.$show_revoked.$show_expired)) { + $show_valid = 'V'; + $show_revoked = 'R'; + $show_expired = 'E'; } -$qstr_filter = 'search='.htvar($search) . '&' . "show_valid=$show_valid&" . "show_revoked=$show_revoked&" . "show_expired=$show_expired&"; +$qstr_filter = 'search='.htvar($search) . '&' . "show_valid=$show_valid&" . "show_revoked=$show_revoked&" . "show_expired=$show_expired&"; $qstr_sort = "sortfield=$sortfield&ascdec=$ascdec"; switch ($stage) { -case 'goaway': - printHeader(false); - ?> - -

YOU ARE A VERY BAD BOY!

- - - -

Certificate Details

-

(#)
')?>

- -

REVOKED '.$revoke_date.'

'; - } - - print '
'.CA_cert_text($serial).'
'; - break; - -case 'dl-confirm': - printHeader('ca'); - - $rec = CAdb_get_entry($serial); - - ?> -

You are about to download the PRIVATE certificate key for

-

DO NOT DISTRIBUTE THIS FILE TO THE PUBLIC!

-
- File type: - - -   or   - -
+ case 'goaway': + printHeader(false); + ?> + +

YOU ARE A VERY BAD BOY!

+ + + +

Certificate Details

+

(#)
')?>

+ +

REVOKED '.$revoke_date.'

'; + } + + print '
'.CA_cert_text($serial).'
'; + break; + + case 'dl-confirm': + printHeader('ca'); + + $rec = CAdb_get_entry($serial); + + ?> +

You are about to download the PRIVATE certificate key for

+

DO NOT DISTRIBUTE THIS FILE TO THE PUBLIC!

+
+ File type: + + +   or   + +
-

You are about to REVOKE the following certificate: -
- - + + '.htvar($rec['serial']).'
+ '.htvar($rec['common_name']).'
+ '.htvar($rec['email']).'
+ '.htvar($rec['organization']).'
+ '.htvar($rec['unit']).'
+ '.htvar($rec['locality']).'
+ '.htvar($rec['province']).'
+ '.htvar($rec['country']).'
+ +
-

+ break; + + case 'download': + if (strstr($submit, "Back")) { + $dl_type = ''; + } + + $rec = CAdb_get_entry($serial); + + switch ($dl_type) { + case 'PKCS#12': + upload($config['pfx_dir'] . "/$serial.pfx", "$rec[common_name].p12", 'application/x-pkcs12'); + break; + case 'PEMCERT': + upload($config['new_certs_dir'] . "/$serial.pem", "$rec[common_name]-cert.pem", 'application/pkix-cert'); + break; + case 'PEMKEY': + upload($config['private_dir'] . "/$serial-key.pem", "$rec[common_name]-key.pem", 'application/octet-stream'); + break; + case 'PEMBUNDLE': + upload(array($config['private_dir'] . "/$serial-key.pem",$config['new_certs_dir'] . "/$serial.pem"), $rec['common_name'] . "-Bundle.pem", 'application/octet-stream'); + break; + case 'PEMCABUNDLE': + upload(array($config['private_dir'] . "/$serial-key.pem",$config['new_certs_dir'] . "/$serial.pem", $config['cacert_pem']), $rec['common_name'] . "-CABundle.pem", 'application/octet-stream'); + break; + default: + header("Location: ${PHP_SELF}?$qstr_sort&$qstr_filter"); + } + break; + + case 'revoke-form': + $rec = CAdb_get_entry($serial); + + printHeader('ca'); + + ?> +

You are about to REVOKE the following certificate: +
+ + - - '.htvar($rec['serial']).'
- '.htvar($rec['common_name']).'
- '.htvar($rec['email']).'
- '.htvar($rec['organization']).'
- '.htvar($rec['unit']).'
- '.htvar($rec['locality']).'
- '.htvar($rec['province']).'
- '.htvar($rec['country']).'
- -
+

Serial Number
- User's Name
- Email Address
- Organization
- Department/Unit
- Locality
- State/Province
- Country
-

-
-

Are you sure?

-
- - -   - -
'; - - break; - -case 'revoke': - $ret = true; - if ($submit == 'Yes') - list($ret, $errtxt) = CA_revoke_cert($serial); - - if (! $ret) { - printHeader('ca'); - - print "
"; - ?> - -

There was an error revoking your certificate.


-
-

Debug Info:

-
-
-

- -

-

- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Certificate Renewal Form

This will Revoke the old Certificate and Create a new one
You can add a password if required
Common Name
E-mail Address
Organization
Department/Unit
Locality
State/Province
Country
Certificate Password
Certificate Life
  -   - - - -
-
- - + Email Address
+ Organization
+ Department/Unit
+ Locality
+ State/Province
+ Country
+

+
+

Are you sure?

+
+ + +   + +
'; + + break; + + case 'revoke': + $ret = true; + if ($submit == 'Yes') { + list($ret, $errtxt) = CA_revoke_cert($serial); + } + + if (! $ret) { + printHeader('ca'); + + print "
"; + ?> + +

There was an error revoking your certificate.


+
+

Debug Info:

+
+
+

+ +

+

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Certificate Renewal Form

This will Revoke the old Certificate and Create a new one
You can add a password if required
Common Name
E-mail Address
Organization
Department/Unit
Locality
State/Province
Country
Certificate Password
Certificate Life
  +   + + + +
+
+ + "; - ?> - -

There was an error creating your certificate.

-

-
-

Debug Info:

-
-
-

- -

- - - - - - + + '; + + $headings = array( + 'status'=>"Status", 'issued'=>"Issued", 'expires'=>"Expires", + 'common_name'=>"User's Name", 'email'=>"E-mail", + 'organization'=>"Organization", 'unit'=>"Department", + 'locality'=>"Locality" + ); + + foreach ($headings as $field => $head) { + print ''; + } + print ''; + print ''; + + $x = "^[$show_valid$show_revoked$show_expired]"; + + if (in_array($PHPki_user, $PHPki_admins)) { + $x = "$x.*$search"; + } else { + $x = "$x.*$search.*$PHPki_user|$x.*$PHPki_user.*$search"; + } + + $db = csort(CAdb_to_array($x), $sortfield, ($ascdec=='A'?SORT_ASC:SORT_DESC)); + + $stcolor = array('Valid'=>'green','Revoked'=>'red','Expired'=>'orange'); + + foreach ($db as $rec) { + print ' + + + + + + + + + '; + } + + print '
CERTIFICATE MANAGEMENT CONTROL PANEL
-
" method="get" name="filter"> + if (! $ret) { + printHeader('ca'); + + print ""; + ?> + +

There was an error creating your certificate.

+

+
+

Debug Info:

+
+
+

+ +

+

+ + + + + - - '; - - $headings = array( - 'status'=>"Status", 'issued'=>"Issued", 'expires'=>"Expires", - 'common_name'=>"User's Name", 'email'=>"E-mail", - 'organization'=>"Organization", 'unit'=>"Department", - 'locality'=>"Locality" - ); - - foreach($headings as $field=>$head) { - print ''; - } - print ''; - print ''; - - $x = "^[$show_valid$show_revoked$show_expired]"; - - if (in_array($PHPki_user, $PHPki_admins)) { - $x = "$x.*$search"; - } - else { - $x = "$x.*$search.*$PHPki_user|$x.*$PHPki_user.*$search"; - } - - $db = csort(CAdb_to_array($x), $sortfield, ($ascdec=='A'?SORT_ASC:SORT_DESC)); - - $stcolor = array('Valid'=>'green','Revoked'=>'red','Expired'=>'orange'); - - foreach($db as $rec) { - print ' - - - - - - - - - '; - } - - print '
CERTIFICATE MANAGEMENT CONTROL PANEL
+
" method="get" name="filter"> Search:        - >Valid + >Valid    - >Revoked + >Revoked    - >Expired + >Expired       - +
-
'.$head.''; - - if ($sortfield == $field) { - print ' '. - '\'Change'; - } - - print 'Actions
' .$rec[status].''.$rec['issued'].''.$rec['expires'].''.$rec['common_name'].'' . htvar($rec['email']) . ''.htvar($rec['organization']).''.htvar($rec['unit']).''.htvar($rec['locality']).''. - 'Display'; - - if ($rec['status'] == 'Valid') { - print ' - '. - 'Download - '. - 'Revoke'; - } - print ' - '. - 'Renew -
'; - - printFooter(); +
'.$head.''; + + if ($sortfield == $field) { + print ' '. + '\'Change'; + } + + print 'Actions
' .$rec[status].''.$rec['issued'].''.$rec['expires'].''.$rec['common_name'].'' . htvar($rec['email']) . ''.htvar($rec['organization']).''.htvar($rec['unit']).''.htvar($rec['locality']).''. + 'Display'; + + if ($rec['status'] == 'Valid') { + print ' + '. + 'Download + '. + 'Revoke'; + } + print ' + '. + 'Renew +
'; + + printFooter(); } ?> diff --git a/ca/policy.html b/ca/policy.html index 6f6ef88..4cdd9de 100644 --- a/ca/policy.html +++ b/ca/policy.html @@ -1,78 +1,34 @@ - + + -Certificate Authority Agreement + Certificate Authority Agreement +

Certificate Authority Agreement

-

Certificate Authority Agreement

-

Policy and Practices

+

Policy and Practices


+
-

-

This is a statement of practices by this Digital Certificate Authority. -Your use of this Certificate Authority constitutes your and/or your agency's -understanding and full acceptance of these practices and all associated risks. -Please have an authorized person at your agency sign this document and fax it to 000-000-0000 +

This is a statement of practices by this Digital Certificate Authority. Your use of this Certificate Authority constitutes your and/or your agency's understanding and full acceptance of these practices and all associated risks. Please have an authorized person at your agency sign this document and fax it to 000-000-0000

-

This document may not be all encompassing, and we reserve the right to modify it at any time. +

This document may not be all encompassing, and we reserve the right to modify it at any time.

- - diff --git a/ca/request_cert.php b/ca/request_cert.php index 2dbef6e..e39be0b 100644 --- a/ca/request_cert.php +++ b/ca/request_cert.php @@ -7,7 +7,7 @@ include('../include/openssl_functions.php') ; # User's preferences file -$user_cnf = $config['home_dir'] . "/config/user-".strtr($PHPki_user,'/\\','|#').'.php'; +$user_cnf = $config['home_dir'] . "/config/user-".strtr($PHPki_user, '/\\', '|#').'.php'; # Retrieve GET/POST values $form_stage = gpvar('form_stage'); @@ -48,355 +48,399 @@ switch ($form_stage) { + case 'validate': + $er = ''; + + if (! $country) { + $er .= 'Missing Country
'; + } + if (! $province) { + $er .= 'Missing State/Province
'; + } + if (! $locality) { + $er .= 'Missing Locality (City/County)
'; + } + if (! $organization) { + $er .= 'Missing Organization (Company/Agency)
'; + } + if (! $unit) { + $er .= 'Missing Unit/Department
'; + } + if (! $common_name) { + $er .= 'Missing E-mail User\'s Full Name
'; + } + if (! $email) { + $er .= 'Missing E-mail Address
'; + } + + if (($cert_type == 'email' || $cert_type == 'email_signing') && ! $passwd) { + $er .= 'Missing Certificate Password
'; + } + if (($cert_type == 'email' || $cert_type == 'email_signing') && ! $passwdv) { + $er .= 'Missing Certificate Password Verification "Again"
'; + } + + if ($passwd && strlen($passwd) < 8) { + $er .= 'Certificate password is too short.
'; + } + + if ($passwd and $passwd != $passwdv) { + $er .= 'Password and password verification do not match.
'; + } + + //if ( ! is_alnum($passwd) or ! is_alnum($passwdv) ) + // $er .= 'Password contains invalid characters.
'; + + if ($email && ! is_email($email)) { + $er .= 'E-mail address ('. htvar($email) . ') may be invalid.
'; + } + + $ip_ar=explode("\n", $ip_addr); + foreach ($ip_ar as $value) { + if ($value && ! is_ip($value)) { + $er .= 'IP address ('. htvar($value) . ') may be invalid.
'; + } + } + + $dns_n=explode("\n", $dns_names); + foreach ($dns_n as $value) { + if ($value && ! is_fqdn(trim($value))) { + $er .= 'DNS Name ('. htvar($value) . ') may be invalid.
'; + } + } + + if ($er) { + $er = '

ERROR(S) IN FORM:

' . $er . '

'; + } + + if ($email && ($serial = CAdb_in($email, $common_name))) { + $er = ''; + $certtext = CA_cert_text($serial); + $er .= '

A valid certificate already exists for ' . htvar("$common_name <$email>") . '

'; + $er .= '
 ' . htvar($certtext) . ' 
'; + } + + if ($er) { + printHeader(); + ?> + +
+ + +
+ + "; + + printFooter(); + break; + } + + case 'confirm': + printHeader(); + + ?> +

You are about to create a certificate using the following information:

+ + + + + +
+

+ User's Name
+ E-mail Address
+ Organization
+ Department/Unit
+ Locality
+ State/Province
+ Country
+ Certificate Life
+ Key Size
+ Certificate Use
+ '; + print 'IP Addresses
'; + } + ?> +

+
+ '; + print htvar($email) . '
'; + print htvar($organization) . '
'; + print htvar($unit) . '
'; + print htvar($locality) . '
'; + print htvar($province) . '
'; + print htvar($country) . '
'; + print htvar($expiry). ' Year'.($expiry == 1 ? '' : 's').'
'; + print htvar($keysize). ' bits
'; + + switch ($cert_type) { + case 'email': + print 'E-mail, SSL Client' . '
'; + break; + case 'email_signing': + print 'E-mail, SSL Client, Code Signing' . '
'; + break; + case 'server': + print 'SSL Server' . '
'; + print htvar($dns_names). '
'; + print htvar($ip_addr). '
'; + break; + case 'vpn_client': + print 'VPN Client Only' . '
'; + break; + case 'vpn_server': + print 'VPN Server Only' . '
'; + break; + case 'vpn_client_server': + print 'VPN Client, VPN Server' . '
'; + break; + case 'time_stamping': + print 'Time Stamping' . '
'; + } + ?> +
+ +

Are you sure?

+

+ + +   +   + +

+ + '; + fwrite($fp, $x); + fclose($fp); + + break; + + case 'final': + if ($submit == "Yes Create and Download" || $submit == "Yes. Just Create") { + if (! $serial = CAdb_in($email, $common_name)) { + list($ret,$errtxt) = CA_create_cert($cert_type, $country, $province, $locality, $organization, $unit, $common_name, $email, $expiry, $passwd, $keysize, $dns_names, $ip_addr); + + if (! $ret) { + printHeader(); + ?> +
+ +

There was an error creating your certificate.


+
+

Debug Info:

+
+
+

+ + +

+

+ + + +
+ + -case 'validate': - $er = ''; - - if (! $country) $er .= 'Missing Country
'; - if (! $province) $er .= 'Missing State/Province
'; - if (! $locality) $er .= 'Missing Locality (City/County)
'; - if (! $organization) $er .= 'Missing Organization (Company/Agency)
'; - if (! $unit) $er .= 'Missing Unit/Department
'; - if (! $common_name) $er .= 'Missing E-mail User\'s Full Name
'; - if (! $email) $er .= 'Missing E-mail Address
'; - - if (($cert_type == 'email' || $cert_type == 'email_signing') && ! $passwd) $er .= 'Missing Certificate Password
'; - if (($cert_type == 'email' || $cert_type == 'email_signing') && ! $passwdv) $er .= 'Missing Certificate Password Verification "Again"
'; - - if ( $passwd && strlen($passwd) < 8 ) - $er .= 'Certificate password is too short.
'; - - if ( $passwd and $passwd != $passwdv ) - $er .= 'Password and password verification do not match.
'; - - //if ( ! is_alnum($passwd) or ! is_alnum($passwdv) ) - // $er .= 'Password contains invalid characters.
'; - - if ( $email && ! is_email($email) ) - $er .= 'E-mail address ('. htvar($email) . ') may be invalid.
'; - - $ip_ar=explode("\n", $ip_addr); - foreach ($ip_ar as $value){ - if ( $value && ! is_ip($value) ) - $er .= 'IP address ('. htvar($value) . ') may be invalid.
'; - } - - $dns_n=explode("\n", $dns_names); - foreach ($dns_n as $value){ - if ( $value && ! is_fqdn(trim($value)) ) - $er .= 'DNS Name ('. htvar($value) . ') may be invalid.
'; - } - - if ( $er ) - $er = '

ERROR(S) IN FORM:

' . $er . '

'; - - if ($email && ($serial = CAdb_in($email,$common_name))) { - $er = ''; - $certtext = CA_cert_text($serial); - $er .= '

A valid certificate already exists for ' . htvar("$common_name <$email>") . '

'; - $er .= '
 ' . htvar($certtext) . ' 
'; - - } - - if ($er) { - printHeader(); - ?> - - - - -
- - "; - - printFooter(); - break; - } - -case 'confirm': - printHeader(); - - ?> -

You are about to create a certificate using the following information:

-

Certificate Request Form

- - - - -
-

- User's Name
- E-mail Address
- Organization
- Department/Unit
- Locality
- State/Province
- Country
- Certificate Life
- Key Size
- Certificate Use
- '; - print 'IP Addresses
'; - } - ?> -

-
- '; - print htvar($email) . '
'; - print htvar($organization) . '
'; - print htvar($unit) . '
'; - print htvar($locality) . '
'; - print htvar($province) . '
'; - print htvar($country) . '
'; - print htvar($expiry). ' Year'.($expiry == 1 ? '' : 's').'
'; - print htvar($keysize). ' bits
'; - - switch ($cert_type) { - case 'email': - print 'E-mail, SSL Client' . '
'; - break; - case 'email_signing': - print 'E-mail, SSL Client, Code Signing' . '
'; - break; - case 'server': - print 'SSL Server' . '
'; - print htvar($dns_names). '
'; - print htvar($ip_addr). '
'; - break; - case 'vpn_client': - print 'VPN Client Only' . '
'; - break; - case 'vpn_server': - print 'VPN Server Only' . '
'; - break; - case 'vpn_client_server': - print 'VPN Client, VPN Server' . '
'; - break; - case 'time_stamping': - print 'Time Stamping' . '
'; - - } - ?> -
- -

Are you sure?

-

- - -   -   - -

- - '; - fwrite($fp,$x); - fclose($fp); - - break; - -case 'final': - if ($submit == "Yes Create and Download" || $submit == "Yes. Just Create") { - if (! $serial = CAdb_in($email,$common_name)) { - list($ret,$errtxt) = CA_create_cert($cert_type, $country, $province, $locality, $organization, $unit, $common_name, $email, $expiry, $passwd, $keysize, $dns_names, $ip_addr); - - if (! $ret) { - printHeader(); - ?> -
- -

There was an error creating your certificate.


-
-

Debug Info:

-
-
-

- - -

-

- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + E-mail, SSL Client'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + ?> + + + + + + + + + + + + + + - - - - - - -

Certificate Request Form

Common Name*
(i.e. User real name or computer hostname - used as SubjectAltName)
E-mail Address *
Organization (Company/Agency)*
Department/Unit*
Locality (City/County)*
State/Province*
Country*
Certificate Password*
(Mandatory for Email,SSL Client,Code signing)
   Again
Certificate Life*
Key Size*
Certificate Use:*
E-mail Address *
Organization (Company/Agency)*
Department/Unit*
Locality (City/County)*
State/Province*
Country*
Certificate Password*
(Mandatory for Email,SSL Client,Code signing)
   Again
Certificate Life*
Key Size*
Certificate Use:*
  
  
* Fields are required
-
- * Fields are required + + + + diff --git a/config.php b/config.php index ffe6a06..5ce0432 100644 --- a/config.php +++ b/config.php @@ -1,3 +1,2 @@ diff --git a/css/style.css b/css/style.css index 2d67e76..2f38207 100644 --- a/css/style.css +++ b/css/style.css @@ -1,171 +1,171 @@ h1 { - font-size: 32px; + font-size: 32px; } h2 { - font-size: 24px; + font-size: 24px; } h3 { - font-size: 18px; + font-size: 18px; } body { - margin: 10px; - padding: 0; - background: #fafaff; - font-family: Arial, Veranda, Helvetica, sans-serif; - font-size: 14px; + margin: 10px; + padding: 0; + background: #fafaff; + font-family: Arial, Veranda, Helvetica, sans-serif; + font-size: 14px; } img { - border: 0; + border: 0; } a { - color: #00F; - background-color: transparent; + color: #00F; + background-color: transparent; } a:link, a:active, a:visited { - color: #00F; - background-color: transparent; + color: #00F; + background-color: transparent; } a.headermenu:link, a.headermenu:active, a.headermenu:visited { - text-decoration: underline; - color: #00F; - background-color: transparent; - padding-left: 8px; + text-decoration: underline; + color: #00F; + background-color: transparent; + padding-left: 8px; } form { - padding: 0; - margin: 0; + padding: 0; + margin: 0; } fieldset { - border: 2px solid black; - margin-left: 10px; - padding: 10px; - width: 700px; - font-size: 10px; + border: 2px solid black; + margin-left: 10px; + padding: 10px; + width: 700px; + font-size: 10px; } legend { - background-color: rgb(200, 220, 240); - border: 2px solid black; - padding: 0.25em; - padding-top: 0.1em; - font-size: 12px; + background-color: rgb(200, 220, 240); + border: 2px solid black; + padding: 0.25em; + padding-top: 0.1em; + font-size: 12px; } table { - font-size: 12px; - margin-right: .1in; + font-size: 12px; + margin-right: .1in; } th { - font-weight: bold; - background-color: #AFC3E4; - padding: 3px; - color: #323C4D; - text-align: center; - vertical-align: middle; - border: 1px solid #606060; - white-space: nowrap; + font-weight: bold; + background-color: #AFC3E4; + padding: 3px; + color: #323C4D; + text-align: center; + vertical-align: middle; + border: 1px solid #606060; + white-space: nowrap; } td { - background-color: #DEE3EC; - padding: 3px; - text-align: left; - vertical-align: middle; - border: 1px solid #a0a0a0; + background-color: #DEE3EC; + padding: 3px; + text-align: left; + vertical-align: middle; + border: 1px solid #a0a0a0; } .menu { - height: 22px; - font-size: 13px; - text-align: center; - vertical-align: bottom; - border: 1px solid #808080; - border-left: 2px solid #808080; - border-bottom: 2px solid #808080; - color: #000000; + height: 22px; + font-size: 13px; + text-align: center; + vertical-align: bottom; + border: 1px solid #808080; + border-left: 2px solid #808080; + border-bottom: 2px solid #808080; + color: #000000; } .menu-pad { - height: 22px; - font-size: 13px; - text-align: center; - padding-left: 1em; - padding-right: 1em; - vertical-align: bottom; - border: 1px solid #808080; - border-left: 2px solid #808080; - border-bottom: 2px solid #808080; - color: #000000; + height: 22px; + font-size: 13px; + text-align: center; + padding-left: 1em; + padding-right: 1em; + vertical-align: bottom; + border: 1px solid #808080; + border-left: 2px solid #808080; + border-bottom: 2px solid #808080; + color: #000000; } .menu a { - vertical-align: bottom; - text-decoration: none; - font-size: 13px; + vertical-align: bottom; + text-decoration: none; + font-size: 13px; } .headermenu-ie { - text-align: center; - margin-right: 0.1in; - margin-top: 0.20in; + text-align: center; + margin-right: 0.1in; + margin-top: 0.20in; } .headermenu-konq { - text-align: center; - margin-right: 0.1in; - margin-top: 0.25in; + text-align: center; + margin-right: 0.1in; + margin-top: 0.25in; } .logo-ie { - font-family: 'impact', sans-serif; - font-size: 60pt; - font-weight: bold; - color: #99caff; - margin-top: -0.20in; - margin-bottom: 0; - margin-right: 0.2in; - text-align: left; + font-family: 'impact', sans-serif; + font-size: 60pt; + font-weight: bold; + color: #99caff; + margin-top: -0.20in; + margin-bottom: 0; + margin-right: 0.2in; + text-align: left; } .title-ie { - font-family: 'impact', sans-serif; - font-size: 22pt; - font-weight: bold; - font-style: italic; - margin-right: 0.4in; - margin-top: -0.52in; - margin-bottom: 0; - text-align: left; + font-family: 'impact', sans-serif; + font-size: 22pt; + font-weight: bold; + font-style: italic; + margin-right: 0.4in; + margin-top: -0.52in; + margin-bottom: 0; + text-align: left; } .logo-konq { - font-family: 'impact', sans-serif; - font-size: 62pt; - font-weight: bold; - color: #99caff; - margin-top: -0.20in; - margin-bottom: 0; - margin-right: 0.2in; - text-align: left; + font-family: 'impact', sans-serif; + font-size: 62pt; + font-weight: bold; + color: #99caff; + margin-top: -0.20in; + margin-bottom: 0; + margin-right: 0.2in; + text-align: left; } .title-konq { - font-family: 'impact', 'sans-serif'; - font-size: 24pt; - font-weight: bold; - font-style: italic; - margin-right: 0.4in; - margin-top: -0.55in; - margin-bottom: 0; - text-align: left; + font-family: 'impact', 'sans-serif'; + font-size: 24pt; + font-weight: bold; + font-style: italic; + margin-right: 0.4in; + margin-top: -0.55in; + margin-bottom: 0; + text-align: left; } diff --git a/gen_crl.php b/gen_crl.php index e1cbf41..e590b5b 100644 --- a/gen_crl.php +++ b/gen_crl.php @@ -10,5 +10,3 @@ include('../html/include/openssl_functions.php') ; CA_generate_crl(); - -?> diff --git a/help.php b/help.php index c5615ed..8b9555b 100644 --- a/help.php +++ b/help.php @@ -5,11 +5,12 @@ printHeader(about); ?> -

PHPki HELP FILES

-help/PKI_basics.html>

PKI and E-mail Encryption - A Brief Explanation

-help/cacert_install_ie.html>

Installing Our Root Certificate For Use With Outlook and Outlook Express

-

help/usercert_install_ie.html>

Installing Your Personal E-mail Certificate For Use With Outlook and Outlook Express

-

help/glossary.html>

Glossary

+
+

PHPki HELP FILES

+

PKI and E-mail Encryption - A Brief Explanation

+

Installing Our Root Certificate For Use With Outlook and Outlook Express

+

Installing Your Personal E-mail Certificate For Use With Outlook and Outlook Express

+

Glossary

+ - -PKI and E-mail Encryption - A Brief Explanation + + + PKI and E-mail Encryption - A Brief Explanation - -

PKI and E-mail Encryption - A Brief Explanation

-PKI stands for Public Key Infrastructure. PKI is Information -Technology infrastructure that enables users of a basically unsecure public -network (such as the Internet) to securely and privately exchange data through -the use of a public and a private -cryptographic key pair that is obtained and shared through a -trusted Authority. + +
+

PKI and E-mail Encryption - A Brief Explanation

+
-

-Public and private keys are like two halves of a single key. PKI encryption -algorithms are designed such that a public key is used to encrypt or -"lock" a message, and only the complementary private key can "unlock" that -message. -Think of a bank vault or safe that can only be unlocked by two individuals -using two different but complementary keys. Neither of those keys can be used -by itself to unlock the vault. +

PKI stands for Public Key Infrastructure. PKI is Information Technology infrastructure that enables users of a basically unsecure public network (such as the Internet) to securely and privately exchange data through the use of a public and a private cryptographic key pair that is obtained and shared through a trusted Authority.

-

-In practice, individuals wishing to exchange encrypted e-mail -will agree to mutually trust one or more -Certificate Authorities(CA) by downloading and installing each trusted Authority's -root certificate on their computers. -They will each obtain their own personal -digital certificate -from a trusted Certificate Authority, and install them on their -respective computers. -Because they mutually trust the Certificate Authorities, they trust each other's -digital certificates. More specifically, they trust the -public keys contained within -their personal digital certificates which have been -digitally signed by a -trusted Certificate Authority. -They will then exchange their trusted public keys by sending each other -digitally signed e-mail messages. Once each party has the other's public key, -they may exchange trusted and encrypted messsages. +

Public and private keys are like two halves of a single key. PKI encryption algorithms are designed such that a public key is used to encrypt or "lock" a message, and only the complementary private key can "unlock" that message. Think of a bank vault or safe that can only be unlocked by two individuals using two different but complementary keys. Neither of those keys can be used by itself to unlock the vault.

-

-Public key exchange and encryption is like exchanging notarized documents. -One trusts a notarized document because a trusted third party, the Notary -Public, has signed it. The Certificate Authority is the Notary Public, and -the public keys are the documents. +

In practice, individuals wishing to exchange encrypted e-mail will agree to mutually trust one or more Certificate Authorities(CA) by downloading and installing each trusted Authority's root certificate on their computers. They will each obtain their own personal digital certificate from a trusted Certificate Authority, and install them on their respective computers. Because they mutually trust the Certificate Authorities, they trust each other's digital certificates. More specifically, they trust the public keys contained within their personal digital certificates which have been digitally signed by a trusted Certificate Authority. They will then exchange their trusted public keys by sending each other digitally + signed e-mail messages. Once each party has the other's public key, they may exchange trusted and encrypted messsages.

-

-Remember, having a personal digital certificate alone does not -give one the ability to send encrypted e-mail to others, but only allows the -receipt of encrypted e-mail. PKI is a cooperative encryption -standard. Both parties who are exchanging encrypted messages must have -personal digital certificates, they must trust the Certificate Authority -which issued the other persons certificate, and they must exchange -public keys with each other, as described above. +

Public key exchange and encryption is like exchanging notarized documents. One trusts a notarized document because a trusted third party, the Notary Public, has signed it. The Certificate Authority is the Notary Public, and the public keys are the documents.

-

-The process of installing certificates and exchanging public keys is dependent -upon the e-mail application one uses, and is beyond the scope of this document. +

Remember, having a personal digital certificate alone does not give one the ability to send encrypted e-mail to others, but only allows the receipt of encrypted e-mail. PKI is a cooperative encryption standard. Both parties who are exchanging encrypted messages must have personal digital certificates, they must trust the Certificate Authority which issued the other persons certificate, and they must exchange public keys with each other, as described above.

+

The process of installing certificates and exchanging public keys is dependent upon the e-mail application one uses, and is beyond the scope of this document.

diff --git a/help/cacert_install_ie.html b/help/cacert_install_ie.html index bf62331..6118a7d 100644 --- a/help/cacert_install_ie.html +++ b/help/cacert_install_ie.html @@ -1,29 +1,47 @@ + + -Root Certificate Installation for Outlook & Outlook Express - + Root Certificate Installation for Outlook & Outlook Express + + -

Root Certificate Installation for Outlook & Outlook Express

-

A Step-by-Step Guide


-

-

-

Open the folder which holds the certificates you have downloaded.
-Right-click on the certificate you wish to install, and select -Install Certificate from the context menu. -


-

Click the Next button in the Certificate Wizard -welcome window. -


-

Click the Next button in the Select a Certificate Store window. -


-

Click the Finish button in the Complete the Certificate.. window. -


-

You may be asked to confirm the root certificate installation. Click the Yes button if a window like this appears. -


-

Windows confirms the root certificate was successfully imported.
-You may now install your personal e-mail certificate. - -

+
+

Root Certificate Installation for Outlook & Outlook Express

+ +

A Step-by-Step Guide

+

+ +

+ +

Open the folder which holds the certificates you have downloaded.
+ Right-click on the certificate you wish to install, and select Install Certificate from the context menu.

+ +


+

+ +

Click the Next button in the Certificate Wizard welcome window.

+ +


+

+ +

Click the Next button in the Select a Certificate Store window.

+ +


+

+ +

Click the Finish button in the Complete the Certificate.. window.

+ +


+

+ +

You may be asked to confirm the root certificate installation. Click the Yes button if a window like this appears.

+ +


+

+ +

Windows confirms the root certificate was successfully imported.
+ You may now install your personal e-mail certificate.

diff --git a/help/glossary.html b/help/glossary.html index 28c2044..391ef2b 100644 --- a/help/glossary.html +++ b/help/glossary.html @@ -1,144 +1,169 @@ + + -PHPki Glossary - + PHPki Glossary + - - -

- - - -

PUBLIC KEY INFRASTRUCTURE

-PKI stands for Public Key Infrastructure. PKI is IT infrastructure that enables users of a basically unsecure public network (such as the Internet) to securely and privately exchange data through the use of a public and a private cryptographic key pair that is obtained and shared through a trusted authority. - -PKI is not only software or hardware. It is an infrastructure. So, PKI is a combination of products, services, facilities, policies, procedures, agreements, and people. All of these elements work together to provide for secure interactions on the Internet and other open networks. PKI is not a single monolithic entity, but a distributed system. The component elements may include multiple organization-specific public key infrastructures that are interoperable and interconnected. -
- -

- - - -

DIGITAL CERTIFICATE

-

-An attachment to an electronic message used for security purposes. The most common use of a digital certificate is to verify that a user sending a message is who he or she claims to be, and to provide the receiver with the means to encode a reply. - -

An individual wishing to send an encrypted message applies for a digital certificate from a Certificate Authority (CA). The CA issues an encrypted digital certificate containing the applicant's public key and a variety of other identification information. The CA makes its own public key readily available through print publicity or perhaps on the Internet. - -

The recipient of an encrypted message uses the CA's public key to decode the digital certificate attached to the message, verifies it as issued by the CA and then obtains the sender's public key and identification information held within the certificate. With this information, the recipient can send an encrypted reply. - -

The most widely used standard for digital certificates is X.509. -

- -

- - - -

CERTIFICATE AUTHORITY

-A trusted third-party organization or company that issues digital certificates used to create digital signatures and public-private key pairs. The role of the CA in this process is to guarantee that the individual granted the unique certificate is, in fact, who he or she claims to be. Usually, this means that the CA has an arrangement with a financial institution, such as a credit card company, which provides it with information to confirm an individual's claimed identity. CAs are a critical component in data security and electronic commerce because they guarantee that the two parties exchanging information are really who they claim to be. -
- -

- - - -

PUBLIC KEY ENCRYPTION

-A cryptographic system that uses two keys -- a public key known to everyone and a private or secret key known only to the recipient of the message. When John wants to send a secure message to Jane, he uses Jane's public key to encrypt the message. Jane then uses her private key to decrypt it. - -

An important element to the public key system is that the public and private keys are related in such a way that only the public key can be used to encrypt messages and only the corresponding private key can be used to decrypt them. Moreover, it is virtually impossible to deduce the private key if you know the public key. -

- -

- - - -

S/MIME

-S/MIME (Secure Multi-Purpose Internet Mail Extensions) is a secure method of sending e-mail that uses the RSA encryption system. S/MIME is included in the latest versions of the Web browsers from Microsoft and Netscape and has also been endorsed by other vendors that make messaging products. RSA has proposed S/MIME as a standard to the Internet Engineering Task Force (IETF). -
- -

- - - -

RSA

-RSA is an Internet encryption and authentication system that uses an algorithm developed in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman. The RSA algorithm is the most commonly used encryption and authentication algorithm and is included as part of the Web browsers from Microsoft and Netscape. It's also part of Lotus Notes, Intuit's Quicken, and many other products. The encryption system was owned by RSA Security, but a recent patent expiration placed it into the public domain. The technologies are part of existing or proposed Web, Internet, and computing standards. -
- -

- - - -

ROOT CERTIFICATE

-A root certificate is like a MASTER -digital certificate. -You must install a certificate authority's root certificate -before you can trust other certificates issued by that same certificate -authority. Root certificates are used to "sign" other certificates. -A signature by a root certificate is somewhat analogous to "notarizing" a -document in the physical world. When you install a root certificate on your -computer, you are saying you "trust" that certification authority and all -certificates it signs. -
- -

- - - -

DIGITAL SIGNATURE

-A digital code that can be attached to an electronically transmitted message -that uniquely identifies the sender. Like a written signature, the purpose of -a digital signature is to guarantee that the individual sending the message -really is who he or she claims to be. Digital certificates inherently provide -digital signature capability to most S/MIME enable e-mail clients. Digitally -signing an e-mail usually provides the recipient the with the sender's public -key, so the recipient may then send encrypted e-mail back to the sender. -
- -

- - - -

X.509

-The most widely used standard for defining digital certificates. X.509 is -actually an ITU Recommendation, which means that has not yet been officially -defined or approved. As a result, companies have implemented the standard in -different ways. For example, both Netscape and Microsoft use X.509 certificates -to implement SSL in their web servers and browsers. But an X.509 certificate -generated by Netscape may not be readable by Microsoft products, and vice -versa. -
- -

- - - -

PEM

-PEM is a widely used standard for storing digital certificates. -A PEM encoded file can contain all of private keys, public keys, and -(x.509) certificates. It is the default format for OpenSSL. -It stores data in Base64 encoded format, surrounded by ascii headers, so it is -suitable for text mode transfers between systems. PEM files usually end with -a .PEM extension. -
- -

- - - -

DER

-DER is a widely used standard for storing digital certificates. A DER encoded -file can contain all of private keys, public keys, and (x.509) -certificates. DER is a binary encoded headerless format. DER files usually -end with a .CRT or .CER extension. -
- -

- - - -

PKCS #12

-PKCS #12 (a.k.a. Personal Information Exchange Standard) is a standard for storing private keys and certificates securely (well sort of). It is used in (among other things) Netscape and Microsoft Internet Explorer with their import and export options. PKCS12 files usually end with a .PFX extension. -
- -

+ + + + + + + + + + + +
+

PUBLIC KEY INFRASTRUCTURE

+
PKI stands for Public Key Infrastructure. PKI is IT infrastructure that enables users of a basically unsecure public network (such as the Internet) to securely and privately exchange data through the use of a public and a private cryptographic key pair that is obtained and shared through a trusted authority. PKI is not only software or hardware. It is an infrastructure. So, PKI is a combination of products, services, facilities, policies, procedures, agreements, and people. All of these elements work together to provide for secure interactions on the Internet and other open networks. PKI is not a single monolithic entity, but a distributed system. The component elements may include multiple organization-specific public key infrastructures that are interoperable and interconnected.
+ + + + + + + + + +
+

DIGITAL CERTIFICATE

+
+

An attachment to an electronic message used for security purposes. The most common use of a digital certificate is to verify that a user sending a message is who he or she claims to be, and to provide the receiver with the means to encode a reply.

+ +

An individual wishing to send an encrypted message applies for a digital certificate from a Certificate Authority (CA). The CA issues an encrypted digital certificate containing the applicant's public key and a variety of other identification information. The CA makes its own public key readily available through print publicity or perhaps on the Internet.

+ +

The recipient of an encrypted message uses the CA's public key to decode the digital certificate attached to the message, verifies it as issued by the CA and then obtains the sender's public key and identification information held within the certificate. With this information, the recipient can send an encrypted reply.

+ +

The most widely used standard for digital certificates is X.509.

+
+ + + + + + + + + +
+

CERTIFICATE AUTHORITY

+
A trusted third-party organization or company that issues digital certificates used to create digital signatures and public-private key pairs. The role of the CA in this process is to guarantee that the individual granted the unique certificate is, in fact, who he or she claims to be. Usually, this means that the CA has an arrangement with a financial institution, such as a credit card company, which provides it with information to confirm an individual's claimed identity. CAs are a critical component in data security and electronic commerce because they guarantee that the two parties exchanging information are really who they claim to be.
+ + + + + + + + + +
+

PUBLIC KEY ENCRYPTION

+
+

A cryptographic system that uses two keys -- a public key known to everyone and a private or secret key known only to the recipient of the message. When John wants to send a secure message to Jane, he uses Jane's public key to encrypt the message. Jane then uses her private key to decrypt it.

+ +

An important element to the public key system is that the public and private keys are related in such a way that only the public key can be used to encrypt messages and only the corresponding private key can be used to decrypt them. Moreover, it is virtually impossible to deduce the private key if you know the public key.

+
+ + + + + + + + + +
+

S/MIME

+
S/MIME (Secure Multi-Purpose Internet Mail Extensions) is a secure method of sending e-mail that uses the RSA encryption system. S/MIME is included in the latest versions of the Web browsers from Microsoft and Netscape and has also been endorsed by other vendors that make messaging products. RSA has proposed S/MIME as a standard to the Internet Engineering Task Force (IETF).
+ + + + + + + + + +
+

RSA

+
RSA is an Internet encryption and authentication system that uses an algorithm developed in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman. The RSA algorithm is the most commonly used encryption and authentication algorithm and is included as part of the Web browsers from Microsoft and Netscape. It's also part of Lotus Notes, Intuit's Quicken, and many other products. The encryption system was owned by RSA Security, but a recent patent expiration placed it into the public domain. The technologies are part of existing or proposed Web, Internet, and computing standards.
+ + + + + + + + + +
+

ROOT CERTIFICATE

+
A root certificate is like a MASTER digital certificate. You must install a certificate authority's root certificate before you can trust other certificates issued by that same certificate authority. Root certificates are used to "sign" other certificates. A signature by a root certificate is somewhat analogous to "notarizing" a document in the physical world. When you install a root certificate on your computer, you are saying you "trust" that certification authority and all certificates it signs.
+ + + + + + + + + +
+

DIGITAL SIGNATURE

+
A digital code that can be attached to an electronically transmitted message that uniquely identifies the sender. Like a written signature, the purpose of a digital signature is to guarantee that the individual sending the message really is who he or she claims to be. Digital certificates inherently provide digital signature capability to most S/MIME enable e-mail clients. Digitally signing an e-mail usually provides the recipient the with the sender's public key, so the recipient may then send encrypted e-mail back to the sender.
+ + + + + + + + + +
+

X.509

+
The most widely used standard for defining digital certificates. X.509 is actually an ITU Recommendation, which means that has not yet been officially defined or approved. As a result, companies have implemented the standard in different ways. For example, both Netscape and Microsoft use X.509 certificates to implement SSL in their web servers and browsers. But an X.509 certificate generated by Netscape may not be readable by Microsoft products, and vice versa.
+ + + + + + + + + +
+

PEM

+
PEM is a widely used standard for storing digital certificates. A PEM encoded file can contain all of private keys, public keys, and (x.509) certificates. It is the default format for OpenSSL. It stores data in Base64 encoded format, surrounded by ascii headers, so it is suitable for text mode transfers between systems. PEM files usually end with a .PEM extension.
+ + + + + + + + + +
+

DER

+
DER is a widely used standard for storing digital certificates. A DER encoded file can contain all of private keys, public keys, and (x.509) certificates. DER is a binary encoded headerless format. DER files usually end with a .CRT or .CER extension.
+ + + + + + + + + +
+

PKCS #12

+
PKCS #12 (a.k.a. Personal Information Exchange Standard) is a standard for storing private keys and certificates securely (well sort of). It is used in (among other things) Netscape and Microsoft Internet Explorer with their import and export options. PKCS12 files usually end with a .PFX extension.

+
+ + diff --git a/help/usercert_install_ie.html b/help/usercert_install_ie.html index c223c34..62da42a 100644 --- a/help/usercert_install_ie.html +++ b/help/usercert_install_ie.html @@ -1,40 +1,51 @@ + + -Personal E-mail Certificate Installation for Outlook & Outlook Express - + Personal E-mail Certificate Installation for Outlook & Outlook Express + + -

Personal E-mail Certificate Installation for Outlook & Outlook Express

-

A Step-by-Step Guide


-

-

-

Open the folder which holds the certificates you have downloaded.
-Right-click on the certificate you wish to install, and select -Install PFX from the context menu. -


-

Click the Next button in the Certificate Wizard -welcome window. -


-

Click the Next button in the Select File to Import window. -


-

The personal e-mail certificate files created by PHPki contain an encrypted -copy of your private key. When your certficate was created, a password was -given to PHPki to encrypt the private key. The same password is used to -decrypt your private key and install the certificate. Do not forget or lose -this password as it cannot be recovered under any circumstance. -Select the Enable strong private key protection option if you -would like Windows to add an additional layer of password protection to use -your certificate. This is not necessary, and will not be covered further here. -There is no need to select the Mark the private key as exportable -option. Enter your certificate password and click the Next button -in the Password Protection for Private Keys window. -


-

Click the Next button in the Select a Certificate Store window. -


-

Click the Finish button in the Complete the Certificate.. window. -


-

Windows confirms the root certificate was successfully imported.
- -

+
+

Personal E-mail Certificate Installation for Outlook & Outlook Express

+ +

A Step-by-Step Guide

+

+ +

+ +

Open the folder which holds the certificates you have downloaded.
+ Right-click on the certificate you wish to install, and select Install PFX from the context menu.

+ +


+

+ +

Click the Next button in the Certificate Wizard welcome window.

+ +


+

+ +

Click the Next button in the Select File to Import window.

+ +


+

+ +

The personal e-mail certificate files created by PHPki contain an encrypted copy of your private key. When your certficate was created, a password was given to PHPki to encrypt the private key. The same password is used to decrypt your private key and install the certificate. Do not forget or lose this password as it cannot be recovered under any circumstance. Select the Enable strong private key protection option if you would like Windows to add an additional layer of password protection to use your certificate. This is not necessary, and will not be covered further here. There is no need to select the Mark the private key as exportable option. Enter your certificate password and click the Next button in the Password Protection for Private Keys window.

+ +


+

+ +

Click the Next button in the Select a Certificate Store window.

+ +


+

+ +

Click the Finish button in the Complete the Certificate.. window.

+ +


+

+ +

Windows confirms the root certificate was successfully imported.

diff --git a/include/common.php b/include/common.php index e349223..dcc155a 100644 --- a/include/common.php +++ b/include/common.php @@ -2,46 +2,48 @@ umask(0007); -if (isset($_SERVER['PHP_AUTH_USER'])) - $PHPki_user = md5($_SERVER['PHP_AUTH_USER']); -else - $PHPki_user = md5('default'); +if (isset($_SERVER['PHP_AUTH_USER'])) { + $PHPki_user = md5($_SERVER['PHP_AUTH_USER']); +} else { + $PHPki_user = md5('default'); +} $PHP_SELF = htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, "utf-8"); -function printHeader($withmenu="default") { - global $config; - $title = ($config['header_title']?$config['header_title']:'PHPki Certificate Authority'); - - switch ($withmenu) { - case 'public': - case 'about': - case 'setup': - $style_css = './css/style.css'; - break; - case 'ca': - case 'admin': - default: - $style_css = '../css/style.css'; - break; - } - - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Expires: -1"); +function printHeader($withmenu = "default") +{ + global $config; + $title = ($config['header_title']?$config['header_title']:'PHPki Certificate Authority'); + + switch ($withmenu) { + case 'public': + case 'about': + case 'setup': + $style_css = './css/style.css'; + break; + case 'ca': + case 'admin': + default: + $style_css = '../css/style.css'; + break; + } + + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header("Expires: -1"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); - ?> - - - - PHPki: <?php echo $title?> - - - - - -
PHPki
-
- -
- ReadMe - Setup - About -
- "; - - if (DEMO) { - print "Public"; - print "Manage"; - } - else { - print "Menu"; - } - - if (file_exists('policy.html')) { - print 'Policy'; - } - ?> - Help - About - - "; - - if (DEMO) { - print "Public"; - print "Manage"; - } - else { - print "Menu"; - } - - if (file_exists('../policy.html')) { - print 'Policy'; - } - ?> - Help - About - -
+ + + +
PHPki
+
+ +
+ ReadMe + Setup + About +
+ "; + + if (DEMO) { + print "Public"; + print "Manage"; + } else { + print "Menu"; + } + + if (file_exists('policy.html')) { + print 'Policy'; + } + ?> + Help + About + + "; + + if (DEMO) { + print "Public"; + print "Manage"; + } else { + print "Menu"; + } + + if (file_exists('../policy.html')) { + print 'Policy'; + } + ?> + Help + About + +
-
-
-

PHPki v - Copyright 2003 - William E. Roadcap

- - - +
+
+

PHPki v - Copyright 2003 - William E. Roadcap

+ + + diff --git a/include/my_functions.php b/include/my_functions.php index ca2e8e5..1a28470 100644 --- a/include/my_functions.php +++ b/include/my_functions.php @@ -5,49 +5,57 @@ # # Returns TRUE if browser is Internet Explorer. # -function isIE() { - global $_SERVER; - return strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'); +function isIE() +{ + global $_SERVER; + return strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'); } -function isKonq() { - global $_SERVER; - return strstr($_SERVER['HTTP_USER_AGENT'], 'Konqueror'); +function isKonq() +{ + global $_SERVER; + return strstr($_SERVER['HTTP_USER_AGENT'], 'Konqueror'); } -function isMoz() { - global $_SERVER; - return strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko'); +function isMoz() +{ + global $_SERVER; + return strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko'); } # # Force upload of specified file to browser. # -function upload($source, $destination, $content_type="application/octet-stream") { - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Expires: -1"); -# header("Cache-Control: no-store, no-cache, must-revalidate"); -# header("Cache-Control: post-check=0, pre-check=0", false); -# header("Pragma: no-cache"); +function upload($source, $destination, $content_type = "application/octet-stream") +{ + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header("Expires: -1"); +# header("Cache-Control: no-store, no-cache, must-revalidate"); +# header("Cache-Control: post-check=0, pre-check=0", false); +# header("Pragma: no-cache"); header("Content-Type: $content_type"); - if (is_array($source)) { - $fsize = 0; - foreach($source as $f) $fsize += filesize($f); - } - else { - $fsize = filesize($source); - } + if (is_array($source)) { + $fsize = 0; + foreach ($source as $f) { + $fsize += filesize($f); + } + } else { + $fsize = filesize($source); + } - header("Content-length: " . $fsize); + header("Content-length: " . $fsize); # header("Content-Disposition: attachment; filename=\"" . $destination ."\""); header("Content-Disposition: filename=\"" . $destination ."\""); - if (is_array($source)) - foreach($source as $f) $ret = readfile($f); - else - $ret=readfile($source); + if (is_array($source)) { + foreach ($source as $f) { + $ret = readfile($f); + } + } else { + $ret=readfile($source); + } # $fd=fopen($source,'r'); # fpassthru($fd); @@ -60,35 +68,51 @@ function upload($source, $destination, $content_type="application/octet-stream") # by field name. POST fields have precedence over GET fields. # Quoting/Slashes are stripped if magic quotes gpc is on. # -function gpvar($v) { - global $_GET, $_POST; +function gpvar($v) +{ + global $_GET, $_POST; $x = ""; - if (isset($_GET[$v])) $x = $_GET[$v]; - if (isset($_POST[$v])) $x = $_POST[$v]; - if (get_magic_quotes_gpc()) $x = stripslashes($x); - return $x; + if (isset($_GET[$v])) { + $x = $_GET[$v]; + } + if (isset($_POST[$v])) { + $x = $_POST[$v]; + } + if (get_magic_quotes_gpc()) { + $x = stripslashes($x); + } + return $x; } # # Sort a two multidimensional array by one of it's columns # -function csort($array, $column, $ascdec=SORT_ASC){ +function csort($array, $column, $ascdec = SORT_ASC) +{ - if (sizeof($array) == 0) return $array; + if (sizeof($array) == 0) { + return $array; + } // Sort by digital date rather than text date - if ($column == 'issued') $column = "issuedSort"; - if ($column == 'expires') $column = 'expiresSort'; + if ($column == 'issued') { + $column = "issuedSort"; + } + if ($column == 'expires') { + $column = 'expiresSort'; + } if ($column == 'status') { - foreach($array as $x) { - $sortarr[]=$x[$column]; - $sortdate[] = $x['expiresSort']; - } + foreach ($array as $x) { + $sortarr[]=$x[$column]; + $sortdate[] = $x['expiresSort']; + } array_multisort($sortarr, $ascdec, $sortdate, SORT_ASC, $array); } else { - foreach($array as $x) $sortarr[]=$x[$column]; + foreach ($array as $x) { + $sortarr[]=$x[$column]; + } array_multisort($sortarr, $ascdec, $array); } return $array; @@ -99,11 +123,13 @@ function csort($array, $column, $ascdec=SORT_ASC){ # Returns a value suitable for display in the browser. # Strips slashes if second argument is true. # -function htvar($v, $strip=false) { - if ($strip) - return htmlentities(stripslashes($v), 0, "UTF-8"); - else - return htmlentities($v, 0, "UTF-8"); +function htvar($v, $strip = false) +{ + if ($strip) { + return htmlentities(stripslashes($v), 0, "UTF-8"); + } else { + return htmlentities($v, 0, "UTF-8"); + } } @@ -113,11 +139,13 @@ function htvar($v, $strip=false) { # provided strings with single-quotes and quotes any # other dangerous characters. # -function escshellarg($v, $strip=false) { - if ($strip) - return escapeshellarg(stripslashes($v)); - else - return escapeshellarg($v); +function escshellarg($v, $strip = false) +{ + if ($strip) { + return escapeshellarg(stripslashes($v)); + } else { + return escapeshellarg($v); + } } @@ -125,93 +153,103 @@ function escshellarg($v, $strip=false) { # Similar to escshellarg(), but doesn't surround provided # string with single-quotes. # -function escshellcmd($v, $strip=false) { - if ($strip) - return escapeshellcmd(stripslashes($v)); - else - return escapeshellarg($v); +function escshellcmd($v, $strip = false) +{ + if ($strip) { + return escapeshellcmd(stripslashes($v)); + } else { + return escapeshellarg($v); + } } - + # # Recursively strips slashes from a string or array. # -function stripslashes_array(&$a) { - if (is_array($a)) { - foreach($a as $k => $v) { - my_stripslashes($a[$k]); - } - } - else { - $a = stripslashes($a); - } +function stripslashes_array(&$a) +{ + if (is_array($a)) { + foreach ($a as $k => $v) { + my_stripslashes($a[$k]); + } + } else { + $a = stripslashes($a); + } } # # Don't use this. # -function undo_magic_quotes(&$a) { - if(get_magic_quotes_gpc()) { - global $HTTP_POST_VARS, $HTTP_GET_VARS; - - foreach($HTTP_POST_VARS as $k => $v) { - stripslashes_array($HTTP_POST_VARS[$k]); - global $$k; - stripslashes_array($$k); - } - foreach($HTTP_GET_VARS as $k => $v) { - stripslashes_array($HTTP_GET_VARS[$k]); - global $$k; - stripslashes_array($$k); - } - } +function undo_magic_quotes(&$a) +{ + if (get_magic_quotes_gpc()) { + global $HTTP_POST_VARS, $HTTP_GET_VARS; + + foreach ($HTTP_POST_VARS as $k => $v) { + stripslashes_array($HTTP_POST_VARS[$k]); + global $$k; + stripslashes_array($$k); + } + foreach ($HTTP_GET_VARS as $k => $v) { + stripslashes_array($HTTP_GET_VARS[$k]); + global $$k; + stripslashes_array($$k); + } + } } # # Returns TRUE if argument contains only alphabetic characters. # -function is_alpha($v) { - #return (eregi('[^A-Z]',$v) ? false : true) ; - #return (preg_match('/[^A-Z]'.'/i',$v,PCRE_CASELESS) ? false : true) ; # Replaced eregi() with preg_match() - return (preg_match('/[^A-Z]/i',$v) ? false : true) ; +function is_alpha($v) +{ + #return (eregi('[^A-Z]',$v) ? false : true) ; + #return (preg_match('/[^A-Z]'.'/i',$v,PCRE_CASELESS) ? false : true) ; # Replaced eregi() with preg_match() + return (preg_match('/[^A-Z]/i', $v) ? false : true) ; } # # Returns TRUE if argument contains only numeric characters. # -function is_num($v) { - #return (eregi('[^0-9]',$v) ? false : true) ; - return (preg_match('/[^0-9]/',$v) ? false : true) ; # Replaced eregi() with preg_match() +function is_num($v) +{ + #return (eregi('[^0-9]',$v) ? false : true) ; + return (preg_match('/[^0-9]/', $v) ? false : true) ; # Replaced eregi() with preg_match() } # # Returns TRUE if argument contains only alphanumeric characters. # -function is_alnum($v) { - #return (eregi('[^A-Z0-9]',$v) ? false : true) ; - return (preg_match('/[^A-Z0-9]/i',$v) ? false : true) ; # Replaced eregi() with preg_match() +function is_alnum($v) +{ + #return (eregi('[^A-Z0-9]',$v) ? false : true) ; + return (preg_match('/[^A-Z0-9]/i', $v) ? false : true) ; # Replaced eregi() with preg_match() } # # Returns TRUE if argument is in proper e-mail address format. # -function is_email($v) { - #return (eregi('^[^@ ]+\@[^@ ]+\.[A-Z]{2,4}$',$v) ? true : false); - return (preg_match('/^[^@ ]+\@[^@ ]+\.[A-Z]{2,4}$'.'/i',$v) ? true : false); # Replaced eregi() with preg_match() +function is_email($v) +{ + #return (eregi('^[^@ ]+\@[^@ ]+\.[A-Z]{2,4}$',$v) ? true : false); + return (preg_match('/^[^@ ]+\@[^@ ]+\.[A-Z]{2,4}$'.'/i', $v) ? true : false); # Replaced eregi() with preg_match() } # # Returns True if the given string is a IP address # -function is_ip( $ip = null ) { - if( !$ip or strlen(trim($ip)) == 0){ +function is_ip($ip = null) +{ + if (!$ip or strlen(trim($ip)) == 0) { return false; } $ip=trim($ip); - if(preg_match("/^[0-9]{1,3}(.[0-9]{1,3}){3}$/",$ip)) { - foreach(explode(".", $ip) as $block) - if($block<0 || $block>255 ) + if (preg_match("/^[0-9]{1,3}(.[0-9]{1,3}){3}$/", $ip)) { + foreach (explode(".", $ip) as $block) { + if ($block<0 || $block>255) { return false; + } + } return true; } return false; @@ -220,9 +258,10 @@ function is_ip( $ip = null ) { # # Returns True if the given string is a valid FQDN # -function is_fqdn($FQDN) { +function is_fqdn($FQDN) +{ // remove leading wildcard characters if exist - $FQDN = preg_replace('/^\*\./','', $FQDN, 1); + $FQDN = preg_replace('/^\*\./', '', $FQDN, 1); return (!empty($FQDN) && preg_match('/^(?=.{1,254}$)((?=[a-z0-9-]{1,63}\.)(xn--+)?[a-z0-9]+(-[a-z0-9]+)*\.)+(xn--+)?[a-z0-9]{2,63}$/i', $FQDN) > 0); } @@ -231,26 +270,31 @@ function is_fqdn($FQDN) { # as a match is found. # -function eregi_array($regexp, $arr) { +function eregi_array($regexp, $arr) +{ - foreach ($arr as $elem) { - #if (eregi($regexp,$elem)) - if (! preg_match('/^\/.*\/$/', $regexp)) # if it doesn't begin and end with '/' - $regexp = '/'.$regexp.'/'; # pad the $regexp with '/' to prepare for preg_match() - if (preg_match($regexp.'i',$elem)) # Replaced eregi() with preg_match() - return true; - } - return false; + foreach ($arr as $elem) { + #if (eregi($regexp,$elem)) + if (! preg_match('/^\/.*\/$/', $regexp)) { # if it doesn't begin and end with '/' + $regexp = '/'.$regexp.'/'; # pad the $regexp with '/' to prepare for preg_match() + } + if (preg_match($regexp.'i', $elem)) { # Replaced eregi() with preg_match() + return true; + } + } + return false; } # # Reads entire file into a string # Same as file_get_contents in php >= 4.3.0 # -function my_file_get_contents($f) { - return implode('', file($f)); +function my_file_get_contents($f) +{ + return implode('', file($f)); } -function getOSInformation() { +function getOSInformation() +{ if (false == function_exists("shell_exec")) { return null; } @@ -261,4 +305,3 @@ function getOSInformation() { return null; } } -?> diff --git a/include/openssl_functions.php b/include/openssl_functions.php index c93ab69..901b7fb 100644 --- a/include/openssl_functions.php +++ b/include/openssl_functions.php @@ -5,71 +5,71 @@ // File name is placed in ./tmp with a random name. It lingers unless // removed manually. // -function CA_create_cnf($country='',$province='',$locality='',$organization='',$unit='',$common_name='',$email='',$keysize=2048,$dns_names='',$ip_addr='',$serial='') { - global $config, $PHPki_user; - - $issuer = $PHPki_user; - $count_dns = 0; - $count_ip = 0; - $alt_names = ""; - - if (! $dns_names == '') { - - $dns_n=explode("\n", $dns_names); - $count_dns = $count_dns + 1; - $alt_names .= "DNS.$count_dns = $common_name\n"; - foreach ($dns_n as $value) { - if (! $value == '') { - $count_dns = $count_dns + 1; - $alt_names .= "DNS.$count_dns = ".trim($value)."\n"; - } - } - } - - if (! $ip_addr == '') { - $ip_ar=explode("\n", $ip_addr); - foreach ($ip_ar as $value) { - if (! $value == '') { - $count_dns = $count_dns + 1; - $count_ip = $count_ip + 1; - # reetp IP should not be added to a DNS entry - #$alt_names .= "DNS.$count_dns = ".trim($value)."\n"; - $alt_names .= "IP.$count_ip = ".trim($value)."\n"; - } - } - } - - if (($count_dns > 0) || ($count_ip > 0)) { - $server_altnames = "@alt_names"; - } else { - $server_altnames = "DNS:$common_name,email:copy"; - } - -$configHOME = $config['home_dir']; -$configRANDFILE = $config['random']; -$configCa_dir = $config['ca_dir']; -$configCert_dir = $config['cert_dir']; -$configCrl_dir = $config['crl_dir']; -$configDatabase = $config['index']; -$configNew_certs_dir = $config['new_certs_dir']; -$configPrivate_dir = $config['private_dir']; -$configSerial = $config['serial']; -$configCacert_pem = $config['cacert_pem']; -$configCacrl_pem = $config['cacrl_pem']; -$configCakey = $config['cakey']; -$configDefault_md = $config['default_md']; -$configBase_url = $config['base_url']; -$configCrl_dist = $config['crl_distrib']; -$configComment_root = $config['comment_root']; -$configPolicy_url = $config['policy_url']; -$configRevoke_url = $config['revoke_url']; -$configComment_email = $config['comment_email']; -$configComment_sign = $config['comment_sign']; -$configComment_srv = $config['comment_srv']; - - - -$cnf_contents = " +function CA_create_cnf($country = '', $province = '', $locality = '', $organization = '', $unit = '', $common_name = '', $email = '', $keysize = 2048, $dns_names = '', $ip_addr = '', $serial = '') +{ + global $config, $PHPki_user; + + $issuer = $PHPki_user; + $count_dns = 0; + $count_ip = 0; + $alt_names = ""; + + if (! $dns_names == '') { + $dns_n=explode("\n", $dns_names); + $count_dns = $count_dns + 1; + $alt_names .= "DNS.$count_dns = $common_name\n"; + foreach ($dns_n as $value) { + if (! $value == '') { + $count_dns = $count_dns + 1; + $alt_names .= "DNS.$count_dns = ".trim($value)."\n"; + } + } + } + + if (! $ip_addr == '') { + $ip_ar=explode("\n", $ip_addr); + foreach ($ip_ar as $value) { + if (! $value == '') { + $count_dns = $count_dns + 1; + $count_ip = $count_ip + 1; + # reetp IP should not be added to a DNS entry + #$alt_names .= "DNS.$count_dns = ".trim($value)."\n"; + $alt_names .= "IP.$count_ip = ".trim($value)."\n"; + } + } + } + + if (($count_dns > 0) || ($count_ip > 0)) { + $server_altnames = "@alt_names"; + } else { + $server_altnames = "DNS:$common_name,email:copy"; + } + + $configHOME = $config['home_dir']; + $configRANDFILE = $config['random']; + $configCa_dir = $config['ca_dir']; + $configCert_dir = $config['cert_dir']; + $configCrl_dir = $config['crl_dir']; + $configDatabase = $config['index']; + $configNew_certs_dir = $config['new_certs_dir']; + $configPrivate_dir = $config['private_dir']; + $configSerial = $config['serial']; + $configCacert_pem = $config['cacert_pem']; + $configCacrl_pem = $config['cacrl_pem']; + $configCakey = $config['cakey']; + $configDefault_md = $config['default_md']; + $configBase_url = $config['base_url']; + $configCrl_dist = $config['crl_distrib']; + $configComment_root = $config['comment_root']; + $configPolicy_url = $config['policy_url']; + $configRevoke_url = $config['revoke_url']; + $configComment_email = $config['comment_email']; + $configComment_sign = $config['comment_sign']; + $configComment_srv = $config['comment_srv']; + + + + $cnf_contents = " HOME = $configHOME RANDFILE = $configRANDFILE dir = $configCa_dir @@ -256,13 +256,13 @@ function CA_create_cnf($country='',$province='',$locality='',$organization='',$u "; - # Write out the config file. - $cnf_file = tempnam('../../tmp','cnf-'); // Why is this not in the phpki dir ? why ../../ ? - $handle = fopen($cnf_file,"w"); - fwrite($handle, $cnf_contents); - fclose($handle); - - return($cnf_file); + # Write out the config file. + $cnf_file = tempnam('../../tmp', 'cnf-'); // Why is this not in the phpki dir ? why ../../ ? + $handle = fopen($cnf_file, "w"); + fwrite($handle, $cnf_contents); + fclose($handle); + + return($cnf_file); } // @@ -271,137 +271,153 @@ function CA_create_cnf($country='',$province='',$locality='',$organization='',$u // Fields: serial, country, province, locality, organization, // issuer, unit, common_name, email // -function CAdb_to_array($search = '.*') { - global $config; - - # Prepend a default status to search string if missing. - #if (! ereg('^\^\[.*\]', $search)) $search = '^[VRE].*'.$search; - if (! preg_match("/^\^\[.*\]/", $search)) $search = '^[VRE].*'.$search; - # Include valid certs? - #if (ereg('^\^\[.*V.*\]',$search)) $inclval = true; - if (preg_match('/^\^\[.*V.*\]/',$search)) $inclval = true; - # Include revoked certs? - #if (ereg('^\^\[.*R.*\]',$search)) $inclrev = true; - if (preg_match('/^\^\[.*R.*\]/',$search)) $inclrev = true; - # Include expired certs? - #if (ereg('^\^\[.*E.*\]',$search)) $inclexp = true; - if (preg_match('/^\^\[.*E.*\]/',$search)) $inclexp = true; - - # There isn't really a status of 'E' in the openssl index. - # Change (E)xpired to (V)alid within the search string. - #$search = ereg_replace('^(\^\[.*)E(.*\])','\\1V\\2',$search); - $search = preg_replace('/^(\^\[.*)E(.*\])/','${1}V${2}',$search); - - $db = array(); - exec('egrep -i '.escshellarg($search).' '.$config['index'], $x); - foreach($x as $y) { - $i = CAdb_explode_entry($y); - if (($i['status'] == "Valid" && $inclval) || ($i['status'] == "Revoked" && $inclrev) || ($i['status'] == "Expired" && $inclexp)) - $db[$i['serial']] = $i; - } - - return($db); +function CAdb_to_array($search = '.*') +{ + global $config; + + # Prepend a default status to search string if missing. + #if (! ereg('^\^\[.*\]', $search)) $search = '^[VRE].*'.$search; + if (! preg_match("/^\^\[.*\]/", $search)) { + $search = '^[VRE].*'.$search; + } + # Include valid certs? + #if (ereg('^\^\[.*V.*\]',$search)) $inclval = true; + if (preg_match('/^\^\[.*V.*\]/', $search)) { + $inclval = true; + } + # Include revoked certs? + #if (ereg('^\^\[.*R.*\]',$search)) $inclrev = true; + if (preg_match('/^\^\[.*R.*\]/', $search)) { + $inclrev = true; + } + # Include expired certs? + #if (ereg('^\^\[.*E.*\]',$search)) $inclexp = true; + if (preg_match('/^\^\[.*E.*\]/', $search)) { + $inclexp = true; + } + + # There isn't really a status of 'E' in the openssl index. + # Change (E)xpired to (V)alid within the search string. + #$search = ereg_replace('^(\^\[.*)E(.*\])','\\1V\\2',$search); + $search = preg_replace('/^(\^\[.*)E(.*\])/', '${1}V${2}', $search); + + $db = array(); + exec('egrep -i '.escshellarg($search).' '.$config['index'], $x); + foreach ($x as $y) { + $i = CAdb_explode_entry($y); + if (($i['status'] == "Valid" && $inclval) || ($i['status'] == "Revoked" && $inclrev) || ($i['status'] == "Expired" && $inclexp)) { + $db[$i['serial']] = $i; + } + } + + return($db); } // // Returns an array containing the index record for // certificate $serial. -// -function CAdb_get_entry($serial) { - global $config; - $regexp = "^[VR]\t.*\t.*\t$serial\t.*\t.*$"; +// +function CAdb_get_entry($serial) +{ + global $config; + $regexp = "^[VR]\t.*\t.*\t$serial\t.*\t.*$"; $x = exec('egrep '.escshellarg($regexp).' '.$config['index']); - if ($x) - return CAdb_explode_entry($x); - else { - return false; - } + if ($x) { + return CAdb_explode_entry($x); + } else { + return false; + } } // -// Returns the serial number of a VALID certificate matching +// Returns the serial number of a VALID certificate matching // $email and/or $name. Returns FALSE if no match is found. // -function CAdb_in($email="", $name="") { - global $config; - $email = escshellcmd($email); - $name = escshellcmd($name); - $regexp = "^[V].*CN=$name/(Email|emailAddress)=$email"; +function CAdb_in($email = "", $name = "") +{ + global $config; + $email = escshellcmd($email); + $name = escshellcmd($name); + $regexp = "^[V].*CN=$name/(Email|emailAddress)=$email"; $x =exec('egrep '.escshellarg($regexp).' '.$config['index']); if ($x) { - list($j,$j,$j,$serial,$j,$j) = explode("\t", $x); - return "$serial"; - } - else - return false; + list($j,$j,$j,$serial,$j,$j) = explode("\t", $x); + return "$serial"; + } else { + return false; + } } // // Alias for CAdb_in() // -function CAdb_serial($email, $name='') { - return CAdb_in($email, $name=''); +function CAdb_serial($email, $name = '') +{ + return CAdb_in($email, $name = ''); } // // Alias for CAdb_in() // -function CAdb_exists($email, $name='') { - return CAdb_in($email, $name=''); +function CAdb_exists($email, $name = '') +{ + return CAdb_in($email, $name = ''); } // // Returns the certificate 'issuer' // -function CAdb_issuer($serial) { - global $config; - $rec = CAdb_get_entry($serial); - return $rec['issuer']; +function CAdb_issuer($serial) +{ + global $config; + $rec = CAdb_get_entry($serial); + return $rec['issuer']; } // // Returns an array containing the respective fields given a // a raw line ($dbentry) from the certificate index. -// Fields: serial, country, province locality, organization, +// Fields: serial, country, province locality, organization, // issuer, unit, common_name, email // -function CAdb_explode_entry($dbentry) { - $a = explode("\t", $dbentry); - $b = preg_split('/\/([A-Z]|[a-z])+=/', $a[5]); - - switch ($a[0]) { - case "V": - $db['status'] = "Valid"; - break; - case "R": - $db['status'] = "Revoked"; - break; - } - - // CA_cert_start/enddate - // A date will be returned in this format - // Feb 27 16:00:09 2020 GMT - // Add a 'digital' sort key for digital date sorting later - sscanf(CA_cert_startdate($a[3]),"%s%s%s%s", $mm,$dd,$tt,$yy); - $db['issued'] = strftime("%Y-%b-%d", strtotime("$yy-$mm-$dd")); - $db['issuedSort'] = strftime("%Y-%m-%d", strtotime("$yy-$mm-$dd")); - - sscanf(CA_cert_enddate($a[3]), "%s%s%s%s",$mm,$dd,$tt,$yy); - $db['expires'] = strftime("%Y-%b-%d", strtotime("$yy-$mm-$dd")); - $db['expiresSort'] = strftime("%Y-%m-%d", strtotime("$yy-$mm-$dd")); - - if (time() > strtotime("$yy-$mm-$dd")) { - $db['status'] = "Expired"; - } - - - // Compatibility with migrated certs from openvpn-bridge - if(count($b) == 7){ +function CAdb_explode_entry($dbentry) +{ + $a = explode("\t", $dbentry); + $b = preg_split('/\/([A-Z]|[a-z])+=/', $a[5]); + + switch ($a[0]) { + case "V": + $db['status'] = "Valid"; + break; + case "R": + $db['status'] = "Revoked"; + break; + } + + // CA_cert_start/enddate + // A date will be returned in this format + // Feb 27 16:00:09 2020 GMT + // Add a 'digital' sort key for digital date sorting later + sscanf(CA_cert_startdate($a[3]), "%s%s%s%s", $mm, $dd, $tt, $yy); + $db['issued'] = strftime("%Y-%b-%d", strtotime("$yy-$mm-$dd")); + $db['issuedSort'] = strftime("%Y-%m-%d", strtotime("$yy-$mm-$dd")); + + sscanf(CA_cert_enddate($a[3]), "%s%s%s%s", $mm, $dd, $tt, $yy); + $db['expires'] = strftime("%Y-%b-%d", strtotime("$yy-$mm-$dd")); + $db['expiresSort'] = strftime("%Y-%m-%d", strtotime("$yy-$mm-$dd")); + + if (time() > strtotime("$yy-$mm-$dd")) { + $db['status'] = "Expired"; + } + + + // Compatibility with migrated certs from openvpn-bridge + if (count($b) == 7) { $db['serial'] = $a[3]; $db['country'] = $b[1]; $db['province'] = $b[2]; @@ -411,102 +427,108 @@ function CAdb_explode_entry($dbentry) { $db['unit'] = $b[4]; $db['common_name'] = $b[5]; $db['email'] = $b[6]; - } - // Compatibility with renewed certs from openvpn-bridge - elseif(count($b) == 8){ - $db['serial'] = $a[3]; - $db['country'] = $b[1]; - $db['province'] = $b[2]; - $db['locality'] = $b[3]; - $db['organization'] = $b[4]; - $db['issuer'] = ''; - $db['unit'] = $b[5]; - $db['common_name'] = $b[6]; - $db['email'] = $b[7]; - } - // Else, it's a certificate created with phpki - else{ - $db['serial'] = $a[3]; - $db['country'] = $b[1]; - $db['province'] = $b[2]; - $db['locality'] = $b[3]; - $db['organization'] = $b[4]; - $db['issuer'] = $b[5]; - $db['unit'] = $b[6]; - $db['common_name'] = $b[7]; - $db['email'] = $b[8]; - } - - return $db; + } // Compatibility with renewed certs from openvpn-bridge + elseif (count($b) == 8) { + $db['serial'] = $a[3]; + $db['country'] = $b[1]; + $db['province'] = $b[2]; + $db['locality'] = $b[3]; + $db['organization'] = $b[4]; + $db['issuer'] = ''; + $db['unit'] = $b[5]; + $db['common_name'] = $b[6]; + $db['email'] = $b[7]; + } // Else, it's a certificate created with phpki + else { + $db['serial'] = $a[3]; + $db['country'] = $b[1]; + $db['province'] = $b[2]; + $db['locality'] = $b[3]; + $db['organization'] = $b[4]; + $db['issuer'] = $b[5]; + $db['unit'] = $b[6]; + $db['common_name'] = $b[7]; + $db['email'] = $b[8]; + } + + return $db; } // // Returns the date & time a specified certificate is revoked, // Returns FALSE if the certificate is not revoked. // -function CAdb_is_revoked($serial) { - global $config; - $regexp = "^R\t.*\t.*\t$serial\t.*\t.*$"; +function CAdb_is_revoked($serial) +{ + global $config; + $regexp = "^R\t.*\t.*\t$serial\t.*\t.*$"; $x = exec('egrep '.escshellarg($regexp).' '.$config['index']); - if ($x) { - list($j,$j,$revoke_date,$j,$j,$j) = explode("\t", $x); - // Revoke date = 'R' + start date and is in this format - // 200227162209Z - sscanf($revoke_date, "%2s%2s%2s",$yy,$mm,$dd); - return strftime("%b %d, %Y", strtotime("$yy-$mm-$dd")); - } - else - return false; + if ($x) { + list($j,$j,$revoke_date,$j,$j,$j) = explode("\t", $x); + // Revoke date = 'R' + start date and is in this format + // 200227162209Z + sscanf($revoke_date, "%2s%2s%2s", $yy, $mm, $dd); + return strftime("%b %d, %Y", strtotime("$yy-$mm-$dd")); + } else { + return false; + } } // // Returns TRUE if a certificate is valid, otherwise FALSE. // -function CAdb_is_valid($serial) { - global $config; - $regexp = "^V\t.*\t.*\t$serial\t.*\t.*$"; +function CAdb_is_valid($serial) +{ + global $config; + $regexp = "^V\t.*\t.*\t$serial\t.*\t.*$"; - if (exec('egrep '.escshellarg($regexp).' '.$config['index'])) - return true; - else - return false; + if (exec('egrep '.escshellarg($regexp).' '.$config['index'])) { + return true; + } else { + return false; + } } // // Returns the long-form certificate description as output by // openssl x509 -in certificatefile -text -purpose // -function CA_cert_text($serial) { - global $config; - $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; - return(shell_exec(X509.' -in '.escshellarg($certfile).' -text -purpose 2>&1')); +function CA_cert_text($serial) +{ + global $config; + $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; + return(shell_exec(X509.' -in '.escshellarg($certfile).' -text -purpose 2>&1')); } // // Returns the long-form text of the Certificate Revocation List -// openssl crl -in crlfile -text +// openssl crl -in crlfile -text // -function CA_crl_text() { - global $config; - $crlfile = $config['cacrl_pem']; - return(shell_exec(CRL.' -in '.escshellarg($crlfile).' -text 2>&1')); +function CA_crl_text() +{ + global $config; + $crlfile = $config['cacrl_pem']; + return(shell_exec(CRL.' -in '.escshellarg($crlfile).' -text 2>&1')); } // Returns the static takey.pem file -function ta_key_text() { +function ta_key_text() +{ global $config; return(shell_exec('cat '.escshellarg($config['private_dir']).'/takey.pem 2>&1')); } // Returns the dhparam file -function dhparam_text() { +function dhparam_text() +{ global $config; return(shell_exec('cat '.escshellarg($config['private_dir']).'/dhparam2048.pem 2>&1')); } // Returns the root CA certificate file (PEM Encoded) -function root_pem_text() { +function root_pem_text() +{ global $config; return(shell_exec('cat '.escshellarg($config['cacert_pem']).' 2>&1')); } @@ -514,432 +536,446 @@ function root_pem_text() { // // Returns the subject of a certificate. // -function CA_cert_subject($serial) { - global $config; - $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; - $x = exec(X509.' -in '.escshellarg($certfile).' -noout -subject 2>&1'); - return(str_replace('subject=', '', $x)); +function CA_cert_subject($serial) +{ + global $config; + $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; + $x = exec(X509.' -in '.escshellarg($certfile).' -noout -subject 2>&1'); + return(str_replace('subject=', '', $x)); } // // Returns the common name of a certificate. // -function CA_cert_cname($serial) { - global $config; - #return(ereg_replace('^.*/CN=(.*)/.*','\\1',CA_cert_subject($serial))); - return(preg_replace('/^.*\/CN=(.*)\/.*/','${1}',CA_cert_subject($serial))); - +function CA_cert_cname($serial) +{ + global $config; + #return(ereg_replace('^.*/CN=(.*)/.*','\\1',CA_cert_subject($serial))); + return(preg_replace('/^.*\/CN=(.*)\/.*/', '${1}', CA_cert_subject($serial))); } // // Returns the email address of a certificate. // -function CA_cert_email($serial) { - global $config; - $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; - $x = exec(X509.' -in '.escshellarg($certfile).' -noout -email 2>&1'); - return($x); +function CA_cert_email($serial) +{ + global $config; + $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; + $x = exec(X509.' -in '.escshellarg($certfile).' -noout -email 2>&1'); + return($x); } // // Returns the effective date of a certificate. // -function CA_cert_startdate($serial) { - global $config; - $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; - $x = exec(X509.' -in '.escshellarg($certfile).' -noout -startdate 2>&1'); - return(str_replace('notBefore=','',$x)); +function CA_cert_startdate($serial) +{ + global $config; + $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; + $x = exec(X509.' -in '.escshellarg($certfile).' -noout -startdate 2>&1'); + return(str_replace('notBefore=', '', $x)); } // // Returns the expiration date of a certificate. // -function CA_cert_enddate($serial) { - global $config; - $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; - $x = exec(X509.' -in '.escshellarg($certfile).' -noout -enddate 2>&1'); - return(str_replace('notAfter=','',$x)); +function CA_cert_enddate($serial) +{ + global $config; + $certfile = $config['new_certs_dir'] . '/' . $serial . '.pem'; + $x = exec(X509.' -in '.escshellarg($certfile).' -noout -enddate 2>&1'); + return(str_replace('notAfter=', '', $x)); } // // Revokes a specified certificate. // -function CA_revoke_cert($serial) { - global $config; +function CA_revoke_cert($serial) +{ + global $config; - $fd = fopen($config['index'],'a'); - flock($fd, LOCK_EX); + $fd = fopen($config['index'], 'a'); + flock($fd, LOCK_EX); - $certfile = $config['new_certs_dir'] . "/$serial.pem"; - $cmd_output[] = 'Revoking the certificate.'; - $configCa_pwd = $config['ca_pwd']; - $configOpenssl_cnf = $config['openssl_cnf']; - exec(CA." -config $configOpenssl_cnf -revoke ".escshellarg($certfile)." -passin pass:$ConfigCa_pwd 2>&1", $cmd_output, $ret); + $certfile = $config['new_certs_dir'] . "/$serial.pem"; + $cmd_output[] = 'Revoking the certificate.'; + $configCa_pwd = $config['ca_pwd']; + $configOpenssl_cnf = $config['openssl_cnf']; + exec(CA." -config $configOpenssl_cnf -revoke ".escshellarg($certfile)." -passin pass:$ConfigCa_pwd 2>&1", $cmd_output, $ret); - if ($ret == 0) { - unset($cmd_output); - list($ret, $cmd_output[]) = CA_generate_crl(); - } - - fclose($fd); + if ($ret == 0) { + unset($cmd_output); + list($ret, $cmd_output[]) = CA_generate_crl(); + } + + fclose($fd); - return array(($ret == true || $ret == 0 ? true : false), implode('
',$cmd_output)); + return array(($ret == true || $ret == 0 ? true : false), implode('
', $cmd_output)); } // // Creates a new certificate request, and certificate in various formats -// according to specified parameters. PKCS12 bundle files contain the +// according to specified parameters. PKCS12 bundle files contain the // private key, certificate, and CA certificate. // // Returns an array containing the output of failed openssl commands. // -function CA_create_cert($cert_type='email',$country,$province,$locality,$organization,$unit,$common_name,$email,$expiry,$passwd,$keysize=2048,$dns_names,$ip_addr) { - global $config; - - # Wait here if another user has the database locked. - $fd = fopen($config['index'],"a"); - flock($fd, LOCK_EX); - - # Get the next available serial number - $serial = trim(implode('',file($config['serial']))); - - $userkey = $config['private_dir'] . "/$serial-key.pem"; - $userreq = $config['req_dir'] ."/$serial-req.pem"; - $userder = $config['cert_dir'] . "/$serial.der"; - $userpfx = $config['pfx_dir'] . "/$serial.pfx"; - - $expiry_days = round($expiry * 365.25, 0); - - $cnf_file = CA_create_cnf($country,$province,$locality,$organization,$unit,$common_name,$email,$keysize,$dns_names,$ip_addr,$serial); - - # Escape certain dangerous characters in user input - $email = escshellcmd($email); - $_passwd = escshellarg($passwd); - $friendly_name = escshellarg($common_name); - $extensions = escshellarg($cert_type.'_ext'); - - # Create the certificate request - unset($cmd_output); - $cmd_output[] = 'Creating certificate request.'; - - if (($_passwd) && ($_passwd != "''")) { - exec(REQ." -new -newkey rsa:$keysize -keyout '$userkey' -out '$userreq' -config '$cnf_file' -days '$expiry_days' -passout pass:$_passwd 2>&1", $cmd_output, $ret); - } - else { - exec(REQ." -new -newkey rsa:$keysize -keyout '$userkey' -out '$userreq' -config '$cnf_file' -days '$expiry_days' -nodes 2>&1", $cmd_output, $ret); - } - - # Sign the certificate request and create the certificate - if ($ret == 0) { - unset($cmd_output); - $cmd_output[] = "Signing $cert_type certificate request."; - $configCa_pwd = $config['ca_pwd']; - exec(CA." -config '$cnf_file' -in '$userreq' -out /dev/null -notext -days '$expiry_days' -passin pass:'$configCa_pwd' -batch -extensions $extensions 2>&1", $cmd_output, $ret); - }; - - # Create DER format certificate - if ($ret == 0) { - unset($cmd_output); - $cmd_output[] = "Creating DER format certificate."; - exec(X509." -in '$usercert' -out '$userder' -inform PEM -outform DER 2>&1", $cmd_output, $ret); - }; - - # Create a PKCS12 certificate file for download to Windows - if ($ret == 0) { - unset($cmd_output); - $cmd_output[] = "Creating PKCS12 format certificate."; - $configCacert_pem = $config['cacert_pem']; - $configOrganization = $config['organization']; - $configRandom = $config['random']; - - if (($_passwd) && ($_passwd != "''")) { - $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx pass: $_passwd"; - exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -rand '$configRandom' -passin pass:$_passwd -passout pass:$_passwd 2>&1", $cmd_output, $ret); - } - else { - $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx"; - // reetp - this needs looking at - exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -nodes -passout pass: 2>&1", $cmd_output, $ret); - //exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$config[cacert_pem]' -caname '$config[organization]' -out '$userpfx' -name $friendly_name -nodes 2>&1", $cmd_output, $ret); - } - }; - - #Unlock the CA database - fclose($fd); - - #Remove temporary openssl config file. - if (file_exists($cnf_file)) unlink($cnf_file); - - if ($ret == 0) { - # Successful! - # Return status=true and serial number of issued certificate. - return array(true, $serial); - - } - else { - # Not successful. :-( - # Clean up our loose ends. - # Return status=false and openssl output/errors for debug. - CA_remove_cert($serial); - $cmd_output[] = 'Click on the "Help" link above for information on how to report this problem.'; - return array(false, implode("
",$cmd_output)); - } +function CA_create_cert($cert_type = 'email', $country, $province, $locality, $organization, $unit, $common_name, $email, $expiry, $passwd, $keysize = 2048, $dns_names, $ip_addr) +{ + global $config; + + # Wait here if another user has the database locked. + $fd = fopen($config['index'], "a"); + flock($fd, LOCK_EX); + + # Get the next available serial number + $serial = trim(implode('', file($config['serial']))); + + $userkey = $config['private_dir'] . "/$serial-key.pem"; + $userreq = $config['req_dir'] ."/$serial-req.pem"; + $userder = $config['cert_dir'] . "/$serial.der"; + $userpfx = $config['pfx_dir'] . "/$serial.pfx"; + + $expiry_days = round($expiry * 365.25, 0); + + $cnf_file = CA_create_cnf($country, $province, $locality, $organization, $unit, $common_name, $email, $keysize, $dns_names, $ip_addr, $serial); + + # Escape certain dangerous characters in user input + $email = escshellcmd($email); + $_passwd = escshellarg($passwd); + $friendly_name = escshellarg($common_name); + $extensions = escshellarg($cert_type.'_ext'); + + # Create the certificate request + unset($cmd_output); + $cmd_output[] = 'Creating certificate request.'; + + if (($_passwd) && ($_passwd != "''")) { + exec(REQ." -new -newkey rsa:$keysize -keyout '$userkey' -out '$userreq' -config '$cnf_file' -days '$expiry_days' -passout pass:$_passwd 2>&1", $cmd_output, $ret); + } else { + exec(REQ." -new -newkey rsa:$keysize -keyout '$userkey' -out '$userreq' -config '$cnf_file' -days '$expiry_days' -nodes 2>&1", $cmd_output, $ret); + } + + # Sign the certificate request and create the certificate + if ($ret == 0) { + unset($cmd_output); + $cmd_output[] = "Signing $cert_type certificate request."; + $configCa_pwd = $config['ca_pwd']; + exec(CA." -config '$cnf_file' -in '$userreq' -out /dev/null -notext -days '$expiry_days' -passin pass:'$configCa_pwd' -batch -extensions $extensions 2>&1", $cmd_output, $ret); + }; + + # Create DER format certificate + if ($ret == 0) { + unset($cmd_output); + $cmd_output[] = "Creating DER format certificate."; + exec(X509." -in '$usercert' -out '$userder' -inform PEM -outform DER 2>&1", $cmd_output, $ret); + }; + + # Create a PKCS12 certificate file for download to Windows + if ($ret == 0) { + unset($cmd_output); + $cmd_output[] = "Creating PKCS12 format certificate."; + $configCacert_pem = $config['cacert_pem']; + $configOrganization = $config['organization']; + $configRandom = $config['random']; + + if (($_passwd) && ($_passwd != "''")) { + $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx pass: $_passwd"; + exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -rand '$configRandom' -passin pass:$_passwd -passout pass:$_passwd 2>&1", $cmd_output, $ret); + } else { + $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx"; + // reetp - this needs looking at + exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -nodes -passout pass: 2>&1", $cmd_output, $ret); + //exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$config[cacert_pem]' -caname '$config[organization]' -out '$userpfx' -name $friendly_name -nodes 2>&1", $cmd_output, $ret); + } + }; + + #Unlock the CA database + fclose($fd); + + #Remove temporary openssl config file. + if (file_exists($cnf_file)) { + unlink($cnf_file); + } + + if ($ret == 0) { + # Successful! + # Return status=true and serial number of issued certificate. + return array(true, $serial); + } else { + # Not successful. :-( + # Clean up our loose ends. + # Return status=false and openssl output/errors for debug. + CA_remove_cert($serial); + $cmd_output[] = 'Click on the "Help" link above for information on how to report this problem.'; + return array(false, implode("
", $cmd_output)); + } } // // Renews a specified certificate, revoking any existing valid versions. -// Uses old certificate request to Creates a new request, and certificate +// Uses old certificate request to Creates a new request, and certificate // in various formats. // // Returns an array containing the output of failed openssl commands. // -// FIXME: Yes, I know... This functions contains much duplicative code +// FIXME: Yes, I know... This functions contains much duplicative code // from CA_create_cert(). Bleh! -// -function CA_renew_cert($old_serial,$expiry,$passwd) { - global $config; - - # Do not renew a revoked certificate if a valid one exists for this - # URL. Find and renew the valid certificate instead. - if (CAdb_is_revoked($old_serial)) { - $ret = CAdb_in(CA_cert_email($old_serial),CA_cert_cname($old_serial)); - if ($ret && $old_serial != $ret) $old_serial = $ret; - } - - # Valid certificates must be revoked prior to renewal. - if (CAdb_is_valid($old_serial)) { - $ret = CA_revoke_cert($old_serial); - if (! $ret[0]) return $ret; - } - - $cert_type = CA_cert_type($old_serial); - $extensions = $cert_type.'_ext'; - - # Get common_name from old certificate for use as the - # "friendly name" of PKCS12 certificate. - $rec = CAdb_get_entry($old_serial); - $country = $rec['country']; - $province = $rec['province']; - $locality = $rec['locality']; - $organization = $rec['organization']; - $unit = $rec['unit']; - $common_name = $rec['common_name']; - $email = $rec['email']; - - # Wait here if another user has the database locked. - $fd = fopen($config['index'],"a"); - flock($fd, LOCK_EX); - - # Get the next available serial number - $serial = trim(implode('',file($config['serial']))); - - $old_userkey = $config['private_dir'] . "$old_serial-key.pem"; - $old_userreq = $config['req_dir'] . "/$old_serial-req.pem"; - $userkey = $config['private_dir'] . "/$serial-key.pem"; - $userreq = $config['req_dir'] . "/$serial-req.pem"; - $usercert = $config['new_certs_dir'] . "/$serial.pem"; - $userder = $config['cert_dir'] . "/$serial.der"; - $userpfx = $config['pfx_dir'] . "/$serial.pfx"; - - - $expiry_days = round($expiry * 365.25, 0); - - $cmd_output = array(); - $ret = 0; - - # Create a new certificate request by copying the old request. - if (! file_exists($old_userreq) || ! copy($old_userreq,$userreq)) { - $cmd_output[] = 'Could not create new certificate request file.'; - $ret = 1; - } - - # Copy private key to new file. - if ($ret == 0 && (! file_exists($old_userkey) || ! copy($old_userkey,$userkey))) { - $cmd_output[] = "Could not update private key file."; - $ret = 1; - } - - $cnf_file = CA_create_cnf($country,$province,$locality,$organization,$unit,$common_name,$email); - - # "friendly name" of PKCS12 certificate. - $friendly_name = escshellarg($rec['common_name']); - - # Escape dangerous characters in user input. - $_passwd = escshellarg($passwd); - - $configCa_pwd = $config['ca_pwd']; - $configCacert_pem = $config['cacert_pem']; - $configOrganization = $config['organization']; - $configRandom = $config['random']; - - # Sign the certificate request and create the certificate. - if ($ret == 0) { - unset($cmd_output); - $cmd_output[] = "Signing the $cert_type certificate request."; - exec(CA." -config '$cnf_file' -in '$userreq' -out /dev/null -notext -days '$expiry_days' -passin pass:'$configCa_pwd' -batch -extensions $extensions 2>&1", $cmd_output, $ret); - }; - - # Create DER format certificate - if ($ret == 0) { - unset($cmd_output); - $cmd_output[] = "Creating DER format certificate."; - exec(X509." -in '$usercert' -out '$userder' -inform PEM -outform DER 2>&1", $cmd_output, $ret); - }; - - # Create a PKCS12 certificate file for download to Windows - if ($ret == 0) { - unset($cmd_output); - $cmd_output[] = "Creating PKCS12 format certificate."; - if (($_passwd) && ($_passwd != "''")) { - $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx pass: $_passwd"; - exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -rand '$configRandom' -passin pass:$_passwd -passout pass:$_passwd 2>&1", $cmd_output, $ret); - } - else { - $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx"; +// +function CA_renew_cert($old_serial, $expiry, $passwd) +{ + global $config; + + # Do not renew a revoked certificate if a valid one exists for this + # URL. Find and renew the valid certificate instead. + if (CAdb_is_revoked($old_serial)) { + $ret = CAdb_in(CA_cert_email($old_serial), CA_cert_cname($old_serial)); + if ($ret && $old_serial != $ret) { + $old_serial = $ret; + } + } + + # Valid certificates must be revoked prior to renewal. + if (CAdb_is_valid($old_serial)) { + $ret = CA_revoke_cert($old_serial); + if (! $ret[0]) { + return $ret; + } + } + + $cert_type = CA_cert_type($old_serial); + $extensions = $cert_type.'_ext'; + + # Get common_name from old certificate for use as the + # "friendly name" of PKCS12 certificate. + $rec = CAdb_get_entry($old_serial); + $country = $rec['country']; + $province = $rec['province']; + $locality = $rec['locality']; + $organization = $rec['organization']; + $unit = $rec['unit']; + $common_name = $rec['common_name']; + $email = $rec['email']; + + # Wait here if another user has the database locked. + $fd = fopen($config['index'], "a"); + flock($fd, LOCK_EX); + + # Get the next available serial number + $serial = trim(implode('', file($config['serial']))); + + $old_userkey = $config['private_dir'] . "$old_serial-key.pem"; + $old_userreq = $config['req_dir'] . "/$old_serial-req.pem"; + $userkey = $config['private_dir'] . "/$serial-key.pem"; + $userreq = $config['req_dir'] . "/$serial-req.pem"; + $usercert = $config['new_certs_dir'] . "/$serial.pem"; + $userder = $config['cert_dir'] . "/$serial.der"; + $userpfx = $config['pfx_dir'] . "/$serial.pfx"; + + + $expiry_days = round($expiry * 365.25, 0); + + $cmd_output = array(); + $ret = 0; + + # Create a new certificate request by copying the old request. + if (! file_exists($old_userreq) || ! copy($old_userreq, $userreq)) { + $cmd_output[] = 'Could not create new certificate request file.'; + $ret = 1; + } + + # Copy private key to new file. + if ($ret == 0 && (! file_exists($old_userkey) || ! copy($old_userkey, $userkey))) { + $cmd_output[] = "Could not update private key file."; + $ret = 1; + } + + $cnf_file = CA_create_cnf($country, $province, $locality, $organization, $unit, $common_name, $email); + + # "friendly name" of PKCS12 certificate. + $friendly_name = escshellarg($rec['common_name']); + + # Escape dangerous characters in user input. + $_passwd = escshellarg($passwd); + + $configCa_pwd = $config['ca_pwd']; + $configCacert_pem = $config['cacert_pem']; + $configOrganization = $config['organization']; + $configRandom = $config['random']; + + # Sign the certificate request and create the certificate. + if ($ret == 0) { + unset($cmd_output); + $cmd_output[] = "Signing the $cert_type certificate request."; + exec(CA." -config '$cnf_file' -in '$userreq' -out /dev/null -notext -days '$expiry_days' -passin pass:'$configCa_pwd' -batch -extensions $extensions 2>&1", $cmd_output, $ret); + }; + + # Create DER format certificate + if ($ret == 0) { + unset($cmd_output); + $cmd_output[] = "Creating DER format certificate."; + exec(X509." -in '$usercert' -out '$userder' -inform PEM -outform DER 2>&1", $cmd_output, $ret); + }; + + # Create a PKCS12 certificate file for download to Windows + if ($ret == 0) { + unset($cmd_output); + $cmd_output[] = "Creating PKCS12 format certificate."; + if (($_passwd) && ($_passwd != "''")) { + $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx pass: $_passwd"; + exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -rand '$configRandom' -passin pass:$_passwd -passout pass:$_passwd 2>&1", $cmd_output, $ret); + } else { + $cmd_output[] = "infile: $usercert keyfile: $userkey outfile: $userpfx"; // reetp - this needs looking at - exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -nodes -passout pass: 2>&1", $cmd_output, $ret); - //exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$config[cacert_pem]' -caname '$config[organization]' -out '$userpfx' -name $friendly_name -nodes 2>&1", $cmd_output, $ret); - - } - }; - - #Unlock the CA database - fclose($fd); - - # https://github.com/radicand/phpki/issues/14 - if (preg_match('E-mail Protection', $certtext) && preg_match('Code Signing', $certtest)) { - $cert_type = 'email_signing'; - } - if (preg_match('E-mail Protection', $certtext)) { - $cert_type = 'email'; - } - - #Remove temporary openssl config file. - if (file_exists($cnf_file)) unlink($cnf_file); - - if ($ret == 0) { - return array(true, $serial); - } - else { - # Not successful, so clean up before exiting. - CA_remove_cert($serial); - - if (eregi_array('.*private key.*',$cmd_output)) - $cmd_output[] = 'This was likely caused by entering the wrong certificate password.'; - else - $cmd_output[] = 'Click on the "Help" link above for information on how to report this problem.'; - - return array(false, implode('
',$cmd_output)); - } + exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$configCacert_pem' -caname '$configOrganization' -out '$userpfx' -name $friendly_name -nodes -passout pass: 2>&1", $cmd_output, $ret); + //exec(PKCS12." -export -in '$usercert' -inkey '$userkey' -certfile '$config[cacert_pem]' -caname '$config[organization]' -out '$userpfx' -name $friendly_name -nodes 2>&1", $cmd_output, $ret); + } + }; + + #Unlock the CA database + fclose($fd); + + # https://github.com/radicand/phpki/issues/14 + if (preg_match('E-mail Protection', $certtext) && preg_match('Code Signing', $certtest)) { + $cert_type = 'email_signing'; + } + if (preg_match('E-mail Protection', $certtext)) { + $cert_type = 'email'; + } + + #Remove temporary openssl config file. + if (file_exists($cnf_file)) { + unlink($cnf_file); + } + + if ($ret == 0) { + return array(true, $serial); + } else { + # Not successful, so clean up before exiting. + CA_remove_cert($serial); + + if (eregi_array('.*private key.*', $cmd_output)) { + $cmd_output[] = 'This was likely caused by entering the wrong certificate password.'; + } else { + $cmd_output[] = 'Click on the "Help" link above for information on how to report this problem.'; + } + + return array(false, implode('
', $cmd_output)); + } } // -// Creates a new Certificate Revocation List and copies it the the approriate +// Creates a new Certificate Revocation List and copies it the the approriate // locations. Returns error messages from failed commands. // -function CA_generate_crl() { - global $config; +function CA_generate_crl() +{ + global $config; - $configOpenssl_cnf = $config['openssl_cnf']; - $configCacrl_pem = $config['cacrl_pem']; - $configCa_pwd = $config['ca_pwd']; - $configCacrl_der = $config['cacrl_der']; - $ret = 0; + $configOpenssl_cnf = $config['openssl_cnf']; + $configCacrl_pem = $config['cacrl_pem']; + $configCa_pwd = $config['ca_pwd']; + $configCacrl_der = $config['cacrl_der']; + $ret = 0; - $cmd_output[] = "Generating Certificate Revocation List."; - exec(CA. " -gencrl -config '$configOpenssl_cnf' -out '$configCacrl_pem' -passin pass:'$configCa_pwd' 2>&1", $cmd_output, $ret); + $cmd_output[] = "Generating Certificate Revocation List."; + exec(CA. " -gencrl -config '$configOpenssl_cnf' -out '$configCacrl_pem' -passin pass:'$configCa_pwd' 2>&1", $cmd_output, $ret); - if ($ret == 0) { - unset($cmd_output); - $cmd_output[] = "Creating DER format Certificate Revocation List."; - exec(CRL." -in '$configCacrl_der' -out '$configCacrl_der' -inform PEM -outform DER 2>&1", $cmd_output, $ret); - } + if ($ret == 0) { + unset($cmd_output); + $cmd_output[] = "Creating DER format Certificate Revocation List."; + exec(CRL." -in '$configCacrl_der' -out '$configCacrl_der' -inform PEM -outform DER 2>&1", $cmd_output, $ret); + } - return array(($ret == 0 ? true : false), implode('
',$cmd_output)); + return array(($ret == 0 ? true : false), implode('
', $cmd_output)); } // // Removes a specified certificate from the certificate index, // and all traces of it from the file system. // -function CA_remove_cert($serial) { - global $config; - - $userreq = $config['req_dir'] . "/$serial-req.pem"; - $userkey = $config['private_dir'] . "/$serial-key.pem"; - $usercert = $config['new_certs_dir'] . "/$serial.pem"; - $userder = $config['cert_dir'] . "/$serial.der"; - $userpfx = $config['pfx_dir'] ."/$serial.pfx"; - - $configIndex = $config['index']; - - # Wait here if another user has the database locked. - $fd = fopen($configIndex,'a'); - flock($fd, LOCK_EX); - - if( file_exists($userreq)) unlink($userreq); - if( file_exists($userkey)) unlink($userkey); - if( file_exists($usercert)) unlink($usercert); - if( file_exists($userder)) unlink($userder); - if( file_exists($userpfx)) unlink($userpfx); - - $tmpfile = $configIndex .'.tmp'; - copy($configIndex , $tmpfile); - - $regexp = "^[VR]\t.*\t.*\t".$serial."\t.*\t.*$"; - exec('egrep -v '.escshellarg($regexp)." $tmpfile > $configIndex 2>/dev/null"); - - unlink($tmpfile); - fclose($fd); - +function CA_remove_cert($serial) +{ + global $config; + + $userreq = $config['req_dir'] . "/$serial-req.pem"; + $userkey = $config['private_dir'] . "/$serial-key.pem"; + $usercert = $config['new_certs_dir'] . "/$serial.pem"; + $userder = $config['cert_dir'] . "/$serial.der"; + $userpfx = $config['pfx_dir'] ."/$serial.pfx"; + + $configIndex = $config['index']; + + # Wait here if another user has the database locked. + $fd = fopen($configIndex, 'a'); + flock($fd, LOCK_EX); + + if (file_exists($userreq)) { + unlink($userreq); + } + if (file_exists($userkey)) { + unlink($userkey); + } + if (file_exists($usercert)) { + unlink($usercert); + } + if (file_exists($userder)) { + unlink($userder); + } + if (file_exists($userpfx)) { + unlink($userpfx); + } + + $tmpfile = $configIndex .'.tmp'; + copy($configIndex, $tmpfile); + + $regexp = "^[VR]\t.*\t.*\t".$serial."\t.*\t.*$"; + exec('egrep -v '.escshellarg($regexp)." $tmpfile > $configIndex 2>/dev/null"); + + unlink($tmpfile); + fclose($fd); } // -// Returns the likely intended use for a specified certificate +// Returns the likely intended use for a specified certificate // (email, server, vpn). // -function CA_cert_type($serial) { - - $certtext = CA_cert_text($serial); - - #if (ereg('OpenSSL.* (E.?mail|Personal) .*Certificate', $certtext) && ereg('Code Signing', $certtest)) { - if (preg_match('~OpenSSL.* (E.?mail|Personal) .*Certificate~', $certtext) && preg_match('~Code Signing~', $certtest)) { - $cert_type = 'email_codesigning'; - } - #if (ereg('OpenSSL.* (E.?mail|Personal) .*Certificate', $certtext)) { - if (preg_match('~OpenSSL.* (E.?mail|Personal) .*Certificate~', $certtext)) { - $cert_type = 'email'; - } - #elseif (ereg('OpenSSL.* Server .*Certificate', $certtext)) { - elseif (preg_match('~OpenSSL.* Server .*Certificate~', $certtext)) { - $cert_type = 'server'; - } - #elseif (ereg('timeStamping|Time Stamping', $certtext)) { - elseif (preg_match('~timeStamping|Time Stamping~', $certtext)) { - $cert_type = 'time_stamping'; - } - #elseif (ereg('TLS Web Client Authentication', $certtext) && ereg('TLS Web Server Authentication', $certtext)) { - elseif (preg_match('~TLS Web Client Authentication~', $certtext) && preg_match('~TLS Web Server Authentication~', $certtext)) { - $cert_type = 'vpn_client_server'; - } - #elseif (ereg('TLS Web Client Authentication', $certtext)) { - elseif (preg_match('~TLS Web Client Authentication~', $certtext)) { - $cert_type = 'vpn_client'; - } - #elseif (ereg('TLS Web Server Authentication', $certtext)) { - elseif (preg_match('~TLS Web Server Authentication~', $certtext)) { - $cert_type = 'vpn_server'; - } - else { - $cert_type = 'vpn_client_server'; - } - - return $cert_type; +function CA_cert_type($serial) +{ + + $certtext = CA_cert_text($serial); + + #if (ereg('OpenSSL.* (E.?mail|Personal) .*Certificate', $certtext) && ereg('Code Signing', $certtest)) { + if (preg_match('~OpenSSL.* (E.?mail|Personal) .*Certificate~', $certtext) && preg_match('~Code Signing~', $certtest)) { + $cert_type = 'email_codesigning'; + } + #if (ereg('OpenSSL.* (E.?mail|Personal) .*Certificate', $certtext)) { + if (preg_match('~OpenSSL.* (E.?mail|Personal) .*Certificate~', $certtext)) { + $cert_type = 'email'; + } #elseif (ereg('OpenSSL.* Server .*Certificate', $certtext)) { + elseif (preg_match('~OpenSSL.* Server .*Certificate~', $certtext)) { + $cert_type = 'server'; + } #elseif (ereg('timeStamping|Time Stamping', $certtext)) { + elseif (preg_match('~timeStamping|Time Stamping~', $certtext)) { + $cert_type = 'time_stamping'; + } #elseif (ereg('TLS Web Client Authentication', $certtext) && ereg('TLS Web Server Authentication', $certtext)) { + elseif (preg_match('~TLS Web Client Authentication~', $certtext) && preg_match('~TLS Web Server Authentication~', $certtext)) { + $cert_type = 'vpn_client_server'; + } #elseif (ereg('TLS Web Client Authentication', $certtext)) { + elseif (preg_match('~TLS Web Client Authentication~', $certtext)) { + $cert_type = 'vpn_client'; + } #elseif (ereg('TLS Web Server Authentication', $certtext)) { + elseif (preg_match('~TLS Web Server Authentication~', $certtext)) { + $cert_type = 'vpn_server'; + } else { + $cert_type = 'vpn_client_server'; + } + + return $cert_type; } -function CA_get_root_pem() { - global $config; - return(file_get_contents($config['cacert_pem'])); +function CA_get_root_pem() +{ + global $config; + return(file_get_contents($config['cacert_pem'])); } - -?> diff --git a/main.php b/main.php index e99ed5d..5d5eb65 100644 --- a/main.php +++ b/main.php @@ -8,72 +8,66 @@ $stage = gpvar('stage'); -switch($stage) { +switch ($stage) { + case 'dl_root': + upload($config['cacert_pem'], $config['ca_prefix'] . "cacert.crt", 'application/x-x509-ca-cert'); + break; -case 'dl_root': - upload($config['cacert_pem'], $config['ca_prefix'] . "cacert.crt", 'application/x-x509-ca-cert'); - break; + case 'display_root': + printHeader('public'); -case 'display_root': - printHeader('public'); + ?> +

Root Certificate (PEM Encoded)

+

+

+

+ +
+ -

Root Certificate (PEM Encoded)

-

-

-

-

- -
- +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+
+
- ?> -
-
-
- - - - - - - - - - + - - - -
-

- diff --git a/ns_revoke_query.php b/ns_revoke_query.php index d5da539..bd1e2a1 100644 --- a/ns_revoke_query.php +++ b/ns_revoke_query.php @@ -7,10 +7,10 @@ # # PROTOCOL: # The client should issue an HTTP GET request using a URL that is -# the concatenation of the revocation url and certificate serial +# the concatenation of the revocation url and certificate serial # number. (i.e. http://www.host.dom/phpki/ns_revoke_query.php?10A5F2) # -# The server should return a document of type +# The server should return a document of type # application/x-netscape-revocation containing a single character # '1' if the certificate is revoked, '0' if it is valid. # @@ -25,8 +25,8 @@ $regexp = "^R.*$serial.*$"; $configIndex = $config['index']; -if (exec("egrep '$regexp' '$configIndex'")) - print '1'; -else - print '0'; -?> +if (exec("egrep '$regexp' '$configIndex'")) { + print '1'; +} else { + print '0'; +} diff --git a/policy.html b/policy.html index 47bd506..cf564ff 100644 --- a/policy.html +++ b/policy.html @@ -1,14 +1,15 @@ + + -Certificate Authority Issuer's Statement + Certificate Authority Issuer's Statement + -

Certificate Authority Issuer's Statement

-

-This is a private Limited Liability certificate authority for use by member -non-profit agencies. -

-Certificate non-repudiation is achieved via identity verification by password -authorized certificate managers from each member agency. +

Certificate Authority Issuer's Statement

+ +

This is a private Limited Liability certificate authority for use by member non-profit agencies.

+ +

Certificate non-repudiation is achieved via identity verification by password authorized certificate managers from each member agency.

diff --git a/readme.php b/readme.php index c247a34..9cc1bcf 100644 --- a/readme.php +++ b/readme.php @@ -10,4 +10,3 @@ readfile('./README.md'); print ''; printFooter(); -?> diff --git a/search.php b/search.php index 1e65875..45b0b87 100644 --- a/search.php +++ b/search.php @@ -15,132 +15,137 @@ $show_expired = gpvar('show_expired'); # Force stage back to search form if search string is empty. -if ($stage == "search" && ! $search) $stage = ""; +if ($stage == "search" && ! $search) { + $stage = ""; +} # Force filter to (V)alid certs if no search status is selected. -if ( !($show_valid.$show_revoked.$show_expired) ) $show_valid = 'V'; +if (!($show_valid.$show_revoked.$show_expired)) { + $show_valid = 'V'; +} switch ($stage) { -case 'display': - printHeader('about'); + case 'display': + printHeader('about'); + + print ' +

Certificate Details

+

(#'.htvar($serial).')
'.htvar(CA_cert_cname($serial).' <'.CA_cert_email($serial).'>').'

'; + + if ($revoke_date = CAdb_is_revoked($serial)) { + print '

REVOKED '.htvar($revoke_date).'

'; + } - print ' -

Certificate Details

-

(#'.htvar($serial).')
'.htvar(CA_cert_cname($serial).' <'.CA_cert_email($serial).'>').'

'; + print '
'.htvar(CA_cert_text($serial)).'
'; + break; - if ($revoke_date = CAdb_is_revoked($serial)) - print '

REVOKED '.htvar($revoke_date).'

'; + case 'download': + $rec = CAdb_get_entry($serial); + upload($config['cert_dir'] . "/$serial.der", $rec['common_name'] . ".cer", 'application/pkix-cert'); + break; - print '
'.htvar(CA_cert_text($serial)).'
'; - break; + case 'download_pem': + $rec = CAdb_get_entry($serial); + upload($config['new_certs_dir'] . "/$serial.pem", $rec['common_name'] . ".pem", 'application/pkix-cert'); + break; -case 'download': - $rec = CAdb_get_entry($serial); - upload($config['cert_dir'] . "/$serial.der", $rec['common_name'] . ".cer", 'application/pkix-cert'); + case 'search': + printHeader('public'); + + $db = CAdb_to_array("^[${show_valid}${show_revoked}${show_expired}].*$search"); + + print ''; + if (sizeof($db) == 0) { + ?> +
+

Nothing Found

+
+ + + + + +
+
+ '; - if (sizeof($db) == 0) { - ?> -
-

Nothing Found

-
- - - - - -
-
- '; - print 'CERTIFICATE SEARCH RESULTS'; + print ''; + print ''; $headings = array( status=>"Status", issued=>"Issued", expires=>"Expires", common_name=>"User's Name", email=>"E-mail", organization=>"Organization", unit=>"Department", locality=>"Locality", province=>"State" - ); + ); - print ''; - foreach($headings as $field=>$head) { - print ''; + print ''; + foreach ($headings as $field => $head) { + print ''; + } + print ''; + + foreach ($db as $rec) { + $stcolor = array(Valid=>'green',Revoked=>'red',Expired=>'orange'); + + ?> + + + + + + + + + + + - - - - - - - - - - '; - } - - ?> -
CERTIFICATE SEARCH RESULTS
'.htvar($head). '
'.htvar($head). '
Display + + Download + Download (in PEM format) + '; - - foreach($db as $rec) { - $stcolor = array(Valid=>'green',Revoked=>'red',Expired=>'orange'); - - ?> -
Display - - Download - Download (in PEM format) -
- -
- - - - - -
- - -

Certificate Search

-
- -
- >Valid -      >Revoked -     >Expired - -
- -

- '; + } + + ?> + + +
+ + + + + +
+ + +

Certificate Search

+
+ +
+ >Valid +      >Revoked +     >Expired + +
+ +

+