|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* _ _
|
|
Packit |
90a5c9 |
* _ __ ___ ___ __| | ___ ___| | mod_ssl
|
|
Packit |
90a5c9 |
* | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
|
|
Packit |
90a5c9 |
* | | | | | | (_) | (_| | \__ \__ \ |
|
|
Packit |
90a5c9 |
* |_| |_| |_|\___/ \__,_|___|___/___/_|
|
|
Packit |
90a5c9 |
* |_____|
|
|
Packit |
90a5c9 |
* ssl_engine_init.c
|
|
Packit |
90a5c9 |
* Initialization of Servers
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
/* ``Recursive, adj.;
|
|
Packit |
90a5c9 |
see Recursive.''
|
|
Packit |
90a5c9 |
-- Unknown */
|
|
Packit |
90a5c9 |
#include "ssl_private.h"
|
|
Packit |
90a5c9 |
#include "mod_ssl.h"
|
|
Packit |
90a5c9 |
#include "mod_ssl_openssl.h"
|
|
Packit |
90a5c9 |
#include "mpm_common.h"
|
|
Packit |
90a5c9 |
#include "mod_md.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ssl, SSL, int, init_server,
|
|
Packit |
90a5c9 |
(server_rec *s,apr_pool_t *p,int is_proxy,SSL_CTX *ctx),
|
|
Packit |
90a5c9 |
(s,p,is_proxy,ctx), OK, DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
20f7c8 |
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ssl, SSL, int, add_cert_files,
|
|
Packit |
20f7c8 |
(server_rec *s, apr_pool_t *p,
|
|
Packit |
20f7c8 |
apr_array_header_t *cert_files, apr_array_header_t *key_files),
|
|
Packit |
20f7c8 |
(s, p, cert_files, key_files),
|
|
Packit |
20f7c8 |
OK, DECLINED)
|
|
Packit |
20f7c8 |
|
|
Packit |
20f7c8 |
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ssl, SSL, int, add_fallback_cert_files,
|
|
Packit |
20f7c8 |
(server_rec *s, apr_pool_t *p,
|
|
Packit |
20f7c8 |
apr_array_header_t *cert_files, apr_array_header_t *key_files),
|
|
Packit |
20f7c8 |
(s, p, cert_files, key_files),
|
|
Packit |
20f7c8 |
OK, DECLINED)
|
|
Packit |
20f7c8 |
|
|
Packit |
20f7c8 |
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ssl, SSL, int, answer_challenge,
|
|
Packit |
20f7c8 |
(conn_rec *c, const char *server_name,
|
|
Packit |
20f7c8 |
X509 **pcert, EVP_PKEY **pkey),
|
|
Packit |
20f7c8 |
(c, server_name, pcert, pkey),
|
|
Packit |
20f7c8 |
DECLINED, DECLINED)
|
|
Packit |
20f7c8 |
|
|
Packit |
20f7c8 |
|
|
Packit |
90a5c9 |
/* _________________________________________________________________
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
** Module Initialization
|
|
Packit |
90a5c9 |
** _________________________________________________________________
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_ECC
|
|
Packit |
90a5c9 |
#define KEYTYPES "RSA, DSA or ECC"
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define KEYTYPES "RSA or DSA"
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if MODSSL_USE_OPENSSL_PRE_1_1_API
|
|
Packit |
90a5c9 |
/* OpenSSL Pre-1.1.0 compatibility */
|
|
Packit |
90a5c9 |
/* Taken from OpenSSL 1.1.0 snapshot 20160410 */
|
|
Packit |
90a5c9 |
static int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* q is optional */
|
|
Packit |
90a5c9 |
if (p == NULL || g == NULL)
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
BN_free(dh->p);
|
|
Packit |
90a5c9 |
BN_free(dh->q);
|
|
Packit |
90a5c9 |
BN_free(dh->g);
|
|
Packit |
90a5c9 |
dh->p = p;
|
|
Packit |
90a5c9 |
dh->q = q;
|
|
Packit |
90a5c9 |
dh->g = g;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (q != NULL) {
|
|
Packit |
90a5c9 |
dh->length = BN_num_bits(q);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Grab well-defined DH parameters from OpenSSL, see the BN_get_rfc*
|
|
Packit |
90a5c9 |
* functions in <openssl/bn.h> for all available primes.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static DH *make_dh_params(BIGNUM *(*prime)(BIGNUM *))
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
DH *dh = DH_new();
|
|
Packit |
90a5c9 |
BIGNUM *p, *g;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!dh) {
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
p = prime(NULL);
|
|
Packit |
90a5c9 |
g = BN_new();
|
|
Packit |
90a5c9 |
if (g != NULL) {
|
|
Packit |
90a5c9 |
BN_set_word(g, 2);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!p || !g || !DH_set0_pqg(dh, p, NULL, g)) {
|
|
Packit |
90a5c9 |
DH_free(dh);
|
|
Packit |
90a5c9 |
BN_free(p);
|
|
Packit |
90a5c9 |
BN_free(g);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return dh;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Storage and initialization for DH parameters. */
|
|
Packit |
90a5c9 |
static struct dhparam {
|
|
Packit |
90a5c9 |
BIGNUM *(*const prime)(BIGNUM *); /* function to generate... */
|
|
Packit |
90a5c9 |
DH *dh; /* ...this, used for keys.... */
|
|
Packit |
90a5c9 |
const unsigned int min; /* ...of length >= this. */
|
|
Packit |
90a5c9 |
} dhparams[] = {
|
|
Packit |
90a5c9 |
{ BN_get_rfc3526_prime_8192, NULL, 6145 },
|
|
Packit |
90a5c9 |
{ BN_get_rfc3526_prime_6144, NULL, 4097 },
|
|
Packit |
90a5c9 |
{ BN_get_rfc3526_prime_4096, NULL, 3073 },
|
|
Packit |
90a5c9 |
{ BN_get_rfc3526_prime_3072, NULL, 2049 },
|
|
Packit |
90a5c9 |
{ BN_get_rfc3526_prime_2048, NULL, 1025 },
|
|
Packit |
90a5c9 |
{ BN_get_rfc2409_prime_1024, NULL, 0 }
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void init_dh_params(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
unsigned n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (n = 0; n < sizeof(dhparams)/sizeof(dhparams[0]); n++)
|
|
Packit |
90a5c9 |
dhparams[n].dh = make_dh_params(dhparams[n].prime);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void free_dh_params(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
unsigned n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* DH_free() is a noop for a NULL parameter, so these are harmless
|
|
Packit |
90a5c9 |
* in the (unexpected) case where these variables are already
|
|
Packit |
90a5c9 |
* NULL. */
|
|
Packit |
90a5c9 |
for (n = 0; n < sizeof(dhparams)/sizeof(dhparams[0]); n++) {
|
|
Packit |
90a5c9 |
DH_free(dhparams[n].dh);
|
|
Packit |
90a5c9 |
dhparams[n].dh = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Hand out the same DH structure though once generated as we leak
|
|
Packit |
90a5c9 |
* memory otherwise and freeing the structure up after use would be
|
|
Packit |
90a5c9 |
* hard to track and in fact is not needed at all as it is safe to
|
|
Packit |
90a5c9 |
* use the same parameters over and over again security wise (in
|
|
Packit |
90a5c9 |
* contrast to the keys itself) and code safe as the returned structure
|
|
Packit |
90a5c9 |
* is duplicated by OpenSSL anyway. Hence no modification happens
|
|
Packit |
90a5c9 |
* to our copy. */
|
|
Packit |
90a5c9 |
DH *modssl_get_dh_params(unsigned keylen)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
unsigned n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (n = 0; n < sizeof(dhparams)/sizeof(dhparams[0]); n++)
|
|
Packit |
90a5c9 |
if (keylen >= dhparams[n].min)
|
|
Packit |
90a5c9 |
return dhparams[n].dh;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL; /* impossible to reach. */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_add_version_components(apr_pool_t *p,
|
|
Packit |
90a5c9 |
server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *modver = ssl_var_lookup(p, s, NULL, NULL, "SSL_VERSION_INTERFACE");
|
|
Packit |
90a5c9 |
char *libver = ssl_var_lookup(p, s, NULL, NULL, "SSL_VERSION_LIBRARY");
|
|
Packit |
90a5c9 |
char *incver = ssl_var_lookup(p, s, NULL, NULL,
|
|
Packit |
90a5c9 |
"SSL_VERSION_LIBRARY_INTERFACE");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_add_version_component(p, libver);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(01876)
|
|
Packit |
90a5c9 |
"%s compiled against Server: %s, Library: %s",
|
|
Packit |
90a5c9 |
modver, AP_SERVER_BASEVERSION, incver);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
20f7c8 |
/* _________________________________________________________________
|
|
Packit |
20f7c8 |
**
|
|
Packit |
20f7c8 |
** Let other answer special connection attempts.
|
|
Packit |
20f7c8 |
** Used in ACME challenge handling by mod_md.
|
|
Packit |
20f7c8 |
** _________________________________________________________________
|
|
Packit |
20f7c8 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int ssl_is_challenge(conn_rec *c, const char *servername,
|
|
Packit |
90a5c9 |
X509 **pcert, EVP_PKEY **pkey)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
20f7c8 |
if (APR_SUCCESS == ssl_run_answer_challenge(c, servername, pcert, pkey)) {
|
|
Packit |
20f7c8 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
*pcert = NULL;
|
|
Packit |
90a5c9 |
*pkey = NULL;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
60cf86 |
#ifdef HAVE_FIPS
|
|
Packit |
60cf86 |
static apr_status_t ssl_fips_cleanup(void *data)
|
|
Packit |
60cf86 |
{
|
|
Packit |
60cf86 |
FIPS_mode_set(0);
|
|
Packit |
60cf86 |
return APR_SUCCESS;
|
|
Packit |
60cf86 |
}
|
|
Packit |
60cf86 |
#endif
|
|
Packit |
60cf86 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Per-module initialization
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t ssl_init_Module(apr_pool_t *p, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
server_rec *base_server)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSLModConfigRec *mc = myModConfig(base_server);
|
|
Packit |
90a5c9 |
SSLSrvConfigRec *sc;
|
|
Packit |
90a5c9 |
server_rec *s;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
apr_array_header_t *pphrases;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (SSLeay() < MODSSL_LIBRARY_VERSION) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, base_server, APLOGNO(01882)
|
|
Packit |
90a5c9 |
"Init: this version of mod_ssl was compiled against "
|
|
Packit |
90a5c9 |
"a newer library (%s, version currently loaded is %s)"
|
|
Packit |
90a5c9 |
" - may result in undefined or erroneous behavior",
|
|
Packit |
90a5c9 |
MODSSL_LIBRARY_TEXT, MODSSL_LIBRARY_DYNTEXT);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* We initialize mc->pid per-process in the child init,
|
|
Packit |
90a5c9 |
* but it should be initialized for startup before we
|
|
Packit |
90a5c9 |
* call ssl_rand_seed() below.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
mc->pid = getpid();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Let us cleanup on restarts and exits
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(p, base_server,
|
|
Packit |
90a5c9 |
ssl_init_ModuleKill,
|
|
Packit |
90a5c9 |
apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Any init round fixes the global config
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ssl_config_global_create(base_server); /* just to avoid problems */
|
|
Packit |
90a5c9 |
ssl_config_global_fix(mc);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* try to fix the configuration and open the dedicated SSL
|
|
Packit |
90a5c9 |
* logfile as early as possible
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (s = base_server; s; s = s->next) {
|
|
Packit |
90a5c9 |
sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sc->server) {
|
|
Packit |
90a5c9 |
sc->server->sc = sc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Create the server host:port string because we need it a lot
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (sc->vhost_id) {
|
|
Packit |
90a5c9 |
/* already set. This should only happen if this config rec is
|
|
Packit |
90a5c9 |
* shared with another server. Argh! */
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(10104)
|
|
Packit |
90a5c9 |
"%s, SSLSrvConfigRec shared from %s",
|
|
Packit |
90a5c9 |
ssl_util_vhostid(p, s), sc->vhost_id);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
sc->vhost_id = ssl_util_vhostid(p, s);
|
|
Packit |
90a5c9 |
sc->vhost_id_len = strlen(sc->vhost_id);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Default to enabled if SSLEngine is not set explicitly, and
|
|
Packit |
90a5c9 |
* the protocol is https. */
|
|
Packit |
90a5c9 |
if (ap_get_server_protocol(s)
|
|
Packit |
90a5c9 |
&& strcmp("https", ap_get_server_protocol(s)) == 0
|
|
Packit |
90a5c9 |
&& sc->enabled == SSL_ENABLED_UNSET
|
|
Packit |
90a5c9 |
&& (!apr_is_empty_array(sc->server->pks->cert_files))) {
|
|
Packit |
90a5c9 |
sc->enabled = SSL_ENABLED_TRUE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Fix up stuff that may not have been set. If sc->enabled is
|
|
Packit |
90a5c9 |
* UNSET, then SSL is disabled on this vhost. */
|
|
Packit |
90a5c9 |
if (sc->enabled == SSL_ENABLED_UNSET) {
|
|
Packit |
90a5c9 |
sc->enabled = SSL_ENABLED_FALSE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sc->session_cache_timeout == UNSET) {
|
|
Packit |
90a5c9 |
sc->session_cache_timeout = SSL_SESSION_CACHE_TIMEOUT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sc->server && sc->server->pphrase_dialog_type == SSL_PPTYPE_UNSET) {
|
|
Packit |
90a5c9 |
sc->server->pphrase_dialog_type = SSL_PPTYPE_BUILTIN;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_FIPS
|
|
Packit |
90a5c9 |
if (sc->fips == UNSET) {
|
|
Packit |
90a5c9 |
sc->fips = FALSE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if APR_HAS_THREADS && MODSSL_USE_OPENSSL_PRE_1_1_API
|
|
Packit |
90a5c9 |
ssl_util_thread_setup(p);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* SSL external crypto device ("engine") support
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_Engine(base_server, p)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(01883)
|
|
Packit |
90a5c9 |
"Init: Initialized %s library", MODSSL_LIBRARY_NAME);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Seed the Pseudo Random Number Generator (PRNG)
|
|
Packit |
90a5c9 |
* only need ptemp here; nothing inside allocated from the pool
|
|
Packit |
90a5c9 |
* needs to live once we return from ssl_rand_seed().
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ssl_rand_seed(base_server, ptemp, SSL_RSCTX_STARTUP, "Init: ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_FIPS
|
|
Packit |
90a5c9 |
if(sc->fips) {
|
|
Packit |
90a5c9 |
if (!FIPS_mode()) {
|
|
Packit |
90a5c9 |
if (FIPS_mode_set(1)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(01884)
|
|
Packit |
90a5c9 |
"Operating in SSL FIPS mode");
|
|
Packit |
60cf86 |
apr_pool_cleanup_register(p, NULL, ssl_fips_cleanup,
|
|
Packit |
60cf86 |
apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01885) "FIPS mode failed");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01886)
|
|
Packit |
90a5c9 |
"SSL FIPS mode disabled");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* initialize the mutex handling
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!ssl_mutex_init(base_server, p)) {
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#ifdef HAVE_OCSP_STAPLING
|
|
Packit |
90a5c9 |
ssl_stapling_certinfo_hash_init(p);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* initialize session caching
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((rv = ssl_scache_init(base_server, p)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
pphrases = apr_array_make(ptemp, 2, sizeof(char *));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* initialize servers
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, base_server, APLOGNO(01887)
|
|
Packit |
90a5c9 |
"Init: Initializing (virtual) servers for SSL");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (s = base_server; s; s = s->next) {
|
|
Packit |
90a5c9 |
sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Either now skip this server when SSL is disabled for
|
|
Packit |
90a5c9 |
* it or give out some information about what we're
|
|
Packit |
90a5c9 |
* configuring.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Read the server certificate and key
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ConfigureServer(s, p, ptemp, sc, pphrases))
|
|
Packit |
90a5c9 |
!= APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pphrases->nelts > 0) {
|
|
Packit |
90a5c9 |
memset(pphrases->elts, 0, pphrases->elt_size * pphrases->nelts);
|
|
Packit |
90a5c9 |
pphrases->nelts = 0;
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(02560)
|
|
Packit |
90a5c9 |
"Init: Wiped out the queried pass phrases from memory");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configuration consistency checks
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_CheckServers(base_server, ptemp)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (s = base_server; s; s = s->next) {
|
|
Packit |
90a5c9 |
SSLDirConfigRec *sdc = ap_get_module_config(s->lookup_defaults,
|
|
Packit |
90a5c9 |
&ssl_module);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
if (sc->enabled == SSL_ENABLED_TRUE || sc->enabled == SSL_ENABLED_OPTIONAL) {
|
|
Packit |
90a5c9 |
if ((rv = ssl_run_init_server(s, p, 0, sc->server->ssl_ctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sdc->proxy_enabled) {
|
|
Packit |
90a5c9 |
rv = ssl_run_init_server(s, p, 1, sdc->proxy->ssl_ctx);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Announce mod_ssl and SSL library in HTTP Server field
|
|
Packit |
90a5c9 |
* as ``mod_ssl/X.X.X OpenSSL/X.X.X''
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ssl_add_version_components(p, base_server);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
modssl_init_app_data2_idx(); /* for modssl_get_app_data2() at request time */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
init_dh_params();
|
|
Packit |
90a5c9 |
#if !MODSSL_USE_OPENSSL_PRE_1_1_API
|
|
Packit |
90a5c9 |
init_bio_methods();
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
003d89 |
#ifdef HAVE_OPENSSL_KEYLOG
|
|
Packit |
003d89 |
{
|
|
Packit |
003d89 |
const char *logfn = getenv("SSLKEYLOGFILE");
|
|
Packit |
003d89 |
|
|
Packit |
003d89 |
if (logfn) {
|
|
Packit |
003d89 |
rv = apr_file_open(&mc->keylog_file, logfn,
|
|
Packit |
003d89 |
APR_FOPEN_CREATE|APR_FOPEN_WRITE|APR_FOPEN_APPEND|APR_FOPEN_LARGEFILE,
|
|
Packit |
003d89 |
APR_FPROT_UREAD|APR_FPROT_UWRITE,
|
|
Packit |
003d89 |
mc->pPool);
|
|
Packit |
003d89 |
if (rv) {
|
|
Packit |
003d89 |
ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, s, APLOGNO(10226)
|
|
Packit |
003d89 |
"Could not open log file '%s' configured via SSLKEYLOGFILE",
|
|
Packit |
003d89 |
logfn);
|
|
Packit |
003d89 |
return rv;
|
|
Packit |
003d89 |
}
|
|
Packit |
003d89 |
|
|
Packit |
003d89 |
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(10227)
|
|
Packit |
003d89 |
"Init: Logging SSL private key material to %s", logfn);
|
|
Packit |
003d89 |
}
|
|
Packit |
003d89 |
}
|
|
Packit |
003d89 |
#endif
|
|
Packit |
003d89 |
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Support for external a Crypto Device ("engine"), usually
|
|
Packit |
90a5c9 |
* a hardware accellerator card for crypto operations.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
|
|
Packit |
90a5c9 |
apr_status_t ssl_init_Engine(server_rec *s, apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSLModConfigRec *mc = myModConfig(s);
|
|
Packit |
90a5c9 |
ENGINE *e;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mc->szCryptoDevice) {
|
|
Packit |
90a5c9 |
if (!(e = ENGINE_by_id(mc->szCryptoDevice))) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01888)
|
|
Packit |
90a5c9 |
"Init: Failed to load Crypto Device API `%s'",
|
|
Packit |
90a5c9 |
mc->szCryptoDevice);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef ENGINE_CTRL_CHIL_SET_FORKCHECK
|
|
Packit |
90a5c9 |
if (strEQ(mc->szCryptoDevice, "chil")) {
|
|
Packit |
90a5c9 |
ENGINE_ctrl(e, ENGINE_CTRL_CHIL_SET_FORKCHECK, 1, 0, 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01889)
|
|
Packit |
90a5c9 |
"Init: Failed to enable Crypto Device API `%s'",
|
|
Packit |
90a5c9 |
mc->szCryptoDevice);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(01890)
|
|
Packit |
90a5c9 |
"Init: loaded Crypto Device API `%s'",
|
|
Packit |
90a5c9 |
mc->szCryptoDevice);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ENGINE_free(e);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ctx_tls_extensions(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure TLS extensions support
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01893)
|
|
Packit |
90a5c9 |
"Configuring TLS extension handling");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Server name indication (SNI)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!SSL_CTX_set_tlsext_servername_callback(mctx->ssl_ctx,
|
|
Packit |
90a5c9 |
ssl_callback_ServerNameIndication) ||
|
|
Packit |
90a5c9 |
!SSL_CTX_set_tlsext_servername_arg(mctx->ssl_ctx, mctx)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01894)
|
|
Packit |
90a5c9 |
"Unable to initialize TLS servername extension "
|
|
Packit |
90a5c9 |
"callback (incompatible OpenSSL version?)");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_OCSP_STAPLING
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* OCSP Stapling support, status_request extension
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((mctx->pkp == FALSE) && (mctx->stapling_enabled == TRUE)) {
|
|
Packit |
90a5c9 |
if ((rv = modssl_init_stapling(s, p, ptemp, mctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_SRP
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* TLS-SRP support
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (mctx->srp_vfile != NULL) {
|
|
Packit |
90a5c9 |
int err;
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02308)
|
|
Packit |
90a5c9 |
"Using SRP verifier file [%s]", mctx->srp_vfile);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(mctx->srp_vbase = SRP_VBASE_new(mctx->srp_unknown_user_seed))) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02309)
|
|
Packit |
90a5c9 |
"Unable to initialize SRP verifier structure "
|
|
Packit |
90a5c9 |
"[%s seed]",
|
|
Packit |
90a5c9 |
mctx->srp_unknown_user_seed ? "with" : "without");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
err = SRP_VBASE_init(mctx->srp_vbase, mctx->srp_vfile);
|
|
Packit |
90a5c9 |
if (err != SRP_NO_ERROR) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02310)
|
|
Packit |
90a5c9 |
"Unable to load SRP verifier file [error %d]", err);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_srp_username_callback(mctx->ssl_ctx,
|
|
Packit |
90a5c9 |
ssl_callback_SRPServerParams);
|
|
Packit |
90a5c9 |
SSL_CTX_set_srp_cb_arg(mctx->ssl_ctx, mctx);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ctx_protocol(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSL_CTX *ctx = NULL;
|
|
Packit |
90a5c9 |
MODSSL_SSL_METHOD_CONST SSL_METHOD *method = NULL;
|
|
Packit |
90a5c9 |
char *cp;
|
|
Packit |
90a5c9 |
int protocol = mctx->protocol;
|
|
Packit |
418b31 |
int protocol_set = mctx->protocol_set;
|
|
Packit |
90a5c9 |
SSLSrvConfigRec *sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
Packit |
90a5c9 |
int prot;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Create the new per-server SSL context
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (protocol == SSL_PROTOCOL_NONE) {
|
|
Packit |
418b31 |
if (protocol_set) {
|
|
Packit |
418b31 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02231)
|
|
Packit |
418b31 |
"No SSL protocols available [hint: SSLProtocol]");
|
|
Packit |
418b31 |
return ssl_die(s);
|
|
Packit |
418b31 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
418b31 |
ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s,
|
|
Packit |
418b31 |
"Using OpenSSL/system default SSL/TLS protocols");
|
|
Packit |
418b31 |
cp = "default";
|
|
Packit |
418b31 |
}
|
|
Packit |
418b31 |
else {
|
|
Packit |
418b31 |
cp = apr_pstrcat(p,
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
(protocol & SSL_PROTOCOL_SSLV3 ? "SSLv3, " : ""),
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
(protocol & SSL_PROTOCOL_TLSV1 ? "TLSv1, " : ""),
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSV1_X
|
|
Packit |
90a5c9 |
(protocol & SSL_PROTOCOL_TLSV1_1 ? "TLSv1.1, " : ""),
|
|
Packit |
90a5c9 |
(protocol & SSL_PROTOCOL_TLSV1_2 ? "TLSv1.2, " : ""),
|
|
Packit |
90a5c9 |
#if SSL_HAVE_PROTOCOL_TLSV1_3
|
|
Packit |
90a5c9 |
(protocol & SSL_PROTOCOL_TLSV1_3 ? "TLSv1.3, " : ""),
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
418b31 |
cp[strlen(cp)-2] = NUL;
|
|
Packit |
418b31 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s,
|
|
Packit |
90a5c9 |
"Creating new SSL context (protocols: %s)", cp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
if (protocol == SSL_PROTOCOL_SSLV3) {
|
|
Packit |
90a5c9 |
method = mctx->pkp ?
|
|
Packit |
90a5c9 |
SSLv3_client_method() : /* proxy */
|
|
Packit |
90a5c9 |
SSLv3_server_method(); /* server */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
if (protocol == SSL_PROTOCOL_TLSV1) {
|
|
Packit |
90a5c9 |
method = mctx->pkp ?
|
|
Packit |
90a5c9 |
TLSv1_client_method() : /* proxy */
|
|
Packit |
90a5c9 |
TLSv1_server_method(); /* server */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSV1_X
|
|
Packit |
90a5c9 |
else if (protocol == SSL_PROTOCOL_TLSV1_1) {
|
|
Packit |
90a5c9 |
method = mctx->pkp ?
|
|
Packit |
90a5c9 |
TLSv1_1_client_method() : /* proxy */
|
|
Packit |
90a5c9 |
TLSv1_1_server_method(); /* server */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (protocol == SSL_PROTOCOL_TLSV1_2) {
|
|
Packit |
90a5c9 |
method = mctx->pkp ?
|
|
Packit |
90a5c9 |
TLSv1_2_client_method() : /* proxy */
|
|
Packit |
90a5c9 |
TLSv1_2_server_method(); /* server */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#if SSL_HAVE_PROTOCOL_TLSV1_3
|
|
Packit |
90a5c9 |
else if (protocol == SSL_PROTOCOL_TLSV1_3) {
|
|
Packit |
90a5c9 |
method = mctx->pkp ?
|
|
Packit |
90a5c9 |
TLSv1_3_client_method() : /* proxy */
|
|
Packit |
90a5c9 |
TLSv1_3_server_method(); /* server */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
else { /* For multiple protocols, we need a flexible method */
|
|
Packit |
90a5c9 |
method = mctx->pkp ?
|
|
Packit |
90a5c9 |
SSLv23_client_method() : /* proxy */
|
|
Packit |
90a5c9 |
SSLv23_server_method(); /* server */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
method = mctx->pkp ?
|
|
Packit |
90a5c9 |
TLS_client_method() : /* proxy */
|
|
Packit |
90a5c9 |
TLS_server_method(); /* server */
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
ctx = SSL_CTX_new(method);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
mctx->ssl_ctx = ctx;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_ALL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
|
|
Packit |
90a5c9 |
(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20800000L)
|
|
Packit |
90a5c9 |
/* always disable SSLv2, as per RFC 6176 */
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
if (!(protocol & SSL_PROTOCOL_SSLV3)) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv3);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(protocol & SSL_PROTOCOL_TLSV1)) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSV1_X
|
|
Packit |
90a5c9 |
if (!(protocol & SSL_PROTOCOL_TLSV1_1)) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(protocol & SSL_PROTOCOL_TLSV1_2)) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_2);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#if SSL_HAVE_PROTOCOL_TLSV1_3
|
|
Packit |
90a5c9 |
ssl_set_ctx_protocol_option(s, ctx, SSL_OP_NO_TLSv1_3,
|
|
Packit |
90a5c9 |
protocol & SSL_PROTOCOL_TLSV1_3, "TLSv1.3");
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#else /* #if OPENSSL_VERSION_NUMBER < 0x10100000L */
|
|
Packit |
90a5c9 |
/* We first determine the maximum protocol version we should provide */
|
|
Packit |
90a5c9 |
#if SSL_HAVE_PROTOCOL_TLSV1_3
|
|
Packit |
90a5c9 |
if (SSL_HAVE_PROTOCOL_TLSV1_3 && (protocol & SSL_PROTOCOL_TLSV1_3)) {
|
|
Packit |
90a5c9 |
prot = TLS1_3_VERSION;
|
|
Packit |
90a5c9 |
} else
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
if (protocol & SSL_PROTOCOL_TLSV1_2) {
|
|
Packit |
90a5c9 |
prot = TLS1_2_VERSION;
|
|
Packit |
90a5c9 |
} else if (protocol & SSL_PROTOCOL_TLSV1_1) {
|
|
Packit |
90a5c9 |
prot = TLS1_1_VERSION;
|
|
Packit |
90a5c9 |
} else if (protocol & SSL_PROTOCOL_TLSV1) {
|
|
Packit |
90a5c9 |
prot = TLS1_VERSION;
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
} else if (protocol & SSL_PROTOCOL_SSLV3) {
|
|
Packit |
90a5c9 |
prot = SSL3_VERSION;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
418b31 |
if (protocol_set) {
|
|
Packit |
418b31 |
SSL_CTX_free(ctx);
|
|
Packit |
418b31 |
mctx->ssl_ctx = NULL;
|
|
Packit |
418b31 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(03378)
|
|
Packit |
418b31 |
"No SSL protocols available [hint: SSLProtocol]");
|
|
Packit |
418b31 |
return ssl_die(s);
|
|
Packit |
418b31 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
418b31 |
if (protocol != SSL_PROTOCOL_NONE) SSL_CTX_set_max_proto_version(ctx, prot);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Next we scan for the minimal protocol version we should provide,
|
|
Packit |
90a5c9 |
* but we do not allow holes between max and min */
|
|
Packit |
90a5c9 |
#if SSL_HAVE_PROTOCOL_TLSV1_3
|
|
Packit |
90a5c9 |
if (prot == TLS1_3_VERSION && protocol & SSL_PROTOCOL_TLSV1_2) {
|
|
Packit |
90a5c9 |
prot = TLS1_2_VERSION;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
if (prot == TLS1_2_VERSION && protocol & SSL_PROTOCOL_TLSV1_1) {
|
|
Packit |
90a5c9 |
prot = TLS1_1_VERSION;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (prot == TLS1_1_VERSION && protocol & SSL_PROTOCOL_TLSV1) {
|
|
Packit |
90a5c9 |
prot = TLS1_VERSION;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
if (prot == TLS1_VERSION && protocol & SSL_PROTOCOL_SSLV3) {
|
|
Packit |
90a5c9 |
prot = SSL3_VERSION;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
418b31 |
if (protocol != SSL_PROTOCOL_NONE) SSL_CTX_set_min_proto_version(ctx, prot);
|
|
Packit |
90a5c9 |
#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
|
|
Packit |
90a5c9 |
if (sc->cipher_server_pref == TRUE) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_COMP
|
|
Packit |
90a5c9 |
if (sc->compression != TRUE) {
|
|
Packit |
90a5c9 |
#ifdef SSL_OP_NO_COMPRESSION
|
|
Packit |
90a5c9 |
/* OpenSSL >= 1.0 only */
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_COMPRESSION);
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
sk_SSL_COMP_zero(SSL_COMP_get_compression_methods());
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef SSL_OP_NO_TICKET
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure using RFC 5077 TLS session tickets
|
|
Packit |
90a5c9 |
* for session resumption.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (sc->session_tickets == FALSE) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
|
|
Packit |
90a5c9 |
if (sc->insecure_reneg == TRUE) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_app_data(ctx, s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure additional context ingredients
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE);
|
|
Packit |
90a5c9 |
#ifdef HAVE_ECC
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_ECDH_USE);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Disallow a session from being resumed during a renegotiation,
|
|
Packit |
90a5c9 |
* so that an acceptable cipher suite can be negotiated.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef SSL_MODE_RELEASE_BUFFERS
|
|
Packit |
90a5c9 |
/* If httpd is configured to reduce mem usage, ask openssl to do so, too */
|
|
Packit |
90a5c9 |
if (ap_max_mem_free != APR_ALLOCATOR_MAX_FREE_UNLIMITED)
|
|
Packit |
90a5c9 |
SSL_CTX_set_mode(ctx, SSL_MODE_RELEASE_BUFFERS);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
|
|
Packit |
90a5c9 |
/* For OpenSSL >=1.1.1, disable auto-retry mode so it's possible
|
|
Packit |
90a5c9 |
* to consume handshake records without blocking for app-data.
|
|
Packit |
90a5c9 |
* https://github.com/openssl/openssl/issues/7178 */
|
|
Packit |
90a5c9 |
SSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
003d89 |
|
|
Packit |
003d89 |
#ifdef HAVE_OPENSSL_KEYLOG
|
|
Packit |
003d89 |
if (mctx->sc->mc->keylog_file) {
|
|
Packit |
003d89 |
SSL_CTX_set_keylog_callback(ctx, modssl_callback_keylog);
|
|
Packit |
003d89 |
}
|
|
Packit |
003d89 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_init_ctx_session_cache(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSL_CTX *ctx = mctx->ssl_ctx;
|
|
Packit |
90a5c9 |
SSLModConfigRec *mc = myModConfig(s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_session_cache_mode(ctx, mc->sesscache_mode);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mc->sesscache) {
|
|
Packit |
90a5c9 |
SSL_CTX_sess_set_new_cb(ctx, ssl_callback_NewSessionCacheEntry);
|
|
Packit |
90a5c9 |
SSL_CTX_sess_set_get_cb(ctx, ssl_callback_GetSessionCacheEntry);
|
|
Packit |
90a5c9 |
SSL_CTX_sess_set_remove_cb(ctx, ssl_callback_DelSessionCacheEntry);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_init_ctx_callbacks(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSL_CTX *ctx = mctx->ssl_ctx;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_tmp_dh_callback(ctx, ssl_callback_TmpDH);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_info_callback(ctx, ssl_callback_Info);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLS_ALPN
|
|
Packit |
90a5c9 |
SSL_CTX_set_alpn_select_cb(ctx, ssl_callback_alpn_select, NULL);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ctx_verify(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSL_CTX *ctx = mctx->ssl_ctx;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int verify = SSL_VERIFY_NONE;
|
|
Packit |
90a5c9 |
STACK_OF(X509_NAME) *ca_list;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->auth.verify_mode == SSL_CVERIFY_UNSET) {
|
|
Packit |
90a5c9 |
mctx->auth.verify_mode = SSL_CVERIFY_NONE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->auth.verify_depth == UNSET) {
|
|
Packit |
90a5c9 |
mctx->auth.verify_depth = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure callbacks for SSL context
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (mctx->auth.verify_mode == SSL_CVERIFY_REQUIRE) {
|
|
Packit |
90a5c9 |
verify |= SSL_VERIFY_PEER_STRICT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((mctx->auth.verify_mode == SSL_CVERIFY_OPTIONAL) ||
|
|
Packit |
90a5c9 |
(mctx->auth.verify_mode == SSL_CVERIFY_OPTIONAL_NO_CA))
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
verify |= SSL_VERIFY_PEER;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_verify(ctx, verify, ssl_callback_SSLVerify);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure Client Authentication details
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (mctx->auth.ca_cert_file || mctx->auth.ca_cert_path) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, s,
|
|
Packit |
90a5c9 |
"Configuring client authentication");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!SSL_CTX_load_verify_locations(ctx,
|
|
Packit |
90a5c9 |
mctx->auth.ca_cert_file,
|
|
Packit |
90a5c9 |
mctx->auth.ca_cert_path))
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01895)
|
|
Packit |
90a5c9 |
"Unable to configure verify locations "
|
|
Packit |
90a5c9 |
"for client authentication");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->pks && (mctx->pks->ca_name_file || mctx->pks->ca_name_path)) {
|
|
Packit |
90a5c9 |
ca_list = ssl_init_FindCAList(s, ptemp,
|
|
Packit |
90a5c9 |
mctx->pks->ca_name_file,
|
|
Packit |
90a5c9 |
mctx->pks->ca_name_path);
|
|
Packit |
90a5c9 |
} else
|
|
Packit |
90a5c9 |
ca_list = ssl_init_FindCAList(s, ptemp,
|
|
Packit |
90a5c9 |
mctx->auth.ca_cert_file,
|
|
Packit |
90a5c9 |
mctx->auth.ca_cert_path);
|
|
Packit |
90a5c9 |
if (sk_X509_NAME_num(ca_list) <= 0) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01896)
|
|
Packit |
90a5c9 |
"Unable to determine list of acceptable "
|
|
Packit |
90a5c9 |
"CA certificates for client authentication");
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_client_CA_list(ctx, ca_list);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Give a warning when no CAs were configured but client authentication
|
|
Packit |
90a5c9 |
* should take place. This cannot work.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (mctx->auth.verify_mode == SSL_CVERIFY_REQUIRE) {
|
|
Packit |
90a5c9 |
ca_list = SSL_CTX_get_client_CA_list(ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sk_X509_NAME_num(ca_list) == 0) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(01897)
|
|
Packit |
90a5c9 |
"Init: Oops, you want to request client "
|
|
Packit |
90a5c9 |
"authentication, but no CAs are known for "
|
|
Packit |
90a5c9 |
"verification!? [Hint: SSLCACertificate*]");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ctx_cipher_suite(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSL_CTX *ctx = mctx->ssl_ctx;
|
|
Packit |
90a5c9 |
const char *suite;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure SSL Cipher Suite. Always disable NULL and export ciphers,
|
|
Packit |
90a5c9 |
* see also ssl_engine_config.c:ssl_cmd_SSLCipherSuite().
|
|
Packit |
90a5c9 |
* OpenSSL's SSL_DEFAULT_CIPHER_LIST includes !aNULL:!eNULL from 0.9.8f,
|
|
Packit |
90a5c9 |
* and !EXP from 0.9.8zf/1.0.1m/1.0.2a, so append them while we support
|
|
Packit |
90a5c9 |
* earlier versions.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
suite = mctx->auth.cipher_suite ? mctx->auth.cipher_suite :
|
|
Packit |
90a5c9 |
apr_pstrcat(ptemp, SSL_DEFAULT_CIPHER_LIST, ":!aNULL:!eNULL:!EXP",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, s,
|
|
Packit |
90a5c9 |
"Configuring permitted SSL ciphers [%s]",
|
|
Packit |
90a5c9 |
suite);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!SSL_CTX_set_cipher_list(ctx, suite)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01898)
|
|
Packit |
90a5c9 |
"Unable to configure permitted SSL ciphers");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#if SSL_HAVE_PROTOCOL_TLSV1_3
|
|
Packit |
90a5c9 |
if (mctx->auth.tls13_ciphers
|
|
Packit |
90a5c9 |
&& !SSL_CTX_set_ciphersuites(ctx, mctx->auth.tls13_ciphers)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO()
|
|
Packit |
90a5c9 |
"Unable to configure permitted TLSv1.3 ciphers");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ctx_crl(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
X509_STORE *store = SSL_CTX_get_cert_store(mctx->ssl_ctx);
|
|
Packit |
90a5c9 |
unsigned long crlflags = 0;
|
|
Packit |
90a5c9 |
char *cfgp = mctx->pkp ? "SSLProxy" : "SSL";
|
|
Packit |
90a5c9 |
int crl_check_mode;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->ocsp_mask == UNSET) {
|
|
Packit |
90a5c9 |
mctx->ocsp_mask = SSL_OCSPCHECK_NONE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->crl_check_mask == UNSET) {
|
|
Packit |
90a5c9 |
mctx->crl_check_mask = SSL_CRLCHECK_NONE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
crl_check_mode = mctx->crl_check_mask & ~SSL_CRLCHECK_FLAGS;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure Certificate Revocation List (CRL) Details
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(mctx->crl_file || mctx->crl_path)) {
|
|
Packit |
90a5c9 |
if (crl_check_mode == SSL_CRLCHECK_LEAF ||
|
|
Packit |
90a5c9 |
crl_check_mode == SSL_CRLCHECK_CHAIN) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01899)
|
|
Packit |
90a5c9 |
"Host %s: CRL checking has been enabled, but "
|
|
Packit |
90a5c9 |
"neither %sCARevocationFile nor %sCARevocationPath "
|
|
Packit |
90a5c9 |
"is configured", mctx->sc->vhost_id, cfgp, cfgp);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01900)
|
|
Packit |
90a5c9 |
"Configuring certificate revocation facility");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!store || !X509_STORE_load_locations(store, mctx->crl_file,
|
|
Packit |
90a5c9 |
mctx->crl_path)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01901)
|
|
Packit |
90a5c9 |
"Host %s: unable to configure X.509 CRL storage "
|
|
Packit |
90a5c9 |
"for certificate revocation", mctx->sc->vhost_id);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (crl_check_mode) {
|
|
Packit |
90a5c9 |
case SSL_CRLCHECK_LEAF:
|
|
Packit |
90a5c9 |
crlflags = X509_V_FLAG_CRL_CHECK;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case SSL_CRLCHECK_CHAIN:
|
|
Packit |
90a5c9 |
crlflags = X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
crlflags = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (crlflags) {
|
|
Packit |
90a5c9 |
X509_STORE_set_flags(store, crlflags);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(01902)
|
|
Packit |
90a5c9 |
"Host %s: X.509 CRL storage locations configured, "
|
|
Packit |
90a5c9 |
"but CRL checking (%sCARevocationCheck) is not "
|
|
Packit |
90a5c9 |
"enabled", mctx->sc->vhost_id, cfgp);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Read a file that optionally contains the server certificate in PEM
|
|
Packit |
90a5c9 |
* format, possibly followed by a sequence of CA certificates that
|
|
Packit |
90a5c9 |
* should be sent to the peer in the SSL Certificate message.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int use_certificate_chain(
|
|
Packit |
90a5c9 |
SSL_CTX *ctx, char *file, int skipfirst, pem_password_cb *cb)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
BIO *bio;
|
|
Packit |
90a5c9 |
X509 *x509;
|
|
Packit |
90a5c9 |
unsigned long err;
|
|
Packit |
90a5c9 |
int n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((bio = BIO_new(BIO_s_file())) == NULL)
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
if (BIO_read_filename(bio, file) <= 0) {
|
|
Packit |
90a5c9 |
BIO_free(bio);
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* optionally skip a leading server certificate */
|
|
Packit |
90a5c9 |
if (skipfirst) {
|
|
Packit |
90a5c9 |
if ((x509 = PEM_read_bio_X509(bio, NULL, cb, NULL)) == NULL) {
|
|
Packit |
90a5c9 |
BIO_free(bio);
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
X509_free(x509);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* free a perhaps already configured extra chain */
|
|
Packit |
90a5c9 |
#ifdef OPENSSL_NO_SSL_INTERN
|
|
Packit |
90a5c9 |
SSL_CTX_clear_extra_chain_certs(ctx);
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
if (ctx->extra_certs != NULL) {
|
|
Packit |
90a5c9 |
sk_X509_pop_free((STACK_OF(X509) *)ctx->extra_certs, X509_free);
|
|
Packit |
90a5c9 |
ctx->extra_certs = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
/* create new extra chain by loading the certs */
|
|
Packit |
90a5c9 |
n = 0;
|
|
Packit |
90a5c9 |
while ((x509 = PEM_read_bio_X509(bio, NULL, cb, NULL)) != NULL) {
|
|
Packit |
90a5c9 |
if (!SSL_CTX_add_extra_chain_cert(ctx, x509)) {
|
|
Packit |
90a5c9 |
X509_free(x509);
|
|
Packit |
90a5c9 |
BIO_free(bio);
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
n++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* Make sure that only the error is just an EOF */
|
|
Packit |
90a5c9 |
if ((err = ERR_peek_error()) > 0) {
|
|
Packit |
90a5c9 |
if (!( ERR_GET_LIB(err) == ERR_LIB_PEM
|
|
Packit |
90a5c9 |
&& ERR_GET_REASON(err) == PEM_R_NO_START_LINE)) {
|
|
Packit |
90a5c9 |
BIO_free(bio);
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
while (ERR_get_error() > 0) ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
BIO_free(bio);
|
|
Packit |
90a5c9 |
return n;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ctx_cert_chain(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
BOOL skip_first = FALSE;
|
|
Packit |
90a5c9 |
int i, n;
|
|
Packit |
90a5c9 |
const char *chain = mctx->cert_chain;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Optionally configure extra server certificate chain certificates.
|
|
Packit |
90a5c9 |
* This is usually done by OpenSSL automatically when one of the
|
|
Packit |
90a5c9 |
* server cert issuers are found under SSLCACertificatePath or in
|
|
Packit |
90a5c9 |
* SSLCACertificateFile. But because these are intended for client
|
|
Packit |
90a5c9 |
* authentication it can conflict. For instance when you use a
|
|
Packit |
90a5c9 |
* Global ID server certificate you've to send out the intermediate
|
|
Packit |
90a5c9 |
* CA certificate, too. When you would just configure this with
|
|
Packit |
90a5c9 |
* SSLCACertificateFile and also use client authentication mod_ssl
|
|
Packit |
90a5c9 |
* would accept all clients also issued by this CA. Obviously this
|
|
Packit |
90a5c9 |
* isn't what we want in this situation. So this feature here exists
|
|
Packit |
90a5c9 |
* to allow one to explicitly configure CA certificates which are
|
|
Packit |
90a5c9 |
* used only for the server certificate chain.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!chain) {
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; (i < mctx->pks->cert_files->nelts) &&
|
|
Packit |
90a5c9 |
APR_ARRAY_IDX(mctx->pks->cert_files, i, const char *); i++) {
|
|
Packit |
90a5c9 |
if (strEQ(APR_ARRAY_IDX(mctx->pks->cert_files, i, const char *), chain)) {
|
|
Packit |
90a5c9 |
skip_first = TRUE;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
n = use_certificate_chain(mctx->ssl_ctx, (char *)chain, skip_first, NULL);
|
|
Packit |
90a5c9 |
if (n < 0) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01903)
|
|
Packit |
90a5c9 |
"Failed to configure CA certificate chain!");
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01904)
|
|
Packit |
90a5c9 |
"Configuring server certificate chain "
|
|
Packit |
90a5c9 |
"(%d CA certificate%s)",
|
|
Packit |
90a5c9 |
n, n == 1 ? "" : "s");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ctx(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx_protocol(s, p, ptemp, mctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ssl_init_ctx_session_cache(s, p, ptemp, mctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ssl_init_ctx_callbacks(s, p, ptemp, mctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx_verify(s, p, ptemp, mctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx_cipher_suite(s, p, ptemp, mctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx_crl(s, p, ptemp, mctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->pks) {
|
|
Packit |
90a5c9 |
/* XXX: proxy support? */
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx_cert_chain(s, p, ptemp, mctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx_tls_extensions(s, p, ptemp, mctx)) !=
|
|
Packit |
90a5c9 |
APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_check_public_cert(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
X509 *cert,
|
|
Packit |
90a5c9 |
const char *key_id)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int is_ca, pathlen;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!cert) {
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Some information about the certificate(s)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (modssl_X509_getBC(cert, &is_ca, &pathlen)) {
|
|
Packit |
90a5c9 |
if (is_ca) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(01906)
|
|
Packit |
90a5c9 |
"%s server certificate is a CA certificate "
|
|
Packit |
90a5c9 |
"(BasicConstraints: CA == TRUE !?)", key_id);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pathlen > 0) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(01907)
|
|
Packit |
90a5c9 |
"%s server certificate is not a leaf certificate "
|
|
Packit |
90a5c9 |
"(BasicConstraints: pathlen == %d > 0 !?)",
|
|
Packit |
90a5c9 |
key_id, pathlen);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (modssl_X509_match_name(ptemp, cert, (const char *)s->server_hostname,
|
|
Packit |
90a5c9 |
TRUE, s) == FALSE) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(01909)
|
|
Packit |
90a5c9 |
"%s server certificate does NOT include an ID "
|
|
Packit |
90a5c9 |
"which matches the server name", key_id);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* prevent OpenSSL from showing its "Enter PEM pass phrase:" prompt */
|
|
Packit |
90a5c9 |
static int ssl_no_passwd_prompt_cb(char *buf, int size, int rwflag,
|
|
Packit |
90a5c9 |
void *userdata) {
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_server_certs(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx,
|
|
Packit |
90a5c9 |
apr_array_header_t *pphrases)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSLModConfigRec *mc = myModConfig(s);
|
|
Packit |
90a5c9 |
const char *vhost_id = mctx->sc->vhost_id, *key_id, *certfile, *keyfile;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
X509 *cert;
|
|
Packit |
90a5c9 |
DH *dhparams;
|
|
Packit |
90a5c9 |
#ifdef HAVE_ECC
|
|
Packit |
90a5c9 |
EC_GROUP *ecparams = NULL;
|
|
Packit |
90a5c9 |
int nid;
|
|
Packit |
90a5c9 |
EC_KEY *eckey = NULL;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifndef HAVE_SSL_CONF_CMD
|
|
Packit |
90a5c9 |
SSL *ssl;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* no OpenSSL default prompts for any of the SSL_CTX_use_* calls, please */
|
|
Packit |
90a5c9 |
SSL_CTX_set_default_passwd_cb(mctx->ssl_ctx, ssl_no_passwd_prompt_cb);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Iterate over the SSLCertificateFile array */
|
|
Packit |
90a5c9 |
for (i = 0; (i < mctx->pks->cert_files->nelts) &&
|
|
Packit |
90a5c9 |
(certfile = APR_ARRAY_IDX(mctx->pks->cert_files, i,
|
|
Packit |
90a5c9 |
const char *));
|
|
Packit |
90a5c9 |
i++) {
|
|
Packit |
70c855 |
EVP_PKEY *pkey;
|
|
Packit |
70c855 |
const char *engine_certfile = NULL;
|
|
Packit |
70c855 |
|
|
Packit |
90a5c9 |
key_id = apr_psprintf(ptemp, "%s:%d", vhost_id, i);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ERR_clear_error();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* first the certificate (public key) */
|
|
Packit |
70c855 |
if (modssl_is_engine_id(certfile)) {
|
|
Packit |
70c855 |
engine_certfile = certfile;
|
|
Packit |
70c855 |
}
|
|
Packit |
70c855 |
else if (mctx->cert_chain) {
|
|
Packit |
90a5c9 |
if ((SSL_CTX_use_certificate_file(mctx->ssl_ctx, certfile,
|
|
Packit |
90a5c9 |
SSL_FILETYPE_PEM) < 1)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02561)
|
|
Packit |
90a5c9 |
"Failed to configure certificate %s, check %s",
|
|
Packit |
90a5c9 |
key_id, certfile);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
if ((SSL_CTX_use_certificate_chain_file(mctx->ssl_ctx,
|
|
Packit |
90a5c9 |
certfile) < 1)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02562)
|
|
Packit |
90a5c9 |
"Failed to configure certificate %s (with chain),"
|
|
Packit |
90a5c9 |
" check %s", key_id, certfile);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* and second, the private key */
|
|
Packit |
90a5c9 |
if (i < mctx->pks->key_files->nelts) {
|
|
Packit |
90a5c9 |
keyfile = APR_ARRAY_IDX(mctx->pks->key_files, i, const char *);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
keyfile = certfile;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ERR_clear_error();
|
|
Packit |
90a5c9 |
|
|
Packit |
70c855 |
if (modssl_is_engine_id(keyfile)) {
|
|
Packit |
70c855 |
apr_status_t rv;
|
|
Packit |
70c855 |
|
|
Packit |
70c855 |
cert = NULL;
|
|
Packit |
70c855 |
|
|
Packit |
70c855 |
if ((rv = modssl_load_engine_keypair(s, ptemp, vhost_id,
|
|
Packit |
70c855 |
engine_certfile, keyfile,
|
|
Packit |
70c855 |
&cert, &pkey))) {
|
|
Packit |
70c855 |
return rv;
|
|
Packit |
70c855 |
}
|
|
Packit |
70c855 |
|
|
Packit |
70c855 |
if (cert) {
|
|
Packit |
70c855 |
if (SSL_CTX_use_certificate(mctx->ssl_ctx, cert) < 1) {
|
|
Packit |
70c855 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(10137)
|
|
Packit |
70c855 |
"Failed to configure engine certificate %s, check %s",
|
|
Packit |
70c855 |
key_id, certfile);
|
|
Packit |
70c855 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
70c855 |
return APR_EGENERAL;
|
|
Packit |
70c855 |
}
|
|
Packit |
70c855 |
|
|
Packit |
70c855 |
/* SSL_CTX now owns the cert. */
|
|
Packit |
70c855 |
X509_free(cert);
|
|
Packit |
70c855 |
}
|
|
Packit |
70c855 |
|
|
Packit |
70c855 |
if (SSL_CTX_use_PrivateKey(mctx->ssl_ctx, pkey) < 1) {
|
|
Packit |
70c855 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(10130)
|
|
Packit |
70c855 |
"Failed to configure private key %s from engine",
|
|
Packit |
70c855 |
keyfile);
|
|
Packit |
70c855 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
70c855 |
return APR_EGENERAL;
|
|
Packit |
70c855 |
}
|
|
Packit |
70c855 |
|
|
Packit |
70c855 |
/* SSL_CTX now owns the key */
|
|
Packit |
70c855 |
EVP_PKEY_free(pkey);
|
|
Packit |
70c855 |
}
|
|
Packit |
70c855 |
else if ((SSL_CTX_use_PrivateKey_file(mctx->ssl_ctx, keyfile,
|
|
Packit |
70c855 |
SSL_FILETYPE_PEM) < 1)
|
|
Packit |
70c855 |
&& (ERR_GET_FUNC(ERR_peek_last_error())
|
|
Packit |
70c855 |
!= X509_F_X509_CHECK_PRIVATE_KEY)) {
|
|
Packit |
90a5c9 |
ssl_asn1_t *asn1;
|
|
Packit |
90a5c9 |
const unsigned char *ptr;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ERR_clear_error();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* perhaps it's an encrypted private key, so try again */
|
|
Packit |
90a5c9 |
ssl_load_encrypted_pkey(s, ptemp, i, keyfile, &pphrases);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(asn1 = ssl_asn1_table_get(mc->tPrivateKey, key_id)) ||
|
|
Packit |
90a5c9 |
!(ptr = asn1->cpData) ||
|
|
Packit |
90a5c9 |
!(pkey = d2i_AutoPrivateKey(NULL, &ptr, asn1->nData)) ||
|
|
Packit |
90a5c9 |
(SSL_CTX_use_PrivateKey(mctx->ssl_ctx, pkey) < 1)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02564)
|
|
Packit |
90a5c9 |
"Failed to configure encrypted (?) private key %s,"
|
|
Packit |
90a5c9 |
" check %s", key_id, keyfile);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (SSL_CTX_check_private_key(mctx->ssl_ctx) < 1) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02565)
|
|
Packit |
90a5c9 |
"Certificate and private key %s from %s and %s "
|
|
Packit |
90a5c9 |
"do not match", key_id, certfile, keyfile);
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_SSL_CONF_CMD
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* workaround for those OpenSSL versions where SSL_CTX_get0_certificate
|
|
Packit |
90a5c9 |
* is not yet available: create an SSL struct which we dispose of
|
|
Packit |
90a5c9 |
* as soon as we no longer need access to the cert. (Strictly speaking,
|
|
Packit |
90a5c9 |
* SSL_CTX_get0_certificate does not depend on the SSL_CONF stuff,
|
|
Packit |
90a5c9 |
* but there's no reliable way to check for its existence, so we
|
|
Packit |
90a5c9 |
* assume that if SSL_CONF is available, it's OpenSSL 1.0.2 or later,
|
|
Packit |
90a5c9 |
* and SSL_CTX_get0_certificate is implemented.)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!(cert = SSL_CTX_get0_certificate(mctx->ssl_ctx))) {
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
ssl = SSL_new(mctx->ssl_ctx);
|
|
Packit |
90a5c9 |
if (ssl) {
|
|
Packit |
90a5c9 |
/* Workaround bug in SSL_get_certificate in OpenSSL 0.9.8y */
|
|
Packit |
90a5c9 |
SSL_set_connect_state(ssl);
|
|
Packit |
90a5c9 |
cert = SSL_get_certificate(ssl);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!ssl || !cert) {
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(02566)
|
|
Packit |
90a5c9 |
"Unable to retrieve certificate %s", key_id);
|
|
Packit |
90a5c9 |
#ifndef HAVE_SSL_CONF_CMD
|
|
Packit |
90a5c9 |
if (ssl)
|
|
Packit |
90a5c9 |
SSL_free(ssl);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* warn about potential cert issues */
|
|
Packit |
90a5c9 |
ssl_check_public_cert(s, ptemp, cert, key_id);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if defined(HAVE_OCSP_STAPLING) && !defined(SSL_CTRL_SET_CURRENT_CERT)
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* OpenSSL up to 1.0.1: configure stapling as we go. In 1.0.2
|
|
Packit |
90a5c9 |
* and later, there's SSL_CTX_set_current_cert, which allows
|
|
Packit |
90a5c9 |
* iterating over all certs in an SSL_CTX (including those possibly
|
|
Packit |
90a5c9 |
* loaded via SSLOpenSSLConfCmd Certificate), so for 1.0.2 and
|
|
Packit |
90a5c9 |
* later, we defer to the code in ssl_init_server_ctx.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
20f7c8 |
if (!ssl_stapling_init_cert(s, p, ptemp, mctx, cert)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(02567)
|
|
Packit |
90a5c9 |
"Unable to configure certificate %s for stapling",
|
|
Packit |
90a5c9 |
key_id);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef HAVE_SSL_CONF_CMD
|
|
Packit |
90a5c9 |
SSL_free(ssl);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(02568)
|
|
Packit |
90a5c9 |
"Certificate and private key %s configured from %s and %s",
|
|
Packit |
90a5c9 |
key_id, certfile, keyfile);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Try to read DH parameters from the (first) SSLCertificateFile
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
70c855 |
certfile = APR_ARRAY_IDX(mctx->pks->cert_files, 0, const char *);
|
|
Packit |
70c855 |
if (certfile && !modssl_is_engine_id(certfile)
|
|
Packit |
70c855 |
&& (dhparams = ssl_dh_GetParamFromFile(certfile))) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dhparams);
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02540)
|
|
Packit |
90a5c9 |
"Custom DH parameters (%d bits) for %s loaded from %s",
|
|
Packit |
90a5c9 |
DH_bits(dhparams), vhost_id, certfile);
|
|
Packit |
90a5c9 |
DH_free(dhparams);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_ECC
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Similarly, try to read the ECDH curve name from SSLCertificateFile...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
70c855 |
if (certfile && !modssl_is_engine_id(certfile)
|
|
Packit |
70c855 |
&& (ecparams = ssl_ec_GetParamFromFile(certfile))
|
|
Packit |
70c855 |
&& (nid = EC_GROUP_get_curve_name(ecparams))
|
|
Packit |
70c855 |
&& (eckey = EC_KEY_new_by_curve_name(nid))) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_tmp_ecdh(mctx->ssl_ctx, eckey);
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02541)
|
|
Packit |
90a5c9 |
"ECDH curve %s for %s specified in %s",
|
|
Packit |
90a5c9 |
OBJ_nid2sn(nid), vhost_id, certfile);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* ...otherwise, enable auto curve selection (OpenSSL 1.0.2)
|
|
Packit |
90a5c9 |
* or configure NIST P-256 (required to enable ECDHE for earlier versions)
|
|
Packit |
90a5c9 |
* ECDH is always enabled in 1.1.0 unless excluded from SSLCipherList
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#if MODSSL_USE_OPENSSL_PRE_1_1_API
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
#if defined(SSL_CTX_set_ecdh_auto)
|
|
Packit |
90a5c9 |
SSL_CTX_set_ecdh_auto(mctx->ssl_ctx, 1);
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
|
|
Packit |
90a5c9 |
SSL_CTX_set_tmp_ecdh(mctx->ssl_ctx, eckey);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
/* OpenSSL assures us that _free() is NULL-safe */
|
|
Packit |
90a5c9 |
EC_KEY_free(eckey);
|
|
Packit |
90a5c9 |
EC_GROUP_free(ecparams);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLS_SESSION_TICKETS
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_ticket_key(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
apr_file_t *fp;
|
|
Packit |
90a5c9 |
apr_size_t len;
|
|
Packit |
90a5c9 |
char buf[TLSEXT_TICKET_KEY_LEN];
|
|
Packit |
90a5c9 |
char *path;
|
|
Packit |
90a5c9 |
modssl_ticket_key_t *ticket_key = mctx->ticket_key;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!ticket_key->file_path) {
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
path = ap_server_root_relative(p, ticket_key->file_path);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = apr_file_open(&fp, path, APR_READ|APR_BINARY,
|
|
Packit |
90a5c9 |
APR_OS_DEFAULT, ptemp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02286)
|
|
Packit |
90a5c9 |
"Failed to open ticket key file %s: (%d) %pm",
|
|
Packit |
90a5c9 |
path, rv, &rv;;
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = apr_file_read_full(fp, &buf[0], TLSEXT_TICKET_KEY_LEN, &len;;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02287)
|
|
Packit |
90a5c9 |
"Failed to read %d bytes from %s: (%d) %pm",
|
|
Packit |
90a5c9 |
TLSEXT_TICKET_KEY_LEN, path, rv, &rv;;
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
memcpy(ticket_key->key_name, buf, 16);
|
|
Packit |
90a5c9 |
memcpy(ticket_key->hmac_secret, buf + 16, 16);
|
|
Packit |
90a5c9 |
memcpy(ticket_key->aes_key, buf + 32, 16);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!SSL_CTX_set_tlsext_ticket_key_cb(mctx->ssl_ctx,
|
|
Packit |
90a5c9 |
ssl_callback_SessionTicket)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01913)
|
|
Packit |
90a5c9 |
"Unable to initialize TLS session ticket key callback "
|
|
Packit |
90a5c9 |
"(incompatible OpenSSL version?)");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(02288)
|
|
Packit |
90a5c9 |
"TLS session ticket key for %s successfully loaded from %s",
|
|
Packit |
90a5c9 |
(mySrvConfig(s))->vhost_id, path);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static BOOL load_x509_info(apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
STACK_OF(X509_INFO) *sk,
|
|
Packit |
90a5c9 |
const char *filename)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
BIO *in;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(in = BIO_new(BIO_s_file()))) {
|
|
Packit |
90a5c9 |
return FALSE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (BIO_read_filename(in, filename) <= 0) {
|
|
Packit |
90a5c9 |
BIO_free(in);
|
|
Packit |
90a5c9 |
return FALSE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ERR_clear_error();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
PEM_X509_INFO_read_bio(in, sk, NULL, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_free(in);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return TRUE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_proxy_certs(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int n, ncerts = 0;
|
|
Packit |
90a5c9 |
STACK_OF(X509_INFO) *sk;
|
|
Packit |
90a5c9 |
modssl_pk_proxy_t *pkp = mctx->pkp;
|
|
Packit |
90a5c9 |
STACK_OF(X509) *chain;
|
|
Packit |
90a5c9 |
X509_STORE_CTX *sctx;
|
|
Packit |
90a5c9 |
X509_STORE *store = SSL_CTX_get_cert_store(mctx->ssl_ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
|
|
Packit |
90a5c9 |
/* For OpenSSL >=1.1.1, turn on client cert support which is
|
|
Packit |
90a5c9 |
* otherwise turned off by default (by design).
|
|
Packit |
90a5c9 |
* https://github.com/openssl/openssl/issues/6933 */
|
|
Packit |
90a5c9 |
SSL_CTX_set_post_handshake_auth(mctx->ssl_ctx, 1);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_client_cert_cb(mctx->ssl_ctx,
|
|
Packit |
90a5c9 |
ssl_callback_proxy_cert);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(pkp->cert_file || pkp->cert_path)) {
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sk = sk_X509_INFO_new_null();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pkp->cert_file) {
|
|
Packit |
90a5c9 |
load_x509_info(ptemp, sk, pkp->cert_file);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pkp->cert_path) {
|
|
Packit |
90a5c9 |
apr_dir_t *dir;
|
|
Packit |
90a5c9 |
apr_finfo_t dirent;
|
|
Packit |
90a5c9 |
apr_int32_t finfo_flags = APR_FINFO_TYPE|APR_FINFO_NAME;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (apr_dir_open(&dir, pkp->cert_path, ptemp) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
while ((apr_dir_read(&dirent, finfo_flags, dir)) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
const char *fullname;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (dirent.filetype == APR_DIR) {
|
|
Packit |
90a5c9 |
continue; /* don't try to load directories */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
fullname = apr_pstrcat(ptemp,
|
|
Packit |
90a5c9 |
pkp->cert_path, "/", dirent.name,
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
load_x509_info(ptemp, sk, fullname);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_dir_close(dir);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((ncerts = sk_X509_INFO_num(sk)) <= 0) {
|
|
Packit |
90a5c9 |
sk_X509_INFO_free(sk);
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(02206)
|
|
Packit |
90a5c9 |
"no client certs found for SSL proxy");
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Check that all client certs have got certificates and private
|
|
Packit |
90a5c9 |
* keys. */
|
|
Packit |
90a5c9 |
for (n = 0; n < ncerts; n++) {
|
|
Packit |
90a5c9 |
X509_INFO *inf = sk_X509_INFO_value(sk, n);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!inf->x509 || !inf->x_pkey || !inf->x_pkey->dec_pkey ||
|
|
Packit |
90a5c9 |
inf->enc_data) {
|
|
Packit |
90a5c9 |
sk_X509_INFO_free(sk);
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, APLOGNO(02252)
|
|
Packit |
90a5c9 |
"incomplete client cert configured for SSL proxy "
|
|
Packit |
90a5c9 |
"(missing or encrypted private key?)");
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (X509_check_private_key(inf->x509, inf->x_pkey->dec_pkey) != 1) {
|
|
Packit |
90a5c9 |
ssl_log_xerror(SSLLOG_MARK, APLOG_STARTUP, 0, ptemp, s, inf->x509,
|
|
Packit |
90a5c9 |
APLOGNO(02326) "proxy client certificate and "
|
|
Packit |
90a5c9 |
"private key do not match");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_ERR, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02207)
|
|
Packit |
90a5c9 |
"loaded %d client certs for SSL proxy",
|
|
Packit |
90a5c9 |
ncerts);
|
|
Packit |
90a5c9 |
pkp->certs = sk;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!pkp->ca_cert_file || !store) {
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* If SSLProxyMachineCertificateChainFile is configured, load all
|
|
Packit |
90a5c9 |
* the CA certs and have OpenSSL attempt to construct a full chain
|
|
Packit |
90a5c9 |
* from each configured end-entity cert up to a root. This will
|
|
Packit |
90a5c9 |
* allow selection of the correct cert given a list of root CA
|
|
Packit |
90a5c9 |
* names in the certificate request from the server. */
|
|
Packit |
90a5c9 |
pkp->ca_certs = (STACK_OF(X509) **) apr_pcalloc(p, ncerts * sizeof(sk));
|
|
Packit |
90a5c9 |
sctx = X509_STORE_CTX_new();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!sctx) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02208)
|
|
Packit |
90a5c9 |
"SSL proxy client cert initialization failed");
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
X509_STORE_load_locations(store, pkp->ca_cert_file, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (n = 0; n < ncerts; n++) {
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
X509_INFO *inf = sk_X509_INFO_value(pkp->certs, n);
|
|
Packit |
90a5c9 |
X509_STORE_CTX_init(sctx, store, inf->x509, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Attempt to verify the client cert */
|
|
Packit |
90a5c9 |
if (X509_verify_cert(sctx) != 1) {
|
|
Packit |
90a5c9 |
int err = X509_STORE_CTX_get_error(sctx);
|
|
Packit |
90a5c9 |
ssl_log_xerror(SSLLOG_MARK, APLOG_WARNING, 0, ptemp, s, inf->x509,
|
|
Packit |
90a5c9 |
APLOGNO(02270) "SSL proxy client cert chain "
|
|
Packit |
90a5c9 |
"verification failed: %s :",
|
|
Packit |
90a5c9 |
X509_verify_cert_error_string(err));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Clear X509_verify_cert errors */
|
|
Packit |
90a5c9 |
ERR_clear_error();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Obtain a copy of the verified chain */
|
|
Packit |
90a5c9 |
chain = X509_STORE_CTX_get1_chain(sctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (chain != NULL) {
|
|
Packit |
90a5c9 |
/* Discard end entity cert from the chain */
|
|
Packit |
90a5c9 |
X509_free(sk_X509_shift(chain));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((i = sk_X509_num(chain)) > 0) {
|
|
Packit |
90a5c9 |
/* Store the chain for later use */
|
|
Packit |
90a5c9 |
pkp->ca_certs[n] = chain;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* Discard empty chain */
|
|
Packit |
90a5c9 |
sk_X509_pop_free(chain, X509_free);
|
|
Packit |
90a5c9 |
pkp->ca_certs[n] = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ssl_log_xerror(SSLLOG_MARK, APLOG_DEBUG, 0, ptemp, s, inf->x509,
|
|
Packit |
90a5c9 |
APLOGNO(02271)
|
|
Packit |
90a5c9 |
"loaded %i intermediate CA%s for cert %i: ",
|
|
Packit |
90a5c9 |
i, i == 1 ? "" : "s", n);
|
|
Packit |
90a5c9 |
if (i > 0) {
|
|
Packit |
90a5c9 |
int j;
|
|
Packit |
90a5c9 |
for (j = 0; j < i; j++) {
|
|
Packit |
90a5c9 |
ssl_log_xerror(SSLLOG_MARK, APLOG_DEBUG, 0, ptemp, s,
|
|
Packit |
90a5c9 |
sk_X509_value(chain, j), APLOGNO(03039)
|
|
Packit |
90a5c9 |
"%i:", j);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* get ready for next X509_STORE_CTX_init */
|
|
Packit |
90a5c9 |
X509_STORE_CTX_cleanup(sctx);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
X509_STORE_CTX_free(sctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define MODSSL_CFG_ITEM_FREE(func, item) \
|
|
Packit |
90a5c9 |
if (item) { \
|
|
Packit |
90a5c9 |
func(item); \
|
|
Packit |
90a5c9 |
item = NULL; \
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_init_ctx_cleanup(modssl_ctx_t *mctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
MODSSL_CFG_ITEM_FREE(SSL_CTX_free, mctx->ssl_ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_SRP
|
|
Packit |
90a5c9 |
if (mctx->srp_vbase != NULL) {
|
|
Packit |
90a5c9 |
SRP_VBASE_free(mctx->srp_vbase);
|
|
Packit |
90a5c9 |
mctx->srp_vbase = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_cleanup_proxy_ctx(void *data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
modssl_ctx_t *mctx = data;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ssl_init_ctx_cleanup(mctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->pkp->certs) {
|
|
Packit |
90a5c9 |
int i = 0;
|
|
Packit |
90a5c9 |
int ncerts = sk_X509_INFO_num(mctx->pkp->certs);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (mctx->pkp->ca_certs) {
|
|
Packit |
90a5c9 |
for (i = 0; i < ncerts; i++) {
|
|
Packit |
90a5c9 |
if (mctx->pkp->ca_certs[i] != NULL) {
|
|
Packit |
90a5c9 |
sk_X509_pop_free(mctx->pkp->ca_certs[i], X509_free);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sk_X509_INFO_pop_free(mctx->pkp->certs, X509_INFO_free);
|
|
Packit |
90a5c9 |
mctx->pkp->certs = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_proxy_ctx(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
modssl_ctx_t *proxy)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (proxy->ssl_ctx) {
|
|
Packit |
90a5c9 |
/* Merged/initialized already */
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(p, proxy,
|
|
Packit |
90a5c9 |
ssl_cleanup_proxy_ctx,
|
|
Packit |
90a5c9 |
apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx(s, p, ptemp, proxy)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_proxy_certs(s, p, ptemp, proxy)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t ssl_init_server_ctx(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
SSLSrvConfigRec *sc,
|
|
Packit |
90a5c9 |
apr_array_header_t *pphrases)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
20f7c8 |
modssl_pk_server_t *pks;
|
|
Packit |
90a5c9 |
#ifdef HAVE_SSL_CONF_CMD
|
|
Packit |
90a5c9 |
ssl_ctx_param_t *param = (ssl_ctx_param_t *)sc->server->ssl_ctx_param->elts;
|
|
Packit |
90a5c9 |
SSL_CONF_CTX *cctx = sc->server->ssl_ctx_config;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
20f7c8 |
int n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Check for problematic re-initializations
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (sc->server->ssl_ctx) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02569)
|
|
Packit |
90a5c9 |
"Illegal attempt to re-initialise SSL for server "
|
|
Packit |
90a5c9 |
"(SSLEngine On should go in the VirtualHost, not in global scope.)");
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
20f7c8 |
/* Allow others to provide certificate files */
|
|
Packit |
20f7c8 |
pks = sc->server->pks;
|
|
Packit |
20f7c8 |
n = pks->cert_files->nelts;
|
|
Packit |
20f7c8 |
ssl_run_add_cert_files(s, p, pks->cert_files, pks->key_files);
|
|
Packit |
20f7c8 |
|
|
Packit |
20f7c8 |
if (n < pks->cert_files->nelts) {
|
|
Packit |
20f7c8 |
/* this overrides any old chain configuration */
|
|
Packit |
20f7c8 |
sc->server->cert_chain = NULL;
|
|
Packit |
20f7c8 |
}
|
|
Packit |
20f7c8 |
|
|
Packit |
20f7c8 |
if (apr_is_empty_array(pks->cert_files) && !sc->server->cert_chain) {
|
|
Packit |
20f7c8 |
ssl_run_add_fallback_cert_files(s, p, pks->cert_files, pks->key_files);
|
|
Packit |
20f7c8 |
|
|
Packit |
20f7c8 |
pks->service_unavailable = 1;
|
|
Packit |
20f7c8 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(10085)
|
|
Packit |
20f7c8 |
"Init: %s will respond with '503 Service Unavailable' for now. There "
|
|
Packit |
20f7c8 |
"are no SSL certificates configured and no other module contributed any.",
|
|
Packit |
20f7c8 |
ssl_util_vhostid(p, s));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ctx(s, p, ptemp, sc->server)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_server_certs(s, p, ptemp, sc->server, pphrases))
|
|
Packit |
90a5c9 |
!= APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_SSL_CONF_CMD
|
|
Packit |
90a5c9 |
SSL_CONF_CTX_set_ssl_ctx(cctx, sc->server->ssl_ctx);
|
|
Packit |
90a5c9 |
for (i = 0; i < sc->server->ssl_ctx_param->nelts; i++, param++) {
|
|
Packit |
90a5c9 |
ERR_clear_error();
|
|
Packit |
90a5c9 |
if (SSL_CONF_cmd(cctx, param->name, param->value) <= 0) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02407)
|
|
Packit |
90a5c9 |
"\"SSLOpenSSLConfCmd %s %s\" failed for %s",
|
|
Packit |
90a5c9 |
param->name, param->value, sc->vhost_id);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02556)
|
|
Packit |
90a5c9 |
"\"SSLOpenSSLConfCmd %s %s\" applied to %s",
|
|
Packit |
90a5c9 |
param->name, param->value, sc->vhost_id);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (SSL_CONF_CTX_finish(cctx) == 0) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02547)
|
|
Packit |
90a5c9 |
"SSL_CONF_CTX_finish() failed");
|
|
Packit |
90a5c9 |
SSL_CONF_CTX_free(cctx);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (SSL_CTX_check_private_key(sc->server->ssl_ctx) != 1) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02572)
|
|
Packit |
90a5c9 |
"Failed to configure at least one certificate and key "
|
|
Packit |
90a5c9 |
"for %s", sc->vhost_id);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_EMERG, s);
|
|
Packit |
90a5c9 |
return ssl_die(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if defined(HAVE_OCSP_STAPLING) && defined(SSL_CTRL_SET_CURRENT_CERT)
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* OpenSSL 1.0.2 and later allows iterating over all SSL_CTX certs
|
|
Packit |
90a5c9 |
* by means of SSL_CTX_set_current_cert. Enabling stapling at this
|
|
Packit |
90a5c9 |
* (late) point makes sure that we catch both certificates loaded
|
|
Packit |
90a5c9 |
* via SSLCertificateFile and SSLOpenSSLConfCmd Certificate.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
20f7c8 |
do {
|
|
Packit |
90a5c9 |
X509 *cert;
|
|
Packit |
90a5c9 |
int i = 0;
|
|
Packit |
90a5c9 |
int ret = SSL_CTX_set_current_cert(sc->server->ssl_ctx,
|
|
Packit |
90a5c9 |
SSL_CERT_SET_FIRST);
|
|
Packit |
90a5c9 |
while (ret) {
|
|
Packit |
90a5c9 |
cert = SSL_CTX_get0_certificate(sc->server->ssl_ctx);
|
|
Packit |
90a5c9 |
if (!cert || !ssl_stapling_init_cert(s, p, ptemp, sc->server,
|
|
Packit |
90a5c9 |
cert)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(02604)
|
|
Packit |
90a5c9 |
"Unable to configure certificate %s:%d "
|
|
Packit |
90a5c9 |
"for stapling", sc->vhost_id, i);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ret = SSL_CTX_set_current_cert(sc->server->ssl_ctx,
|
|
Packit |
90a5c9 |
SSL_CERT_SET_NEXT);
|
|
Packit |
90a5c9 |
i++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
20f7c8 |
} while(0);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLS_SESSION_TICKETS
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_ticket_key(s, p, ptemp, sc->server)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SSL_CTX_set_timeout(sc->server->ssl_ctx,
|
|
Packit |
90a5c9 |
sc->session_cache_timeout == UNSET ?
|
|
Packit |
90a5c9 |
SSL_SESSION_CACHE_TIMEOUT : sc->session_cache_timeout);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Configure a particular server
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t ssl_init_ConfigureServer(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
SSLSrvConfigRec *sc,
|
|
Packit |
90a5c9 |
apr_array_header_t *pphrases)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSLDirConfigRec *sdc = ap_get_module_config(s->lookup_defaults,
|
|
Packit |
90a5c9 |
&ssl_module);
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Initialize the server if SSL is enabled or optional.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((sc->enabled == SSL_ENABLED_TRUE) || (sc->enabled == SSL_ENABLED_OPTIONAL)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(01914)
|
|
Packit |
90a5c9 |
"Configuring server %s for SSL protocol", sc->vhost_id);
|
|
Packit |
90a5c9 |
if ((rv = ssl_init_server_ctx(s, p, ptemp, sc, pphrases))
|
|
Packit |
90a5c9 |
!= APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Initialize OCSP Responder certificate if OCSP enabled */
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_OCSP
|
|
Packit |
90a5c9 |
ssl_init_ocsp_certificates(s, sc->server);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sdc->proxy->sc = sc;
|
|
Packit |
90a5c9 |
if (sdc->proxy_enabled == TRUE) {
|
|
Packit |
90a5c9 |
rv = ssl_init_proxy_ctx(s, p, ptemp, sdc->proxy);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
sdc->proxy_enabled = FALSE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
sdc->proxy_post_config = 1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t ssl_init_CheckServers(server_rec *base_server, apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
server_rec *s;
|
|
Packit |
90a5c9 |
SSLSrvConfigRec *sc;
|
|
Packit |
90a5c9 |
#ifndef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
server_rec *ps;
|
|
Packit |
90a5c9 |
apr_hash_t *table;
|
|
Packit |
90a5c9 |
const char *key;
|
|
Packit |
90a5c9 |
apr_ssize_t klen;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BOOL conflict = FALSE;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Give out warnings when a server has HTTPS configured
|
|
Packit |
90a5c9 |
* for the HTTP port or vice versa
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (s = base_server; s; s = s->next) {
|
|
Packit |
90a5c9 |
sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((sc->enabled == SSL_ENABLED_TRUE) && (s->port == DEFAULT_HTTP_PORT)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
|
|
Packit |
90a5c9 |
base_server, APLOGNO(01915)
|
|
Packit |
90a5c9 |
"Init: (%s) You configured HTTPS(%d) "
|
|
Packit |
90a5c9 |
"on the standard HTTP(%d) port!",
|
|
Packit |
90a5c9 |
ssl_util_vhostid(p, s),
|
|
Packit |
90a5c9 |
DEFAULT_HTTPS_PORT, DEFAULT_HTTP_PORT);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((sc->enabled == SSL_ENABLED_FALSE) && (s->port == DEFAULT_HTTPS_PORT)) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
|
|
Packit |
90a5c9 |
base_server, APLOGNO(01916)
|
|
Packit |
90a5c9 |
"Init: (%s) You configured HTTP(%d) "
|
|
Packit |
90a5c9 |
"on the standard HTTPS(%d) port!",
|
|
Packit |
90a5c9 |
ssl_util_vhostid(p, s),
|
|
Packit |
90a5c9 |
DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Give out warnings when more than one SSL-aware virtual server uses the
|
|
Packit |
90a5c9 |
* same IP:port and an OpenSSL version without support for TLS extensions
|
|
Packit |
90a5c9 |
* (SNI in particular) is used.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
table = apr_hash_make(p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (s = base_server; s; s = s->next) {
|
|
Packit |
90a5c9 |
char *addr;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!((sc->enabled == SSL_ENABLED_TRUE) && s->addrs)) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_sockaddr_ip_get(&addr, s->addrs->host_addr);
|
|
Packit |
90a5c9 |
key = apr_psprintf(p, "%s:%u", addr, s->addrs->host_port);
|
|
Packit |
90a5c9 |
klen = strlen(key);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((ps = (server_rec *)apr_hash_get(table, key, klen))) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, base_server, APLOGNO(02662)
|
|
Packit |
90a5c9 |
"Init: SSL server IP/port conflict: "
|
|
Packit |
90a5c9 |
"%s (%s:%d) vs. %s (%s:%d)",
|
|
Packit |
90a5c9 |
ssl_util_vhostid(p, s),
|
|
Packit |
90a5c9 |
(s->defn_name ? s->defn_name : "unknown"),
|
|
Packit |
90a5c9 |
s->defn_line_number,
|
|
Packit |
90a5c9 |
ssl_util_vhostid(p, ps),
|
|
Packit |
90a5c9 |
(ps->defn_name ? ps->defn_name : "unknown"),
|
|
Packit |
90a5c9 |
ps->defn_line_number);
|
|
Packit |
90a5c9 |
conflict = TRUE;
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_hash_set(table, key, klen, s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (conflict) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, base_server, APLOGNO(01917)
|
|
Packit |
90a5c9 |
"Init: Name-based SSL virtual hosts require "
|
|
Packit |
90a5c9 |
"an OpenSSL version with support for TLS extensions "
|
|
Packit |
90a5c9 |
"(RFC 6066 - Server Name Indication / SNI), "
|
|
Packit |
90a5c9 |
"but the currently used library version (%s) is "
|
|
Packit |
90a5c9 |
"lacking this feature", MODSSL_LIBRARY_DYNTEXT);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int ssl_proxy_section_post_config(apr_pool_t *p, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp, server_rec *s,
|
|
Packit |
90a5c9 |
ap_conf_vector_t *section_config)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSLDirConfigRec *sdc = ap_get_module_config(s->lookup_defaults,
|
|
Packit |
90a5c9 |
&ssl_module);
|
|
Packit |
90a5c9 |
SSLDirConfigRec *pdc = ap_get_module_config(section_config,
|
|
Packit |
90a5c9 |
&ssl_module);
|
|
Packit |
90a5c9 |
if (pdc) {
|
|
Packit |
90a5c9 |
pdc->proxy->sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
ssl_config_proxy_merge(p, sdc, pdc);
|
|
Packit |
90a5c9 |
if (pdc->proxy_enabled) {
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = ssl_init_proxy_ctx(s, p, ptemp, pdc->proxy);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = ssl_run_init_server(s, p, 1, pdc->proxy->ssl_ctx);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return !OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
pdc->proxy_post_config = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
STACK_OF(X509_NAME) *ssl_init_FindCAList(server_rec *s,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
const char *ca_file,
|
|
Packit |
90a5c9 |
const char *ca_path)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
503163 |
STACK_OF(X509_NAME) *ca_list = sk_X509_NAME_new_null();;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Process CA certificate bundle file
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (ca_file) {
|
|
Packit |
503163 |
SSL_add_file_cert_subjects_to_stack(ca_list, ca_file);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If ca_list is still empty after trying to load ca_file
|
|
Packit |
90a5c9 |
* then the file failed to load, and users should hear about that.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (sk_X509_NAME_num(ca_list) == 0) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(02210)
|
|
Packit |
90a5c9 |
"Failed to load SSLCACertificateFile: %s", ca_file);
|
|
Packit |
90a5c9 |
ssl_log_ssl_error(SSLLOG_MARK, APLOG_ERR, s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Process CA certificate path files
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (ca_path) {
|
|
Packit |
90a5c9 |
apr_dir_t *dir;
|
|
Packit |
90a5c9 |
apr_finfo_t direntry;
|
|
Packit |
90a5c9 |
apr_int32_t finfo_flags = APR_FINFO_TYPE|APR_FINFO_NAME;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = apr_dir_open(&dir, ca_path, ptemp)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02211)
|
|
Packit |
90a5c9 |
"Failed to open Certificate Path `%s'",
|
|
Packit |
90a5c9 |
ca_path);
|
|
Packit |
90a5c9 |
sk_X509_NAME_pop_free(ca_list, X509_NAME_free);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((apr_dir_read(&direntry, finfo_flags, dir)) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
const char *file;
|
|
Packit |
90a5c9 |
if (direntry.filetype == APR_DIR) {
|
|
Packit |
90a5c9 |
continue; /* don't try to load directories */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
file = apr_pstrcat(ptemp, ca_path, "/", direntry.name, NULL);
|
|
Packit |
503163 |
SSL_add_file_cert_subjects_to_stack(ca_list, file);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_dir_close(dir);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return ca_list;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void ssl_init_Child(apr_pool_t *p, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSLModConfigRec *mc = myModConfig(s);
|
|
Packit |
90a5c9 |
mc->pid = getpid(); /* only call getpid() once per-process */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* XXX: there should be an ap_srand() function */
|
|
Packit |
90a5c9 |
srand((unsigned int)time(NULL));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* open the mutex lockfile */
|
|
Packit |
90a5c9 |
ssl_mutex_reinit(s, p);
|
|
Packit |
90a5c9 |
#ifdef HAVE_OCSP_STAPLING
|
|
Packit |
90a5c9 |
ssl_stapling_mutex_reinit(s, p);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t ssl_init_ModuleKill(void *data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
SSLSrvConfigRec *sc;
|
|
Packit |
90a5c9 |
server_rec *base_server = (server_rec *)data;
|
|
Packit |
90a5c9 |
server_rec *s;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Drop the session cache and mutex
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ssl_scache_kill(base_server);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Free the non-pool allocated structures
|
|
Packit |
90a5c9 |
* in the per-server configurations
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (s = base_server; s; s = s->next) {
|
|
Packit |
90a5c9 |
sc = mySrvConfig(s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ssl_init_ctx_cleanup(sc->server);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Not Sure but possibly clear X509 trusted cert file */
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_OCSP
|
|
Packit |
90a5c9 |
sk_X509_pop_free(sc->server->ocsp_certs, X509_free);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if !MODSSL_USE_OPENSSL_PRE_1_1_API
|
|
Packit |
90a5c9 |
free_bio_methods();
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
free_dh_params();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|