diff --git a/etc/inc/certs.inc b/etc/inc/certs.inc
index 8d5604f23c..2b192c1f6d 100644
--- a/etc/inc/certs.inc
+++ b/etc/inc/certs.inc
@@ -121,13 +121,14 @@ function ca_chain(& $cert) {
return "";
}
-function ca_import(& $ca, $str, $key="") {
+function ca_import(& $ca, $str, $key="", $serial=0) {
global $config;
$ca['crt'] = base64_encode($str);
if (!empty($key))
$ca['prv'] = base64_encode($key);
-
+ if (!empty($serial))
+ $ca['serial'] = $serial;
$subject = cert_get_subject($str, false);
$issuer = cert_get_issuer($str, false);
@@ -355,6 +356,7 @@ function cert_get_issuer($str_crt, $decode = true) {
$inf_crt = openssl_x509_parse($str_crt);
$components = $inf_crt['issuer'];
+ ksort($components);
if (!is_array($components))
return "unknown";
foreach ($components as $a => $v) {
diff --git a/usr/local/www/system_camanager.php b/usr/local/www/system_camanager.php
index 6eddd3956c..3bf11652c5 100644
--- a/usr/local/www/system_camanager.php
+++ b/usr/local/www/system_camanager.php
@@ -84,6 +84,19 @@ if ($act == "del") {
$savemsg = sprintf(gettext("Certificate Authority %s successfully deleted"), $name) . "
";
}
+if ($act == "edit") {
+ if (!$a_ca[$id]) {
+ pfSenseHeader("system_camanager.php");
+ exit;
+ }
+ $pconfig['descr'] = $a_ca[$id]['descr'];
+ $pconfig['refid'] = $a_ca[$id]['refid'];
+ $pconfig['cert'] = base64_decode($a_ca[$id]['crt']);
+ $pconfig['serial'] = $a_ca[$id]['serial'];
+ if (!empty($a_ca[$id]['prv']))
+ $pconfig['key'] = base64_decode($a_ca[$id]['prv']);
+}
+
if ($act == "new") {
$pconfig['method'] = $_GET['method'];
$pconfig['keylen'] = "2048";
@@ -169,26 +182,37 @@ if ($_POST) {
if (!$input_errors) {
$ca = array();
- $ca['refid'] = uniqid();
+ if (!isset($pconfig['refid']) || empty($pconfig['refid']))
+ $ca['refid'] = uniqid();
+ else
+ $ca['refid'] = $pconfig['refid'];
+
if (isset($id) && $a_ca[$id])
$ca = $a_ca[$id];
- $ca['descr'] = $pconfig['descr'];
+ $ca['descr'] = $pconfig['descr'];
- if ($pconfig['method'] == "existing")
- ca_import($ca, $pconfig['cert'], $pconfig['key']);
+ if ($_POST['edit'] == "edit") {
+ $ca['descr'] = $pconfig['descr'];
+ $ca['refid'] = $pconfig['refid'];
+ $ca['serial'] = $pconfig['serial'];
+ $ca['crt'] = base64_encode($pconfig['cert']);
+ if (!empty($pconfig['key']))
+ $ca['prv'] = base64_encode($pconfig['key']);
+ } else {
+ if ($pconfig['method'] == "existing")
+ ca_import($ca, $pconfig['cert'], $pconfig['key'], $pconfig['serial']);
- if ($pconfig['method'] == "internal")
- {
- $dn = array(
- 'countryName' => $pconfig['dn_country'],
- 'stateOrProvinceName' => $pconfig['dn_state'],
- 'localityName' => $pconfig['dn_city'],
- 'organizationName' => $pconfig['dn_organization'],
- 'emailAddress' => $pconfig['dn_email'],
- 'commonName' => $pconfig['dn_commonname']);
-
- ca_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn);
+ if ($pconfig['method'] == "internal") {
+ $dn = array(
+ 'countryName' => $pconfig['dn_country'],
+ 'stateOrProvinceName' => $pconfig['dn_state'],
+ 'localityName' => $pconfig['dn_city'],
+ 'organizationName' => $pconfig['dn_organization'],
+ 'emailAddress' => $pconfig['dn_email'],
+ 'commonName' => $pconfig['dn_commonname']);
+ ca_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn);
+ }
}
if (isset($id) && $a_ca[$id])
@@ -250,9 +274,14 @@ function method_change() {