diff --git a/src/www/system_certmanager.php b/src/www/system_certmanager.php index 72ac922ed..fae47ffe6 100644 --- a/src/www/system_certmanager.php +++ b/src/www/system_certmanager.php @@ -171,37 +171,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { echo $exp_data; } exit; - } elseif ($act == "p12") { - // export cert+key in p12 format - if (isset($id)) { - $exp_name = urlencode("{$a_cert[$id]['descr']}.p12"); - $args = array(); - $args['friendly_name'] = $a_cert[$id]['descr']; - - $ca = lookup_ca($a_cert[$id]['caref']); - if ($ca) { - $args['extracerts'] = openssl_x509_read(base64_decode($ca['crt'])); - } - set_error_handler ( - function () { - return; - } - ); - - $exp_data = ''; - $res_crt = openssl_x509_read(base64_decode($a_cert[$id]['crt'])); - $res_key = openssl_pkey_get_private(array(0 => base64_decode($a_cert[$id]['prv']) , 1 => '')); - - openssl_pkcs12_export($res_crt, $exp_data, $res_key, null, $args); - $exp_size = strlen($exp_data); - restore_error_handler(); - - header("Content-Type: application/octet-stream"); - header("Content-Disposition: attachment; filename={$exp_name}"); - header("Content-Length: $exp_size"); - echo $exp_data; - } - exit; } elseif ($act == "csr") { if (!isset($id)) { header(url_safe('Location: /system_certmanager.php')); @@ -228,6 +197,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + $pconfig = $_POST; if (isset($a_cert[$_POST['id']])) { $id = $_POST['id']; } @@ -247,6 +217,39 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } header(url_safe('Location: /system_certmanager.php')); exit; + } elseif ($act == "p12") { + // export cert+key in p12 format + if (isset($id)) { + $exp_name = urlencode("{$a_cert[$id]['descr']}.p12"); + $args = array(); + $args['friendly_name'] = $a_cert[$id]['descr']; + + $ca = lookup_ca($a_cert[$id]['caref']); + if ($ca) { + $args['extracerts'] = openssl_x509_read(base64_decode($ca['crt'])); + } + set_error_handler ( + function () { + return; + } + ); + + $exp_data = ''; + $res_crt = openssl_x509_read(base64_decode($a_cert[$id]['crt'])); + $res_key = openssl_pkey_get_private(array(0 => base64_decode($a_cert[$id]['prv']) , 1 => '')); + $res_pw = !empty($pconfig['password']) ? $pconfig['password'] : null; + openssl_pkcs12_export($res_crt, $exp_data, $res_key, $res_pw, $args); + restore_error_handler(); + + $output = json_encode(array( + 'filename' => $exp_name, + 'content' => base64_encode($exp_data) + )); + header("Content-Type: application/json;charset=UTF-8"); + // header("Content-Length: ". strlen($output)); + echo $output; + } + exit; } elseif ($act == "csr") { $input_errors = array(); $pconfig = $_POST; @@ -285,7 +288,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } } elseif (!empty($_POST['save'])) { $input_errors = array(); - $pconfig = $_POST; /* input validation */ if ($pconfig['certmethod'] == "import") { @@ -563,6 +565,67 @@ if (empty($act)) { }); }); + $('.p12btn').on('click', function(event) { + event.preventDefault(); + var id = $(this).data('id'); + + let password_input = $('">'); + let confirm_input = $('">'); + let dialog_items = $('