From f2a86ca96fb8e49d978679dab4cfad6ce2f0d9f4 Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 19 Oct 2010 14:19:44 -0400 Subject: [PATCH] Rename 'name' to 'descr' for CA, Certificates, and CRLs, to gain CDATA protection and standardize field names. Ticket #320. --- etc/inc/certs.inc | 10 ++++---- etc/inc/globals.inc | 2 +- etc/inc/system.inc | 2 +- etc/inc/upgrade_config.inc | 23 +++++++++++------- etc/inc/vpn.inc | 6 ++--- usr/local/www/system_advanced_admin.php | 2 +- usr/local/www/system_camanager.php | 14 +++++------ usr/local/www/system_certmanager.php | 30 ++++++++++++------------ usr/local/www/system_crlmanager.php | 22 ++++++++--------- usr/local/www/system_usermanager.php | 16 ++++++------- usr/local/www/vpn_ipsec_phase1.php | 4 ++-- usr/local/www/vpn_openvpn_client.php | 4 ++-- usr/local/www/vpn_openvpn_server.php | 8 +++---- usr/local/www/wizard.php | 6 ++--- usr/local/www/wizards/openvpn_wizard.inc | 10 ++++---- 15 files changed, 83 insertions(+), 76 deletions(-) diff --git a/etc/inc/certs.inc b/etc/inc/certs.inc index 0a9e342905..ef55a3e6a3 100644 --- a/etc/inc/certs.inc +++ b/etc/inc/certs.inc @@ -72,7 +72,7 @@ function & lookup_cert_by_name($name) { global $config; if (is_array($config['cert'])) foreach ($config['cert'] as & $cert) - if ($cert['name'] == $name) + if ($cert['descr'] == $name) return $cert; } @@ -453,7 +453,7 @@ function crl_create(& $crl, $caref, $name, $serial=0, $lifetime=9999) { $ca =& lookup_ca($caref); if (!$ca) return false; - $crl['name'] = $name; + $crl['descr'] = $name; $crl['caref'] = $caref; $crl['serial'] = $serial; $crl['lifetime'] = $lifetime; @@ -502,7 +502,7 @@ function cert_unrevoke($cert, & $crl) { if (!is_crl_internal($crl)) return false; foreach ($crl['cert'] as $id => $rcert) { - if (($rcert['refid'] == $cert['refid']) || ($rcert['name'] == $cert['name'])) { + if (($rcert['refid'] == $cert['refid']) || ($rcert['descr'] == $cert['descr'])) { unset($crl['cert'][$id]); crl_update($crl); return true; @@ -521,7 +521,7 @@ function is_cert_revoked($cert, $crlref = "") { if (!is_array($crl['cert'])) return false; foreach ($crl['cert'] as $rcert) { - if (($rcert['refid'] == $cert['refid']) || ($rcert['name'] == $cert['name'])) + if (($rcert['refid'] == $cert['refid']) || ($rcert['descr'] == $cert['descr'])) return true; } } else { @@ -529,7 +529,7 @@ function is_cert_revoked($cert, $crlref = "") { if (!is_array($crl['cert'])) continue; foreach ($crl['cert'] as $rcert) { - if (($rcert['refid'] == $cert['refid']) || ($rcert['name'] == $cert['name'])) + if (($rcert['refid'] == $cert['refid']) || ($rcert['descr'] == $cert['descr'])) return true; } } diff --git a/etc/inc/globals.inc b/etc/inc/globals.inc index b11e17b8f5..5196dac7b6 100644 --- a/etc/inc/globals.inc +++ b/etc/inc/globals.inc @@ -89,7 +89,7 @@ $g = array( "disablehelpmenu" => false, "disablehelpicon" => false, "debug" => false, - "latest_config" => "7.4", + "latest_config" => "7.5", "nopkg_platforms" => array("cdrom"), "minimum_ram_warning" => "105", "minimum_ram_warning_text" => "128 MB", diff --git a/etc/inc/system.inc b/etc/inc/system.inc index 8f375f5b72..ba9ad05cff 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -692,7 +692,7 @@ function system_webgui_start() { echo "Creating SSL Certificate... "; $cert = array(); $cert['refid'] = uniqid(); - $cert['name'] = "webConfigurator default"; + $cert['descr'] = "webConfigurator default"; mwexec("/usr/bin/openssl genrsa 1024 > {$g['tmp_path']}/ssl.key"); mwexec("/usr/bin/openssl req -new -x509 -nodes -sha1 -days 2000 -key {$g['tmp_path']}/ssl.key > {$g['tmp_path']}/ssl.crt"); $crt = file_get_contents("{$g['tmp_path']}/ssl.crt"); diff --git a/etc/inc/upgrade_config.inc b/etc/inc/upgrade_config.inc index ca4ec2a30a..1a8c5a1cfb 100644 --- a/etc/inc/upgrade_config.inc +++ b/etc/inc/upgrade_config.inc @@ -1307,7 +1307,7 @@ function upgrade_051_to_052() { /* create ca entry */ $ca = array(); $ca['refid'] = uniqid(); - $ca['name'] = "OpenVPN Server CA #{$index}"; + $ca['descr'] = "OpenVPN Server CA #{$index}"; $ca['crt'] = $server['ca_cert']; $ca['crl'] = $server['crl']; $config['ca'][] = $ca; @@ -1320,7 +1320,7 @@ function upgrade_051_to_052() { /* create cert entry */ $cert = array(); $cert['refid'] = uniqid(); - $cert['name'] = "OpenVPN Server Certificate #{$index}"; + $cert['descr'] = "OpenVPN Server Certificate #{$index}"; $cert['crt'] = $server['server_cert']; $cert['prv'] = $server['server_key']; $config['cert'][] = $cert; @@ -1437,7 +1437,7 @@ function upgrade_051_to_052() { /* create ca entry */ $ca = array(); $ca['refid'] = uniqid(); - $ca['name'] = "OpenVPN Client CA #{$index}"; + $ca['descr'] = "OpenVPN Client CA #{$index}"; $ca['crt'] = $client['ca_cert']; $ca['crl'] = $client['crl']; $config['ca'][] = $ca; @@ -1450,7 +1450,7 @@ function upgrade_051_to_052() { /* create cert entry */ $cert = array(); $cert['refid'] = uniqid(); - $cert['name'] = "OpenVPN Client Certificate #{$index}"; + $cert['descr'] = "OpenVPN Client Certificate #{$index}"; $cert['crt'] = $client['client_cert']; $cert['prv'] = $client['client_key']; $config['cert'][] = $cert; @@ -1615,7 +1615,7 @@ function upgrade_052_to_053() { /* create cert entry */ $cert = array(); $cert['refid'] = uniqid(); - $cert['name'] = "webConfigurator SSL Certificate"; + $cert['descr'] = "webConfigurator SSL Certificate"; $cert['crt'] = $config['system']['webgui']['certificate']; $cert['prv'] = $config['system']['webgui']['private-key']; $config['cert'][] = $cert; @@ -1841,7 +1841,7 @@ function upgrade_055_to_056() { $ca['crt'] = $cacert['cert'][0]; else $ca['crt'] = $cacert['cert']; - $ca['name'] = $cacert['ident']; + $ca['descr'] = $cacert['ident']; $config['ca'][] = $ca; } unset($config['ipsec']['cacert']); @@ -1852,7 +1852,7 @@ function upgrade_055_to_056() { foreach($config['ipsec']['phase1'] as & $ph1ent) { $cert = array(); $cert['refid'] = uniqid(); - $cert['name'] = "IPsec Peer {$ph1ent['remote-gateway']} Certificate"; + $cert['descr'] = "IPsec Peer {$ph1ent['remote-gateway']} Certificate"; if (is_array($ph1ent['cert'])) $cert['crt'] = $ph1ent['cert'][0]; else @@ -2161,7 +2161,7 @@ function upgrade_068_to_069() { continue; $rids = array(); foreach ($user['cert'] as $id => $cert) { - if (!isset($cert['name'])) + if (!isset($cert['descr'])) continue; $tcert = $cert; // Make sure each cert gets a refid @@ -2242,4 +2242,11 @@ function upgrade_073_to_074() { global $config; rename_field($config['system']['user'], 'fullname', 'descr'); } + +function upgrade_074_to_075() { + global $config; + rename_field($config['ca'], 'name', 'descr'); + rename_field($config['cert'], 'name', 'descr'); + rename_field($config['crl'], 'name', 'descr'); +} ?> diff --git a/etc/inc/vpn.inc b/etc/inc/vpn.inc index 8670bde012..b346ce6b39 100644 --- a/etc/inc/vpn.inc +++ b/etc/inc/vpn.inc @@ -206,18 +206,18 @@ function vpn_ipsec_configure($ipchg = false) if (is_array($config['ca']) && count($config['ca'])) { foreach ($config['ca'] as $ca) { if (!isset($ca['crt'])) { - log_error("Error: Invalid certificate info for {$ca['name']}"); + log_error("Error: Invalid certificate info for {$ca['descr']}"); continue; } $cert = base64_decode($ca['crt']); $x509cert = openssl_x509_parse(openssl_x509_read($cert)); if (!is_array($x509cert) || !isset($x509cert['hash'])) { - log_error("Error: Invalid certificate hash info for {$ca['name']}"); + log_error("Error: Invalid certificate hash info for {$ca['descr']}"); continue; } $fname = $g['varetc_path']."/".$x509cert['hash'].".0"; if (!file_put_contents($fname, $cert)) { - log_error("Error: Cannot write IPsec CA file for {$ca['name']}"); + log_error("Error: Cannot write IPsec CA file for {$ca['descr']}"); continue; } } diff --git a/usr/local/www/system_advanced_admin.php b/usr/local/www/system_advanced_admin.php index c3ea1a0da5..f34d1c7152 100644 --- a/usr/local/www/system_advanced_admin.php +++ b/usr/local/www/system_advanced_admin.php @@ -286,7 +286,7 @@ function prot_change() { if ($pconfig['ssl-certref'] == $cert['refid']) $selected = "selected"; ?> - + diff --git a/usr/local/www/system_camanager.php b/usr/local/www/system_camanager.php index 815802f2ad..b60fc5167e 100644 --- a/usr/local/www/system_camanager.php +++ b/usr/local/www/system_camanager.php @@ -78,7 +78,7 @@ if ($act == "del") { if ($a_cert[$index]['caref'] == $a_ca[$id]['refid']) unset($a_cert[$index]); - $name = $a_ca[$id]['name']; + $name = $a_ca[$id]['descr']; unset($a_ca[$id]); write_config(); $savemsg = sprintf(gettext("Certificate Authority %s successfully deleted"), $name) . "
"; @@ -98,7 +98,7 @@ if ($act == "exp") { exit; } - $exp_name = urlencode("{$a_ca[$id]['name']}.crt"); + $exp_name = urlencode("{$a_ca[$id]['descr']}.crt"); $exp_data = base64_decode($a_ca[$id]['crt']); $exp_size = strlen($exp_data); @@ -116,7 +116,7 @@ if ($act == "expkey") { exit; } - $exp_name = urlencode("{$a_ca[$id]['name']}.key"); + $exp_name = urlencode("{$a_ca[$id]['descr']}.key"); $exp_data = base64_decode($a_ca[$id]['prv']); $exp_size = strlen($exp_data); @@ -171,7 +171,7 @@ if ($_POST) { if (isset($id) && $a_ca[$id]) $ca = $a_ca[$id]; - $ca['name'] = $pconfig['name']; + $ca['descr'] = $pconfig['descr']; if ($pconfig['method'] == "existing") ca_import($ca, $pconfig['cert'], $pconfig['key']); @@ -255,7 +255,7 @@ function method_change() { - + @@ -430,7 +430,7 @@ function method_change() { "; @@ -109,7 +109,7 @@ if ($act == "exp") { exit; } - $exp_name = urlencode("{$a_cert[$id]['name']}.crt"); + $exp_name = urlencode("{$a_cert[$id]['descr']}.crt"); $exp_data = base64_decode($a_cert[$id]['crt']); $exp_size = strlen($exp_data); @@ -127,7 +127,7 @@ if ($act == "key") { exit; } - $exp_name = urlencode("{$a_cert[$id]['name']}.key"); + $exp_name = urlencode("{$a_cert[$id]['descr']}.key"); $exp_data = base64_decode($a_cert[$id]['prv']); $exp_size = strlen($exp_data); @@ -145,7 +145,7 @@ if ($act == "csr") { exit; } - $pconfig['name'] = $a_cert[$id]['name']; + $pconfig['descr'] = $a_cert[$id]['descr']; $pconfig['csr'] = base64_decode($a_cert[$id]['csr']); } @@ -222,7 +222,7 @@ if ($_POST) { if (isset($id) && $a_cert[$id]) $cert = $a_cert[$id]; - $cert['name'] = $pconfig['name']; + $cert['descr'] = $pconfig['descr']; if ($pconfig['method'] == "import") cert_import($cert, $pconfig['cert'], $pconfig['key']); @@ -296,7 +296,7 @@ if ($_POST) { $cert = $a_cert[$id]; - $cert['name'] = $pconfig['name']; + $cert['descr'] = $pconfig['descr']; csr_complete($cert, $pconfig['cert']); @@ -436,12 +436,12 @@ function internalca_change() { - + @@ -504,7 +504,7 @@ function internalca_change() { if ($pconfig['caref'] == $ca['refid']) $selected = "selected"; ?> - + @@ -709,13 +709,13 @@ function internalca_change() { continue; $ca = lookup_ca($cert['caref']); if ($ca) - $caname = " (CA: {$ca['name']})"; + $caname = " (CA: {$ca['descr']})"; if ($pconfig['certref'] == $cert['refid']) $selected = "selected"; if (cert_in_use($cert['refid'])) $inuse = " *In Use"; ?> - + @@ -742,7 +742,7 @@ function internalca_change() { - + @@ -794,7 +794,7 @@ function internalca_change() { "; } else { - $name = $a_crl[$id]['name']; + $name = $a_crl[$id]['descr']; unset($a_crl[$id]); write_config(); $savemsg = sprintf(gettext("Certificate Revocation List %s successfully deleted"), $name) . "
"; @@ -99,7 +99,7 @@ if ($act == "exp") { exit; } - $exp_name = urlencode("{$a_crl[$id]['name']}.crl"); + $exp_name = urlencode("{$a_crl[$id]['descr']}.crl"); $exp_data = base64_decode($a_crl[$id]['text']); $exp_size = strlen($exp_data); @@ -147,7 +147,7 @@ if ($_POST) { if (isset($id) && $a_crl[$id]) $crl = $a_crl[$id]; - $crl['name'] = $pconfig['name']; + $crl['descr'] = $pconfig['descr']; $crl['caref'] = $pconfig['caref']; if ($pconfig['method'] == "existing") { @@ -244,7 +244,7 @@ NOTE: This page is still a work in progress and is not yet fully functional. - + @@ -257,7 +257,7 @@ NOTE: This page is still a work in progress and is not yet fully functional. if ($pconfig['caref'] == $ca['refid']) $selected = "selected"; ?> - + @@ -341,7 +341,7 @@ NOTE: This page is still a work in progress and is not yet fully functional. $i = 0; foreach($a_ca as $ca): - $name = htmlspecialchars($ca['name']); + $name = htmlspecialchars($ca['descr']); if($ca['prv']) { $caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png"; @@ -364,7 +364,7 @@ NOTE: This page is still a work in progress and is not yet fully functional. - " alt="" width="17" height="17" border="0" /> + " alt="" width="17" height="17" border="0" /> @@ -377,17 +377,17 @@ NOTE: This page is still a work in progress and is not yet fully functional. $inuse = crl_in_use($tmpcrl['refid']); ?> - + - " alt="" width="17" height="17" border="0" /> + " alt="" width="17" height="17" border="0" /> - ')"> - " alt="" width="17" height="17" border="0" /> + ')"> + " alt="" width="17" height="17" border="0" /> diff --git a/usr/local/www/system_usermanager.php b/usr/local/www/system_usermanager.php index a80ba00d0a..706ffde356 100644 --- a/usr/local/www/system_usermanager.php +++ b/usr/local/www/system_usermanager.php @@ -102,7 +102,7 @@ if (isAllowedPage("system_usermanager")) { $cert =& lookup_cert($a_user[$id]['cert'][$_GET['certid']]); - $exp_name = urlencode("{$a_user[$id]['name']}-{$cert['name']}.crt"); + $exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.crt"); $exp_data = base64_decode($cert['crt']); $exp_size = strlen($exp_data); @@ -122,7 +122,7 @@ if (isAllowedPage("system_usermanager")) { $cert =& lookup_cert($a_user[$id]['cert'][$_GET['certid']]); - $exp_name = urlencode("{$a_user[$id]['name']}-{$cert['name']}.key"); + $exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.key"); $exp_data = base64_decode($cert['prv']); $exp_size = strlen($exp_data); @@ -141,7 +141,7 @@ if (isAllowedPage("system_usermanager")) { } $certdeleted = lookup_cert($a_user[$id]['cert'][$_GET['certid']]); - $certdeleted = $certdeleted['name']; + $certdeleted = $certdeleted['descr']; unset($a_user[$id]['cert'][$_GET['certid']]); write_config(); $_GET['act'] = "edit"; @@ -302,7 +302,7 @@ if (isAllowedPage("system_usermanager")) { $cert['refid'] = uniqid(); $userent['cert'] = array(); - $cert['name'] = $_POST['name']; + $cert['descr'] = $_POST['name']; $subject = cert_get_subject_array($ca['crt']); @@ -644,10 +644,10 @@ function sshkeyClicked(obj) { ?> - + - + @@ -703,7 +703,7 @@ function sshkeyClicked(obj) { - + @@ -715,7 +715,7 @@ function sshkeyClicked(obj) { if (!$ca['prv']) continue; ?> - + diff --git a/usr/local/www/vpn_ipsec_phase1.php b/usr/local/www/vpn_ipsec_phase1.php index 25c6f4f285..c2ba332118 100644 --- a/usr/local/www/vpn_ipsec_phase1.php +++ b/usr/local/www/vpn_ipsec_phase1.php @@ -719,7 +719,7 @@ function dpdchkbox_change() { if ($pconfig['certref'] == $cert['refid']) $selected = "selected"; ?> - +
@@ -738,7 +738,7 @@ function dpdchkbox_change() { if ($pconfig['caref'] == $ca['refid']) $selected = "selected"; ?> - +
diff --git a/usr/local/www/vpn_openvpn_client.php b/usr/local/www/vpn_openvpn_client.php index d957f86ca1..f0db930e9e 100644 --- a/usr/local/www/vpn_openvpn_client.php +++ b/usr/local/www/vpn_openvpn_client.php @@ -615,7 +615,7 @@ function autotls_change() { if ($pconfig['caref'] == $ca['refid']) $selected = "selected"; ?> - + @@ -630,7 +630,7 @@ function autotls_change() { if ($pconfig['certref'] == $cert['refid']) $selected = "selected"; ?> - + diff --git a/usr/local/www/vpn_openvpn_server.php b/usr/local/www/vpn_openvpn_server.php index 216827f81d..c6e4825f84 100644 --- a/usr/local/www/vpn_openvpn_server.php +++ b/usr/local/www/vpn_openvpn_server.php @@ -721,7 +721,7 @@ function netbios_change() { if ($pconfig['caref'] == $ca['refid']) $selected = "selected"; ?> - + @@ -739,7 +739,7 @@ function netbios_change() { if ($pconfig['crlref'] == $crl['refid']) $selected = "selected"; ?> - + @@ -751,12 +751,12 @@ function netbios_change() { - + diff --git a/usr/local/www/wizard.php b/usr/local/www/wizard.php index 3ccf662906..9a4a8fe56e 100755 --- a/usr/local/www/wizard.php +++ b/usr/local/www/wizard.php @@ -518,7 +518,7 @@ function showchange() { echo "\n"; } foreach($config['ca'] as $ca) { - $name = htmlspecialchars($ca['name']); + $name = htmlspecialchars($ca['descr']); $SELECTED = ""; if ($value == $name) $SELECTED = " SELECTED"; $to_echo = "\n"; @@ -556,9 +556,9 @@ function showchange() { echo "\n"; } foreach($config['cert'] as $ca) { - if (stristr($ca['name'], "webconf")) + if (stristr($ca['descr'], "webconf")) continue; - $name = htmlspecialchars($ca['name']); + $name = htmlspecialchars($ca['descr']); $SELECTED = ""; if ($value == $name) $SELECTED = " SELECTED"; $to_echo = "\n"; diff --git a/usr/local/www/wizards/openvpn_wizard.inc b/usr/local/www/wizards/openvpn_wizard.inc index fc7d0c45bd..518aad2e43 100644 --- a/usr/local/www/wizards/openvpn_wizard.inc +++ b/usr/local/www/wizards/openvpn_wizard.inc @@ -187,7 +187,7 @@ function step7_submitphpaction() { $cacns = array(); if (is_array($config['ca'])) { foreach($config['ca'] as $ca) { - $canames[] = $ca['name']; + $canames[] = $ca['descr']; $cainfo = cert_get_subject_hash($ca['crt']); $cacns[] = $cainfo["CN"]; } @@ -214,7 +214,7 @@ function step8_stepbeforeformdisplay() { global $stepid, $config; if (count($config['cert']) < 1 || - (count($config['cert']) == 1 && stristr($config['cert'][0]['name'], "webconf"))) { + (count($config['cert']) == 1 && stristr($config['cert'][0]['descr'], "webconf"))) { $stepid++; } } @@ -273,7 +273,7 @@ function step9_submitphpaction() { $certcns = array(); if (is_array($config['cert'])) { foreach($config['cert'] as $cert) { - $certnames[] = $cert['name']; + $certnames[] = $cert['descr']; $certinfo = cert_get_subject_hash($cert['crt']); $certcns[] = $certinfo["CN"]; } @@ -440,7 +440,7 @@ function step12_submitphpaction() { if (isset($pconfig['step6']['uselist']) && !empty($pconfig['step6']['certca'])) { $ca = array(); $ca['refid'] = uniqid(); - $ca['name'] = $pconfig['step6']['certca']; + $ca['descr'] = $pconfig['step6']['certca']; $dn = array( 'countryName' => $pconfig['step6']['country'], 'stateOrProvinceName' => $pconfig['step6']['state'], @@ -467,7 +467,7 @@ function step12_submitphpaction() { if (isset($pconfig['step9']['uselist'])) { $cert = array(); $cert['refid'] = uniqid(); - $cert['name'] = $pconfig['step9']['certname']; + $cert['descr'] = $pconfig['step9']['certname']; $dn = array( 'countryName' => $pconfig['step9']['country'], 'stateOrProvinceName' => $pconfig['step9']['state'],