diff --git a/ca/request_cert.php b/ca/request_cert.php
index 5e2d1b5..03aeb5d 100644
--- a/ca/request_cert.php
+++ b/ca/request_cert.php
@@ -25,7 +25,8 @@ $passwdv = gpvar('passwdv');
$expiry = gpvar('expiry');
$keysize = gpvar('keysize');
$cert_type = gpvar('cert_type');
-
+$dns_names = gpvar('dns_names');
+$ip_addr = gpvar('ip_addr');
# To repopulate form after error.
$hidden_fields = '
@@ -41,6 +42,8 @@ $hidden_fields = '
+
+
';
@@ -72,10 +75,21 @@ case 'validate':
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 = '
- Certificate Life
+ Certificate Life*
- Key Size
+ Key Size*
- Certificate Use:
-
+ Certificate Use:*
+
E-mail, SSL Client';
print 'E-mail, SSL Client, Code Signing ';
@@ -317,8 +338,16 @@ default:
+
+ Alternative DNS Names (only one per Line)
+
+
+
+ IP's (only one per Line)
+
+
- * All fields are required
+ * Fields are required
diff --git a/include/common.php b/include/common.php
index 1352cdc..4713dd3 100644
--- a/include/common.php
+++ b/include/common.php
@@ -36,8 +36,26 @@ function printHeader($withmenu="default") {
?>
+
PHPki:
+
255 )
+ return false;
+ return true;
+ }
+ return false;
+}
+
+#
+# Returns True if the given string is a valid FQDN
+#
+function is_fqdn($FQDN) {
+ return (!empty($FQDN) && preg_match('/(?=^.{1,254}$)(^(?:(?!\d|-)[a-z0-9\-]{1,63}(? 0);
+}
+
#
# Checks regexp in every element of an array, returns TRUE as soon
# as a match is found.
diff --git a/include/openssl_functions.php b/include/openssl_functions.php
index 0883deb..e2597fd 100644
--- a/include/openssl_functions.php
+++ b/include/openssl_functions.php
@@ -5,15 +5,49 @@
// 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=4096) {
+function CA_create_cnf($country='',$province='',$locality='',$organization='',$unit='',$common_name='',$email='',$keysize=4096,$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;
+ $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";
+ }
+
$cnf_contents = "
HOME = $config[home_dir]
RANDFILE = $config[random]
-dir = $config[ca_dir]
+dir = $config[ca_dir]
certs = $config[cert_dir]
crl_dir = $config[crl_dir]
database = $config[index]
@@ -104,7 +138,7 @@ subjectKeyIdentifier = hash
subjectAltName = email:copy
crlDistributionPoints = URI:$config[base_url]index.php?stage=dl_crl
nsComment = \"PHPki/OpenSSL Generated Root Certificate\"
-#nsCaRevocationUrl = ns_revoke_query.php?
+#nsCaRevocationUrl = $config[base_url]ns_revoke_query.php?$serial
nsCaPolicyUrl = $config[base_url]policy.html
[ email_ext ]
@@ -119,7 +153,7 @@ issuerAltName = issuer:copy
crlDistributionPoints = URI:$config[base_url]index.php?stage=dl_crl
nsComment = \"PHPki/OpenSSL Generated Personal Certificate\"
nsBaseUrl = $config[base_url]
-nsRevocationUrl = ns_revoke_query.php?
+nsRevocationUrl = $config[base_url]ns_revoke_query.php?$serial
nsCaPolicyUrl = $config[base_url]policy.html
[ email_signing_ext ]
@@ -134,7 +168,7 @@ issuerAltName = issuer:copy
crlDistributionPoints = URI:$config[base_url]index.php?stage=dl_crl
nsComment = \"PHPki/OpenSSL Generated Personal Certificate\"
nsBaseUrl = $config[base_url]
-nsRevocationUrl = ns_revoke_query.php?
+nsRevocationUrl = $config[base_url]ns_revoke_query.php?$serial
nsCaPolicyUrl = $config[base_url]policy.html
[ server_ext ]
@@ -144,12 +178,12 @@ nsCertType = critical, server
extendedKeyUsage = critical, serverAuth
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always, issuer:always
-subjectAltName = DNS:$common_name,email:copy
+subjectAltName = $server_altnames
issuerAltName = issuer:copy
crlDistributionPoints = URI:$config[base_url]index.php?stage=dl_crl
nsComment = \"PHPki/OpenSSL Generated Server Certificate\"
nsBaseUrl = $config[base_url]
-nsRevocationUrl = ns_revoke_query.php?
+nsRevocationUrl = $config[base_url]ns_revoke_query.php?$serial
nsCaPolicyUrl = $config[base_url]policy.html
[ time_stamping_ext ]
@@ -163,7 +197,7 @@ issuerAltName = issuer:copy
crlDistributionPoints = URI:$config[base_url]index.php?stage=dl_crl
nsComment = \"PHPki/OpenSSL Generated Time Stamping Certificate\"
nsBaseUrl = $config[base_url]
-nsRevocationUrl = ns_revoke_query.php?
+nsRevocationUrl = $config[base_url]ns_revoke_query.php?$serial
[ vpn_client_ext ]
basicConstraints = critical, CA:false
@@ -191,8 +225,12 @@ nsCertType = critical, server, client
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always, issuer:always
subjectAltName = DNS:$common_name,email:copy
+
+[alt_names]
+$alt_names
";
+
# Write out the config file.
$cnf_file = tempnam('./tmp','cnf-');
$handle = fopen($cnf_file,"w");
@@ -466,7 +504,7 @@ function CA_revoke_cert($serial) {
//
// 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=1024) {
+function CA_create_cert($cert_type='email',$country,$province,$locality,$organization,$unit,$common_name,$email,$expiry,$passwd,$keysize=1024,$dns_names,$ip_addr) {
global $config;
# Wait here if another user has the database locked.
@@ -484,11 +522,11 @@ function CA_create_cert($cert_type='email',$country,$province,$locality,$organiz
$expiry_days = round($expiry * 365.25, 0);
- $cnf_file = CA_create_cnf($country,$province,$locality,$organization,$unit,$common_name,$email,$keysize);
+ $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);
+ $_passwd = escshellarg($passwd);
$friendly_name = escshellarg($common_name);
$extensions = escshellarg($cert_type.'_ext');
diff --git a/ns_revoke_query.php b/ns_revoke_query.php
index 6473bf3..0b9ebd5 100644
--- a/ns_revoke_query.php
+++ b/ns_revoke_query.php
@@ -14,13 +14,17 @@
# application/x-netscape-revocation containing a single character
# '1' if the certificate is revoked, '0' if it is valid.
#
-include('./config.in.php');
+include('./config.php');
include(STORE_DIR.'/config/config.php');
$serial = escapeshellcmd(trim($_SERVER['QUERY_STRING']));
-header("Content-type: application/x-netscape-revocation");
-$regexp = "^R\t.*\t.*\t$serial\t.*\t.*$";
-if (exec("egrep '$regexp' ca/$config[index]"))
+#header("Content-type: application/x-netscape-revocation");
+
+# old Reg Ex doesnt work, new should do the work
+#$regexp = "^R\t.*\t.*\t$serial\t.*\t.*$";
+$regexp = "^R.*$serial.*$";
+
+if (exec("egrep '$regexp' $config[index]"))
print '1';
else
print '0';