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
This software may be freely redistributed under the terms of the GNU Public License provided this page and all copyright notices remain completely intact. +
+
+
'; readfile($config['passwd_file']) - ?> -- - + + + - - - + + +
-
- '; + system("htpasswd -bm $pwdfile $login $passwd 2>&1") + ?> ++
+ - - - + + + '; - system("htpasswd -D $pwdfile $login 2>&1") - ?> --
- '; + system("htpasswd -D $pwdfile $login 2>&1") + ?> ++
+ -SYSADMIN MENU | -|||
---|---|---|---|
|
SYSADMIN MENU | +|||
---|---|---|---|
|
-- - -Debug Info:
- -
CERTIFICATE MANAGEMENT MENU | -|
---|---|
- Create a New Certificate | -Use the Certificate Request Form to create and download new digital certificates. - You may create certificates in succession without re-entering the entire form - by clicking the "Go Back" button after each certificate is created. |
- Manage Certificates | -Conveniently view, download, revoke, and renew your existing certificates using the - Certificate Management Control Panel. |
- Update & View the Certificate Revocation List | -Some applications automagically reference the Certificate Revocation List to determine - certificate validity. It is not necessary to perform this update function, as the CRL is - updated when certificates are revoked. However, doing so is harmless. - Read the online help to learn more about this. |
- Download the Root Certificate - Display the Root Certificate (PEM Encoded) |
- The "Root" certificate must be installed before using any of the - certificates issued here. Read the online help - to learn more about this. |
- Download the Certificate Revocation List - Download in PEM format. |
- This is the official list of revoked certificates. Using this list with your e-mail or - browser application is optional. Some applications will automagically reference this list. |
- Download the static pre-shared key - Display the static pre-shared key |
- This key can be used with OpenVPN as a standalone auth mechanism, or as an additional TLS authentication. |
- Download the Diffie-Hellman parameters - Display the Diffie-Hellman parameters |
- This file is used by OpenVPN for the hand-shake. The Diffie-Hellman key agreement - protocol enables two communication partners to exchange a secret key safely. |
++ + +Debug Info:
+ +
CERTIFICATE MANAGEMENT MENU | +|
---|---|
+ Create a New Certificate | +Use the Certificate Request Form to create and download new digital certificates. + You may create certificates in succession without re-entering the entire form + by clicking the "Go Back" button after each certificate is created. |
+ Manage Certificates | +Conveniently view, download, revoke, and renew your existing certificates using the + Certificate Management Control Panel. |
+ Update & View the Certificate Revocation List | +Some applications automagically reference the Certificate Revocation List to determine + certificate validity. It is not necessary to perform this update function, as the CRL is + updated when certificates are revoked. However, doing so is harmless. + Read the online help to learn more about this. |
+ Download the Root Certificate + Display the Root Certificate (PEM Encoded) |
+ The "Root" certificate must be installed before using any of the + certificates issued here. Read the online help + to learn more about this. |
+ Download the Certificate Revocation List + Download in PEM format. |
+ This is the official list of revoked certificates. Using this list with your e-mail or + browser application is optional. Some applications will automagically reference this list. |
+ Download the static pre-shared key + Display the static pre-shared key |
+ This key can be used with OpenVPN as a standalone auth mechanism, or as an additional TLS authentication. |
+ Download the Diffie-Hellman parameters + Display the Diffie-Hellman parameters |
+ This file is used by OpenVPN for the hand-shake. The Diffie-Hellman key agreement + protocol enables two communication partners to exchange a secret key safely. |
'.CA_cert_text($serial).''; - break; - -case 'dl-confirm': - printHeader('ca'); - - $rec = CAdb_get_entry($serial); - - ?> -
'.CA_cert_text($serial).''; + break; + + case 'dl-confirm': + printHeader('ca'); + + $rec = CAdb_get_entry($serial); + + ?> +
- + 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']).'
+
Serial Number |
-
- '.htvar($rec['serial']).'
--Debug Info:
- -
- -
- - -
-CERTIFICATE MANAGEMENT CONTROL PANEL | |||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
+ '.$head.''; + + if ($sortfield == $field) { + print ' '. + ''; + } + + print ' | '; + } + print 'Actions | '; + 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 '|||||||||||||||||||||||||||||||||||
' .$rec[status].' | +'.$rec['issued'].' | +'.$rec['expires'].' | +'.$rec['common_name'].' | +' . htvar($rec['email']) . ' | +'.htvar($rec['organization']).' | +'.htvar($rec['unit']).' | +'.htvar($rec['locality']).' | +'. + ''; + + if ($rec['status'] == 'Valid') { + print ' + '. + ' + '. + ''; + } + print ' + '. + ' + |
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.
-' . $er . '
'; + } + + if ($er) { + printHeader(); + ?> + + + + '; + 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(); + ?> + + + + + + 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); ?> -' . htvar($certtext) . '
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
-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 @@ + + --
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.
-
-
+
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.
-
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. | +
-
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.
-
-
+
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.
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('+
-
--
PUBLIC CONTENT MENU | +|
---|---|
Search for a Certificate | +Find a digital certificate to download and install in your e-mail or browser application. | +
?stage=dl_root>Download Our Root Certificate | +You must install our "Root" certificate before you can use any of the certificates issued here. Read the online help to learn more about this. | +
?stage=display_root>Display Our Root Certificate (PEM Encoded) | +This option provides the "Root" certificate PEM encoded text for advanced users to manually install via copy and paste. Read the online help to learn more about this. | + +
?stage=dl_crl>Download Our Certificate Revocation List | +The official list of certificates revoked by this site. Installation and use of this list is optional. Some e-mail programs will reference this list automagically. (Some will need it in PEM format.) | +
PUBLIC CONTENT MENU | - -|||
---|---|---|---|
- Search for a Certificate | -Find a digital certificate to download and install in your e-mail or browser application. | ||
- ?stage=dl_root>Download Our Root Certificate | -You must install our "Root" certificate before you can use any of the - certificates issued here. Read the online help - to learn more about this. | ||
- ?stage=display_root>Display Our Root Certificate (PEM Encoded) | -This option provides the "Root" certificate PEM encoded text for advanced users - to manually install via copy and paste. Read the online help - to learn more about this. | +- - ?stage=dl_crl>Download Our Certificate Revocation List | -The official list of certificates revoked by this site. Installation and use of - this list is optional. Some e-mail programs will reference this list automagically. - (Some will need it in PEM format.) |
-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. +
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 ' +'.htvar(CA_cert_text($serial)).''; + break; - if ($revoke_date = CAdb_is_revoked($serial)) - 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) { + ?> +