diff --git a/security/pfSense-pkg-stunnel/Makefile b/security/pfSense-pkg-stunnel/Makefile index 13775420e11e..2cf4c5703ef7 100644 --- a/security/pfSense-pkg-stunnel/Makefile +++ b/security/pfSense-pkg-stunnel/Makefile @@ -32,8 +32,6 @@ do-install: ${STAGEDIR}${PREFIX}/pkg ${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/stunnel.inc \ ${STAGEDIR}${PREFIX}/pkg - ${INSTALL_DATA} -m 0644 ${FILESDIR}${PREFIX}/pkg/stunnel_certs.xml \ - ${STAGEDIR}${PREFIX}/pkg ${INSTALL_DATA} ${FILESDIR}/etc/inc/priv/stunnel.priv.inc \ ${STAGEDIR}/etc/inc/priv ${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/shortcuts/pkg_stunnel.inc \ @@ -42,7 +40,6 @@ do-install: ${STAGEDIR}${DATADIR} @${REINPLACE_CMD} -i '' -e "s|%%PKGVERSION%%|${PKGVERSION}|" \ ${STAGEDIR}${DATADIR}/info.xml \ - ${STAGEDIR}${PREFIX}/pkg/stunnel.xml \ - ${STAGEDIR}${PREFIX}/pkg/stunnel_certs.xml + ${STAGEDIR}${PREFIX}/pkg/stunnel.xml .include diff --git a/security/pfSense-pkg-stunnel/files/etc/inc/priv/stunnel.priv.inc b/security/pfSense-pkg-stunnel/files/etc/inc/priv/stunnel.priv.inc index 2a4f0905232d..906dc6032aaa 100644 --- a/security/pfSense-pkg-stunnel/files/etc/inc/priv/stunnel.priv.inc +++ b/security/pfSense-pkg-stunnel/files/etc/inc/priv/stunnel.priv.inc @@ -26,7 +26,6 @@ $priv_list['page-system-stunnel']['name'] = "WebCfg - System: stunnel package"; $priv_list['page-system-stunnel']['descr'] = "Allow access to stunnel package GUI"; $priv_list['page-system-stunnel']['match'] = array(); $priv_list['page-system-stunnel']['match'][] = "pkg_edit.php?xml=stunnel.xml*"; -$priv_list['page-system-stunnel']['match'][] = "pkg_edit.php?xml=stunnel_certs.xml*"; $priv_list['page-services-stunnel']['match'][] = "shortcuts/pkg_stunnel.inc*"; ?> diff --git a/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.inc b/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.inc index 1abcc9f89d83..f2e730bf8c01 100644 --- a/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.inc +++ b/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.inc @@ -22,115 +22,22 @@ require_once("config.inc"); require_once("util.inc"); require_once("pfsense-utils.inc"); +require_once("certs.inc"); global $config; define('STUNNEL_LOCALBASE', '/usr/local'); define('STUNNEL_ETCDIR', STUNNEL_LOCALBASE . "/etc/stunnel"); -if (!isset($_GET['id']) and !isset($_POST['id'])) { - if ($GLOBALS['config']['installedpackages']['stunnelcerts']['savemsg']) { - $savemsg = $GLOBALS['config']['installedpackages']['stunnelcerts']['savemsg']; - unset($GLOBALS['config']['installedpackages']['stunnelcerts']['savemsg']); - write_config(); - } -} -if (isset($_GET['id'])) { - $config['installedpackages']['stunnelcerts']['config'][$_GET['id']]['cert_chain'] = - base64_decode($config['installedpackages']['stunnelcerts']['config'][$_GET['id']]['cert_chain']); - $config['installedpackages']['stunnelcerts']['config'][$_GET['id']]['cert_key'] = - base64_decode($config['installedpackages']['stunnelcerts']['config'][$_GET['id']]['cert_key']); -} -$certs = $config['installedpackages']['stunnelcerts']['config']; -is_array($certs) ? $num_certs = count($certs) : $num_certs = 0; -if (!isset($_GET['id']) and !isset($_POST['id']) and $num_certs) { - for ($i = 0; $i < $num_certs; $i++) { - $cert = $certs[$i]; - $_info = openssl_x509_parse(base64_decode($cert['cert_chain'])); - $valid = floor(($_info['validTo_time_t'] - time()) / 86400); - if ($cert['cert_chain']) { - if (!openssl_x509_check_private_key(base64_decode($cert['cert_chain']), base64_decode($cert['cert_key']))) { - $_status = 'Invalid key/cert!'; - } elseif ($valid < 30) { - $_status = 'Expires in ' . $valid . ' days!'; - } else { - $_status = 'OK (' . $valid . ' days)'; - } - $config['installedpackages']['stunnelcerts']['config'][$i]['status'] = $_status; - } else { - unset($config['installedpackages']['stunnelcerts']['config'][$i]); - } - } -} + +// Initialize the list of tunnels. $tunnels = $config['installedpackages']['stunnel']['config']; is_array($tunnels) ? $num_tunnels = count($tunnels) : $num_tunnels = 0; if (!isset($_GET['id']) and $num_tunnels) { for ($i = 0; $i < $num_tunnels; $i++) { $tunnel = $tunnels[$i]; - if ($tunnel['certificate']) { - $certid = 0; - if (is_array($config['installedpackages']['stunnelcerts']['config'])) { - foreach ($config['installedpackages']['stunnelcerts']['config'] as $cert) { - if ($tunnel['certificate'] == $cert['filename']) { - $config['installedpackages']['stunnel']['config'][$i]['certificatelink']= - '' . $cert['description'] . ''; - } - $certid++; - } - } - } - } -} -function stunnel_printcsr() { -// $GLOBALS['savemsg'] = "
" . print_r($GLOBALS['config']['installedpackages']['stunnelcerts']['config'], true) . "
"; -} -function stunnel_addcerts($config) { - $certs=$config['installedpackages']['stunnelcerts']['config']; - $tunnels=$config['installedpackages']['stunnel']['config']; - ?> - - - - "; - } - if (!$_POST['cert_key']) { - $GLOBALS['config']['installedpackages']['stunnelcerts']['savemsg'] .= "RSA Key must be specified!
"; - } - if ($_POST['cert_chain'] and $_POST['cert_key']) { - $_cert = openssl_x509_parse($_POST['cert_chain']); - if ($_cert['hash']) { - if (openssl_x509_check_private_key($_POST['cert_chain'], $_POST['cert_key'])) { - file_put_contents(STUNNEL_ETCDIR . '/'. $_cert['hash'] . '.key', $_POST['cert_key']); - file_put_contents(STUNNEL_ETCDIR . '/' . $_cert['hash'] . '.chain', $_POST['cert_chain']); - file_put_contents(STUNNEL_ETCDIR . '/' . $_cert['hash'] . '.pem', $_POST['cert_key']."\n".$_POST['cert_chain']); - system('chown stunnel:stunnel ' . STUNNEL_ETCDIR . '/*'); - chmod(STUNNEL_ETCDIR . '/' . $_cert['hash'] . '.key', 0600); - chmod(STUNNEL_ETCDIR . '/' . $_cert['hash'] . '.pem', 0600); - $_POST['filename'] = $_cert['hash']; - $_POST['expiry_raw'] = $_cert['validTo_time_t']; - $_POST['expiry'] = date('Y-m-d', $_cert['validTo_time_t']); - $_POST['subject'] = $_cert['name']; - } else { - $GLOBALS['config']['installedpackages']['stunnelcerts']['savemsg'] .= "Certificate and key do not match!
"; - $_POST['filename'] = ''; - } - } else { - $GLOBALS['config']['installedpackages']['stunnelcerts']['savemsg'] .= "Couldn't parse certificate!
"; - $_POST['expiry_raw'] = ''; - $_POST['expiry'] = ''; - $_POST['subject'] = ''; - $_POST['filename'] = ''; - } - } - $_POST['cert_key'] = base64_encode($_POST['cert_key']); - $_POST['cert_chain'] = base64_encode($_POST['cert_chain']); - $_fname = $GLOBALS['config']['installedpackages']['stunnelcerts']['config'][$_POST['id']]['filename']; - if ($_fname and $_fname != $_POST['filename']) { - unlink_if_exists(STUNNEL_ETCDIR . '/' . $_fname . '.chain'); - unlink_if_exists(STUNNEL_ETCDIR . '/' . $_fname . '.key'); - unlink_if_exists(STUNNEL_ETCDIR . '/' . $_fname . '.pem'); - } - } -} + function stunnel_install() { safe_mkdir(STUNNEL_ETCDIR); - system("/usr/bin/openssl req -new -x509 -days 365 -nodes -out " . STUNNEL_ETCDIR . "/stunnel.pem -keyout " . STUNNEL_ETCDIR . "/stunnel.pem 2>/dev/null"); + + // Generate a self-signed default certificate. + $cert = array(); + $cert['refid'] = uniqid(); + $cert['descr'] = sprintf(gettext("stunnel default (%s)"), $cert['refid']); + + $dn = array( + 'countryName' => "US", + 'stateOrProvinceName' => "State", + 'localityName' => "Locality", + 'organizationName' => "{$g['product_name']} stunnel Self-Signed Certificate", + 'emailAddress' => "admin@{$config['system']['hostname']}.{$config['system']['domain']}", + 'commonName' => "{$config['system']['hostname']}-{$cert['refid']}"); + $old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warnings directly to a page screwing menu tab */ + if (!cert_create($cert, null, 2048, 365, $dn, "self-signed", "sha256")) { + while ($ssl_err = openssl_error_string()) { + log_error(sprintf(gettext("Error creating WebGUI Certificate: openssl library returns: %s"), $ssl_err)); + } + error_reporting($old_err_level); + return null; + } + error_reporting($old_err_level); + + // Write the .pem file to the expected default location for stunnel and set up required permissions. + file_put_contents(STUNNEL_ETCDIR . "/stunnel.pem", base64_decode($cert['prv']) . base64_decode($cert['crt'])); chmod(STUNNEL_ETCDIR . "/stunnel.pem", 0600); + @mkdir("/var/tmp/stunnel/var/tmp/run/stunnel", 0755, true); system("/usr/sbin/chown -R stunnel:stunnel /var/tmp/stunnel"); $_rcfile['file'] = 'stunnel.sh'; @@ -238,6 +142,7 @@ function stunnel_install() { } fclose($fout); } + function stunnel_deinstall() { rmdir_recursive("/var/tmp/stunnel"); rmdir_recursive(STUNNEL_ETCDIR); diff --git a/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.xml b/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.xml index 618fcdc2cab8..23cc43fcd5c8 100644 --- a/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.xml +++ b/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel.xml @@ -40,10 +40,6 @@ /pkg.php?xml=stunnel.xml - - Certificates - /pkg.php?xml=stunnel_certs.xml - stunnel @@ -104,11 +100,12 @@ Certificate certificate - Select server certificate to use for this tunnel. Certificates are defined on the 'Certificates' page. - select - - - + Select server certificate to use for this tunnel. + select_source + + descr + refid + default default @@ -133,13 +130,13 @@ stunnel_save($config); + + stunnel_save($config); + stunnel_install(); stunnel_deinstall(); - - stunnel_addcerts($config); - diff --git a/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel_certs.xml b/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel_certs.xml deleted file mode 100644 index 2f871afc0c21..000000000000 --- a/security/pfSense-pkg-stunnel/files/usr/local/pkg/stunnel_certs.xml +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - stunnelcerts - %%PKGVERSION%% - Services: Secure Tunnel - Certificates - /usr/local/pkg/stunnel.inc - - - Tunnels - /pkg.php?xml=stunnel.xml - - - Certificates - /pkg.php?xml=stunnel_certs.xml - - - - - - Description - description - - - Subject - subject - - - - Status - status - - - - - Description - description - Enter a (short) description for this certificate. - input - - - Certificate Filename - filename - File name of certificate (read-only; updated on save). Extensions (.pem, .chain, .key) are added automatically. - input - - - Certificate Subject - subject - Certificate subject (read-only; updated on save) - input - 50 - - - Certificate Valid Until - expiry - The certificate will expire on this date, and will no longer work. - input - - - RSA Private Key - cert_key - - - ]]> - - textarea - 7 - 70 - - - Certificate Chain - cert_chain - - - Full chain required for private or EV certificates! - ]]> - - textarea - 7 - 70 - - - - stunnel_save_cert($config); - stunnel_save($config); - - - stunnel_printcsr(); - - - stunnel_disablefields(); - - - stunnel_delete($config); - - diff --git a/security/pfSense-pkg-stunnel/pkg-plist b/security/pfSense-pkg-stunnel/pkg-plist index d4e4c113700c..a231781194d3 100644 --- a/security/pfSense-pkg-stunnel/pkg-plist +++ b/security/pfSense-pkg-stunnel/pkg-plist @@ -1,6 +1,5 @@ pkg/stunnel.xml pkg/stunnel.inc -pkg/stunnel_certs.xml www/shortcuts/pkg_stunnel.inc /etc/inc/priv/stunnel.priv.inc %%DATADIR%%/info.xml