diff --git a/src/etc/inc/certs.inc b/src/etc/inc/certs.inc index 1d6faf7fe7..1f8f5eeb21 100644 --- a/src/etc/inc/certs.inc +++ b/src/etc/inc/certs.inc @@ -1898,6 +1898,11 @@ function cert_print_infoblock($cert) { $certextinfo .= "{$expstring}"; $certextinfo .= '
'; + /* CA Trust store presence */ + $certextinfo .= '' . gettext("Trust Store: ") . ' '; + $certextinfo .= (isset($cert['trust']) && ($cert['trust'] == "enabled")) ? gettext('Included') : gettext('Excluded'); + $certextinfo .= '
'; + /* Output the infoblock */ if (!empty($certextinfo)) { ?>
@@ -1956,4 +1961,48 @@ function cert_notify_expiring() { } } +/****f* certs/ca_setup_trust_store + * NAME + * ca_setup_trust_store - Setup local CA trust store so that CA entries in the + * configuration may be trusted by the operating system. + * INPUTS + * None + * RESULT + * CAs marked as trusted in the configuration will be setup in the OS trust store. + ******/ + +function ca_setup_trust_store() { + global $config; + + /* This directory is trusted by OpenSSL on FreeBSD by default */ + $trust_store_directory = '/etc/ssl/certs'; + + /* Create the directory if it does not already exist, and clean it up if it does. */ + safe_mkdir($trust_store_directory); + unlink_if_exists("{$trust_store_directory}/*.0"); + + init_config_arr(array('ca')); + foreach ($config['ca'] as $ca) { + /* If the entry is invalid or is not trusted, skip it. */ + if (!is_array($ca) || + empty($ca['crt']) || + !isset($ca['trust']) || + ($ca['trust'] != "enabled")) { + continue; + } + + /* Decode the certificate contents */ + $cert_contents = base64_decode($ca['crt']); + /* Get hash value to use for filename */ + $cert_details = openssl_x509_parse($cert_contents); + $ca_filename = "{$trust_store_directory}/{$cert_details['hash']}.0"; + + /* Write CA to trust store and ensure it has correct permissions. */ + file_put_contents($ca_filename, $cert_contents); + chmod($ca_filename, 0644); + chown($ca_filename, 'root'); + chgrp($ca_filename, 'wheel'); + } +} + ?> diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index 06748b334e..4280e2eacb 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -182,6 +182,9 @@ system_hosts_generate(); /* configure loopback interface */ interfaces_loopback_configure(); +/* Setup Local CA Trust Store */ +ca_setup_trust_store(); + /* start syslogd */ system_syslogd_start(); diff --git a/src/usr/local/www/system_camanager.php b/src/usr/local/www/system_camanager.php index 8516a97c09..bfcf42f3b9 100644 --- a/src/usr/local/www/system_camanager.php +++ b/src/usr/local/www/system_camanager.php @@ -87,6 +87,7 @@ if ($_POST['act'] == "del") { $name = $a_ca[$id]['descr']; unset($a_ca[$id]); write_config(); + ca_setup_trust_store(); $savemsg = sprintf(gettext("Certificate Authority %s and its CRLs (if any) successfully deleted."), htmlspecialchars($name)); pfSenseHeader("system_camanager.php"); exit; @@ -102,6 +103,7 @@ if ($act == "edit") { $pconfig['refid'] = $a_ca[$id]['refid']; $pconfig['cert'] = base64_decode($a_ca[$id]['crt']); $pconfig['serial'] = $a_ca[$id]['serial']; + $pconfig['trust'] = ($a_ca[$id]['trust'] == 'enabled'); if (!empty($a_ca[$id]['prv'])) { $pconfig['key'] = base64_decode($a_ca[$id]['prv']); } @@ -242,6 +244,7 @@ if ($_POST['save']) { } $ca['descr'] = $pconfig['descr']; + $ca['trust'] = ($pconfig['trust'] == 'yes') ? "enabled" : "disabled"; if ($act == "edit") { $ca['descr'] = $pconfig['descr']; @@ -317,6 +320,7 @@ if ($_POST['save']) { if (!$input_errors) { write_config(); + ca_setup_trust_store(); pfSenseHeader("system_camanager.php"); } } @@ -575,6 +579,14 @@ $section->addInput(new Form_Input( $pconfig['descr'] )); +$section->addInput(new Form_Checkbox( + 'trust', + 'Trust Store', + 'Add this Certificate Authority to the Operating System Trust Store', + $pconfig['trust'] +))->setHelp('When enabled, the contents of the CA will be added to the trust ' . + 'store so that they will be trusted by the operating system.'); + if (!isset($id) || $act == "edit") { $section->addInput(new Form_Select( 'method',