Commit c88a4f7f authored by Franco Fichtner's avatar Franco Fichtner

certificates: use our own ssl config from now on for #280

Fixes LibreSSL shipping a not so usable openssl.cnf that gets picked
up by php-openssl for mostly random reasons.
parent b4011e9e
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
define("OPEN_SSL_CONF_PATH", "/etc/ssl/openssl.cnf");
global $openssl_digest_algs; global $openssl_digest_algs;
$openssl_digest_algs = array("sha1", "sha224", "sha256", "sha384", "sha512"); $openssl_digest_algs = array("sha1", "sha224", "sha256", "sha384", "sha512");
...@@ -128,15 +126,16 @@ function ca_chain(& $cert) { ...@@ -128,15 +126,16 @@ function ca_chain(& $cert) {
return ""; return "";
} }
function ca_create(&$ca, $keylen, $lifetime, $dn, $digest_alg = 'sha256')
function ca_create(& $ca, $keylen, $lifetime, $dn, $digest_alg = "sha256") { {
$args = array( $args = array(
"x509_extensions" => "v3_ca", 'config' => '/usr/local/etc/ssl/opnsense.cnf',
"digest_alg" => $digest_alg, 'private_key_type' => OPENSSL_KEYTYPE_RSA,
"private_key_bits" => (int)$keylen, 'private_key_bits' => (int)$keylen,
"private_key_type" => OPENSSL_KEYTYPE_RSA, 'x509_extensions' => 'v3_ca',
"encrypt_key" => false); 'digest_alg' => $digest_alg,
'encrypt_key' => false
);
// generate a new key pair // generate a new key pair
$res_key = openssl_pkey_new($args); $res_key = openssl_pkey_new($args);
...@@ -181,33 +180,38 @@ function cert_import(& $cert, $crt_str, $key_str) { ...@@ -181,33 +180,38 @@ function cert_import(& $cert, $crt_str, $key_str) {
return true; return true;
} }
function cert_create(& $cert, $caref, $keylen, $lifetime, $dn, $digest_alg = "sha256") { function cert_create(&$cert, $caref, $keylen, $lifetime, $dn, $digest_alg = 'sha256')
{
$ca =& lookup_ca($caref); $ca = &lookup_ca($caref);
if (!$ca) if (!$ca) {
return false; return false;
}
$ca_str_crt = base64_decode($ca['crt']); $ca_str_crt = base64_decode($ca['crt']);
$ca_str_key = base64_decode($ca['prv']); $ca_str_key = base64_decode($ca['prv']);
$ca_res_crt = openssl_x509_read($ca_str_crt); $ca_res_crt = openssl_x509_read($ca_str_crt);
$ca_res_key = openssl_pkey_get_private(array(0 => $ca_str_key, 1 => "")); $ca_res_key = openssl_pkey_get_private(array(0 => $ca_str_key, 1 => ""));
if(!$ca_res_key) return false; if (!$ca_res_key) {
return false;
}
$ca_serial = ++$ca['serial']; $ca_serial = ++$ca['serial'];
// in case of using Subject Alternative Names use other sections (with postfix '_san') /* subjectAltName can be set _only_ via configuration file */
// pass subjectAltName over environment variable 'SAN'
if ($dn['subjectAltName']) { if ($dn['subjectAltName']) {
putenv("SAN={$dn['subjectAltName']}"); // subjectAltName can be set _only_ via configuration file /* TODO: currently disabled */
putenv("SAN={$dn['subjectAltName']}");
$cert_type .= '_san'; $cert_type .= '_san';
unset($dn['subjectAltName']); unset($dn['subjectAltName']);
} }
$args = array( $args = array(
"x509_extensions" => "usr_cert", 'config' => '/usr/local/etc/ssl/opnsense.cnf',
"digest_alg" => $digest_alg, 'private_key_type' => OPENSSL_KEYTYPE_RSA,
"private_key_bits" => (int)$keylen, 'private_key_bits' => (int)$keylen,
"private_key_type" => OPENSSL_KEYTYPE_RSA, 'x509_extensions' => 'usr_cert',
"encrypt_key" => false); 'digest_alg' => $digest_alg,
'encrypt_key' => false
);
// generate a new key pair // generate a new key pair
$res_key = openssl_pkey_new($args); $res_key = openssl_pkey_new($args);
......
...@@ -90,13 +90,6 @@ if [ ! -f /conf/config.xml ]; then ...@@ -90,13 +90,6 @@ if [ ! -f /conf/config.xml ]; then
echo "done." echo "done."
fi fi
# Bootstrap openssl.cnf for port if necessary
if [ ! -f /usr/local/openssl/openssl.cnf ]; then
echo -n "Bootstrapping openssl.cnf..."
cp /etc/ssl/openssl.cnf /usr/local/openssl/openssl.cnf
echo "done."
fi
# Disable APM on ATA drives. Leaving this on will kill # Disable APM on ATA drives. Leaving this on will kill
# drives long-term, especially laptop drives, by generating # drives long-term, especially laptop drives, by generating
# excessive load cycles. # excessive load cycles.
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment