From ecefc738d72fef321fd00f9c624fead7390348b7 Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 7 Jul 2010 12:22:20 -0400 Subject: [PATCH] Allow importing of a CA's private key (optionally). --- etc/inc/certs.inc | 4 +++- usr/local/www/system_camanager.php | 33 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/etc/inc/certs.inc b/etc/inc/certs.inc index 88fb2b9098..6d48e557e6 100644 --- a/etc/inc/certs.inc +++ b/etc/inc/certs.inc @@ -101,10 +101,12 @@ function ca_chain(& $cert) { return ""; } -function ca_import(& $ca, $str) { +function ca_import(& $ca, $str, $key="") { global $config; $ca['crt'] = base64_encode($str); + if (!empty($key)) + $ca['prv'] = base64_encode($key); $subject = cert_get_subject($str, false); $issuer = cert_get_issuer($str, false); diff --git a/usr/local/www/system_camanager.php b/usr/local/www/system_camanager.php index 0ca94945a1..7aae43e5f7 100644 --- a/usr/local/www/system_camanager.php +++ b/usr/local/www/system_camanager.php @@ -110,6 +110,24 @@ if ($act == "exp") { exit; } +if ($act == "expkey") { + + if (!$a_ca[$id]) { + pfSenseHeader("system_camanager.php"); + exit; + } + + $exp_name = urlencode("{$a_ca[$id]['name']}.key"); + $exp_data = base64_decode($a_ca[$id]['prv']); + $exp_size = strlen($exp_data); + + header("Content-Type: application/octet-stream"); + header("Content-Disposition: attachment; filename={$exp_name}"); + header("Content-Length: $exp_size"); + echo $exp_data; + exit; +} + if ($_POST) { unset($input_errors); @@ -157,7 +175,7 @@ if ($_POST) { $ca['name'] = $pconfig['name']; if ($pconfig['method'] == "existing") - ca_import($ca, $pconfig['cert']); + ca_import($ca, $pconfig['cert'], $pconfig['key']); if ($pconfig['method'] == "internal") { @@ -275,6 +293,14 @@ function method_change() { + +
+ + +
+ + + @@ -457,6 +483,11 @@ function method_change() { " alt="" width="17" height="17" border="0" /> + + + " alt="" width="17" height="17" border="0" /> + + ')"> " alt="" width="17" height="17" border="0" />