ssl_engine_init.c revision baa6746bc66ff1daa1852a3a085906d2dfa96bb6
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* _ _
* _ __ ___ ___ __| | ___ ___| | mod_ssl
* | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
* | | | | | | (_) | (_| | \__ \__ \ |
* |_| |_| |_|\___/ \__,_|___|___/___/_|
* |_____|
* Initialization of Servers
*/
/* ``Recursive, adj.;
see Recursive.''
-- Unknown */
#include "ssl_private.h"
/* _________________________________________________________________
**
** Module Initialization
** _________________________________________________________________
*/
static void ssl_add_version_components(apr_pool_t *p,
server_rec *s)
{
"SSL_VERSION_LIBRARY_INTERFACE");
"%s compiled against Server: %s, Library: %s",
}
/*
* Handle the Temporary RSA Keys and DH Params
*/
}
static void ssl_tmp_keys_free(server_rec *s)
{
}
static int ssl_tmp_key_init_rsa(server_rec *s,
{
#ifdef HAVE_FIPS
"Init: Skipping generating temporary "
"%d bit RSA private key in FIPS mode", bits);
return OK;
}
#endif
{
"Init: Failed to generate temporary "
"%d bit RSA private key", bits);
return !OK;
}
return OK;
}
static int ssl_tmp_key_init_dh(server_rec *s,
{
#ifdef HAVE_FIPS
"Init: Skipping generating temporary "
"%d bit DH parameters in FIPS mode", bits);
return OK;
}
#endif
{
"Init: Failed to generate temporary "
"%d bit DH parameters", bits);
return !OK;
}
return OK;
}
#define MODSSL_TMP_KEY_INIT_RSA(s, bits) \
#define MODSSL_TMP_KEY_INIT_DH(s, bits) \
static int ssl_tmp_keys_init(server_rec *s)
{
"Init: Generating temporary RSA private keys (512/1024 bits)");
if (MODSSL_TMP_KEY_INIT_RSA(s, 512) ||
MODSSL_TMP_KEY_INIT_RSA(s, 1024)) {
return !OK;
}
"Init: Generating temporary DH parameters (512/1024 bits)");
if (MODSSL_TMP_KEY_INIT_DH(s, 512) ||
MODSSL_TMP_KEY_INIT_DH(s, 1024)) {
return !OK;
}
return OK;
}
/*
* Per-module initialization
*/
{
server_rec *s;
/* We initialize mc->pid per-process in the child init,
* but it should be initialized for startup before we
* call ssl_rand_seed() below.
*/
/*
* Let us cleanup on restarts and exits
*/
/*
* Any init round fixes the global config
*/
/*
* try to fix the configuration and open the dedicated SSL
* logfile as early as possible
*/
for (s = base_server; s; s = s->next) {
sc = mySrvConfig(s);
}
}
/*
* Create the server host:port string because we need it a lot
*/
if (ap_get_server_protocol(s) &&
}
/* If sc->enabled is UNSET, then SSL is optional on this vhost */
/* Fix up stuff that may not have been set */
}
}
}
}
#ifdef HAVE_FIPS
}
#endif
}
#if APR_HAS_THREADS
#endif
/*
* SSL external crypto device ("engine") support
*/
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
#endif
"Init: Initialized %s library", SSL_LIBRARY_NAME);
/*
* Seed the Pseudo Random Number Generator (PRNG)
* only need ptemp here; nothing inside allocated from the pool
* needs to live once we return from ssl_rand_seed().
*/
#ifdef HAVE_FIPS
if (!FIPS_mode()) {
if (FIPS_mode_set(1)) {
"Operating in SSL FIPS mode");
}
else {
ssl_die();
}
}
}
else {
"SSL FIPS mode disabled");
}
#endif
/*
* decrypting any encrypted keys via configured SSLPassPhraseDialogs
* anything that needs to live longer than ptemp needs to also survive
* restarts, in which case they'll live inside s->process->pool.
*/
if (ssl_tmp_keys_init(base_server)) {
return !OK;
}
/*
* initialize the mutex handling
*/
if (!ssl_mutex_init(base_server, p)) {
return HTTP_INTERNAL_SERVER_ERROR;
}
#ifdef HAVE_OCSP_STAPLING
if (!ssl_stapling_mutex_init(base_server, p)) {
return HTTP_INTERNAL_SERVER_ERROR;
}
#endif
/*
* initialize session caching
*/
/*
* initialize servers
*/
"Init: Initializing (virtual) servers for SSL");
for (s = base_server; s; s = s->next) {
sc = mySrvConfig(s);
/*
* Either now skip this server when SSL is disabled for
* it or give out some information about what we're
* configuring.
*/
/*
* Read the server certificate and key
*/
}
/*
* Configuration consistency checks
*/
/*
* Announce mod_ssl and SSL library in HTTP Server field
*/
SSL_init_app_data2_idx(); /* for SSL_get_app_data2() at request time */
return OK;
}
/*
* Support for external a Crypto Device ("engine"), usually
* a hardware accellerator card for crypto operations.
*/
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
{
ENGINE *e;
if (mc->szCryptoDevice) {
"Init: Failed to load Crypto Device API `%s'",
mc->szCryptoDevice);
ssl_die();
}
}
if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
"Init: Failed to enable Crypto Device API `%s'",
mc->szCryptoDevice);
ssl_die();
}
"Init: loaded Crypto Device API `%s'",
mc->szCryptoDevice);
ENGINE_free(e);
}
}
#endif
static void ssl_init_server_check(server_rec *s,
apr_pool_t *p,
{
/*
* check for important parameters and the
* possibility that the user forgot to set them.
*/
"No SSL Certificate set [hint: SSLCertificateFile]");
ssl_die();
}
/*
* Check for problematic re-initializations
*/
#ifndef OPENSSL_NO_EC
#endif
)
{
"Illegal attempt to re-initialise SSL for server "
"(theoretically shouldn't happen!)");
ssl_die();
}
}
#ifndef OPENSSL_NO_TLSEXT
static void ssl_init_ctx_tls_extensions(server_rec *s,
apr_pool_t *p,
{
/*
* Configure TLS extensions support
*/
"Configuring TLS extension handling");
/*
* Server name indication (SNI)
*/
"Unable to initialize TLS servername extension "
"callback (incompatible OpenSSL version?)");
ssl_die();
}
#ifdef HAVE_OCSP_STAPLING
/*
* OCSP Stapling support, status_request extension
*/
}
#endif
}
#endif
static void ssl_init_ctx_protocol(server_rec *s,
apr_pool_t *p,
{
char *cp;
/*
* Create the new per-server SSL context
*/
if (protocol == SSL_PROTOCOL_NONE) {
"No SSL protocols available [hint: SSLProtocol]");
ssl_die();
}
cp = apr_pstrcat(p,
NULL);
"Creating new SSL context (protocols: %s)", cp);
if (protocol == SSL_PROTOCOL_SSLV2) {
SSLv2_client_method() : /* proxy */
SSLv2_server_method(); /* server */
}
else if (protocol == SSL_PROTOCOL_SSLV3) {
SSLv3_client_method() : /* proxy */
SSLv3_server_method(); /* server */
}
else if (protocol == SSL_PROTOCOL_TLSV1) {
TLSv1_client_method() : /* proxy */
TLSv1_server_method(); /* server */
}
else { /* For multiple protocols, we need a flexible method */
SSLv23_client_method() : /* proxy */
SSLv23_server_method(); /* server */
}
if (!(protocol & SSL_PROTOCOL_SSLV2)) {
}
if (!(protocol & SSL_PROTOCOL_SSLV3)) {
}
if (!(protocol & SSL_PROTOCOL_TLSV1)) {
}
}
#endif
}
#endif
SSL_CTX_set_app_data(ctx, s);
/*
* Configure additional context ingredients
*/
/*
* Disallow a session from being resumed during a renegotiation,
* so that an acceptable cipher suite can be negotiated.
*/
#endif
}
static void ssl_init_ctx_session_cache(server_rec *s,
apr_pool_t *p,
{
}
}
static void ssl_init_ctx_callbacks(server_rec *s,
apr_pool_t *p,
{
#ifndef OPENSSL_NO_EC
#endif
}
static void ssl_init_ctx_verify(server_rec *s,
apr_pool_t *p,
{
int verify = SSL_VERIFY_NONE;
}
}
/*
* Configure callbacks for SSL context
*/
}
{
}
/*
* Configure Client Authentication details
*/
"Configuring client authentication");
{
"Unable to configure verify locations "
"for client authentication");
ssl_die();
}
} else
if (!ca_list) {
"Unable to determine list of acceptable "
"CA certificates for client authentication");
ssl_die();
}
}
/*
* Give a warning when no CAs were configured but client authentication
* should take place. This cannot work.
*/
if (sk_X509_NAME_num(ca_list) == 0) {
"Init: Oops, you want to request client "
"authentication, but no CAs are known for "
"verification!? [Hint: SSLCACertificate*]");
}
}
}
static void ssl_init_ctx_cipher_suite(server_rec *s,
apr_pool_t *p,
{
/*
* Configure SSL Cipher Suite
*/
if (!suite) {
return;
}
"Configuring permitted SSL ciphers [%s]",
suite);
"Unable to configure permitted SSL ciphers");
ssl_die();
}
}
static void ssl_init_ctx_crl(server_rec *s,
apr_pool_t *p,
{
/*
* Configure Certificate Revocation List (CRL) Details
*/
return;
}
"Configuring certificate revocation facility");
"Unable to configure X.509 CRL storage "
"for certificate revocation");
ssl_die();
}
}
{
int n;
}
static void ssl_init_ctx_cert_chain(server_rec *s,
apr_pool_t *p,
{
int i, n;
return;
}
/*
* Optionally configure extra server certificate chain certificates.
* This is usually done by OpenSSL automatically when one of the
* server cert issuers are found under SSLCACertificatePath or in
* SSLCACertificateFile. But because these are intended for client
* authentication it can conflict. For instance when you use a
* Global ID server certificate you've to send out the intermediate
* CA certificate, too. When you would just configure this with
* SSLCACertificateFile and also use client authentication mod_ssl
* would accept all clients also issued by this CA. Obviously this
* isn't what we want in this situation. So this feature here exists
* to allow one to explicity configure CA certificates which are
* used only for the server certificate chain.
*/
if (!chain) {
return;
}
skip_first = TRUE;
break;
}
}
(char *)chain,
skip_first, NULL);
if (n < 0) {
"Failed to configure CA certificate chain!");
ssl_die();
}
"Configuring server certificate chain "
"(%d CA certificate%s)",
n, n == 1 ? "" : "s");
}
static void ssl_init_ctx(server_rec *s,
apr_pool_t *p,
{
/* XXX: proxy support? */
#ifndef OPENSSL_NO_TLSEXT
#endif
}
}
static int ssl_server_import_cert(server_rec *s,
const char *id,
int idx)
{
MODSSL_D2I_X509_CONST unsigned char *ptr;
return FALSE;
}
"Configuring %s server certificate", type);
"Unable to import %s server certificate", type);
ssl_die();
}
"Unable to configure %s server certificate", type);
ssl_die();
}
#ifdef HAVE_OCSP_STAPLING
"Unable to configure server certificate for stapling");
}
}
#endif
return TRUE;
}
static int ssl_server_import_key(server_rec *s,
const char *id,
int idx)
{
MODSSL_D2I_PrivateKey_CONST unsigned char *ptr;
int pkey_type;
#ifndef OPENSSL_NO_EC
if (idx == SSL_AIDX_ECC)
else
#endif /* SSL_LIBRARY_VERSION */
return FALSE;
}
"Configuring %s server private key", type);
{
"Unable to import %s server private key", type);
ssl_die();
}
"Unable to configure %s server private key", type);
ssl_die();
}
/*
* XXX: wonder if this is still needed, this is old todo doc.
*/
"Copying DSA parameters from private key to certificate");
}
}
return TRUE;
}
static void ssl_check_public_cert(server_rec *s,
int type)
{
char *cn;
if (!cert) {
return;
}
/*
* Some information about the certificate(s)
*/
if (SSL_X509_isSGC(cert)) {
"%s server certificate enables "
"Server Gated Cryptography (SGC)",
}
if (is_ca) {
"%s server certificate is a CA certificate "
"(BasicConstraints: CA == TRUE !?)",
}
if (pathlen > 0) {
"%s server certificate is not a leaf certificate "
"(BasicConstraints: pathlen == %d > 0 !?)",
}
}
if (apr_fnmatch_test(cn)) {
fnm_flags) == APR_FNM_NOMATCH) {
"%s server certificate wildcard CommonName "
"(CN) `%s' does NOT match server name!?",
}
}
"%s server certificate CommonName (CN) `%s' "
"does NOT match server name!?",
}
}
}
static void ssl_init_server_certs(server_rec *s,
apr_pool_t *p,
{
#ifndef OPENSSL_NO_EC
const char *ecc_id;
#endif
int i;
#ifndef OPENSSL_NO_EC
int have_ecc;
#endif
#ifndef OPENSSL_NO_EC
#endif
#ifndef OPENSSL_NO_EC
#endif
#ifndef OPENSSL_NO_EC
|| have_ecc
#endif
)) {
#ifndef OPENSSL_NO_EC
"Oops, no RSA, DSA or ECC server certificate found "
#else
"Oops, no RSA or DSA server certificate found "
#endif
ssl_die();
}
for (i = 0; i < SSL_AIDX_MAX; i++) {
}
#ifndef OPENSSL_NO_EC
#endif
#ifndef OPENSSL_NO_EC
|| have_ecc
#endif
)) {
#ifndef OPENSSL_NO_EC
"Oops, no RSA, DSA or ECC server private key found?!");
#else
"Oops, no RSA or DSA server private key found?!");
#endif
ssl_die();
}
}
static void ssl_init_proxy_certs(server_rec *s,
apr_pool_t *p,
{
int n, ncerts = 0;
return;
}
sk = sk_X509_INFO_new_null();
}
}
"no client certs found for SSL proxy");
return;
}
/* Check that all client certs have got certificates and private
* keys. */
for (n = 0; n < ncerts; n++) {
"incomplete client cert configured for SSL proxy "
"(missing or encrypted private key?)");
ssl_die();
return;
}
}
"loaded %d client certs for SSL proxy",
ncerts);
}
static void ssl_init_proxy_ctx(server_rec *s,
apr_pool_t *p,
{
}
static void ssl_init_server_ctx(server_rec *s,
apr_pool_t *p,
{
}
/*
* Configure a particular server
*/
void ssl_init_ConfigureServer(server_rec *s,
apr_pool_t *p,
{
/* Initialize the server if SSL is enabled or optional.
*/
"Configuring server for SSL protocol");
}
if (sc->proxy_enabled) {
}
}
{
server_rec *s, *ps;
const char *key;
/*
* Give out warnings when a server has HTTPS configured
* for the HTTP port or vice versa
*/
for (s = base_server; s; s = s->next) {
sc = mySrvConfig(s);
"Init: (%s) You configured HTTPS(%d) "
"on the standard HTTP(%d) port!",
ssl_util_vhostid(p, s),
}
"Init: (%s) You configured HTTP(%d) "
"on the standard HTTPS(%d) port!",
ssl_util_vhostid(p, s),
}
}
/*
* Give out warnings when more than one SSL-aware virtual server uses the
* same IP:port. This doesn't work because mod_ssl then will always use
* just the certificate/keys of one virtual host (which one cannot be said
* easily - but that doesn't matter here).
*/
table = apr_hash_make(p);
for (s = base_server; s; s = s->next) {
char *addr;
sc = mySrvConfig(s);
continue;
}
#ifdef OPENSSL_NO_TLSEXT
#else
#endif
0,
#ifdef OPENSSL_NO_TLSEXT
#else
#endif
"%s (%s:%d) vs. %s (%s:%d)",
ssl_util_vhostid(p, s),
s->defn_line_number,
ssl_util_vhostid(p, ps),
continue;
}
}
if (conflict) {
#ifdef OPENSSL_NO_TLSEXT
"Init: You should not use name-based "
"virtual hosts in conjunction with SSL!!");
#else
"Init: Name-based SSL virtual hosts only "
"work for clients with TLS server name indication "
"support (RFC 4366)");
#endif
}
}
#ifdef SSLC_VERSION_NUMBER
static int ssl_init_FindCAList_X509NameCmp(char **a, char **b)
{
return(X509_NAME_cmp((void*)*a, (void*)*b));
}
#else
static int ssl_init_FindCAList_X509NameCmp(const X509_NAME * const *a,
const X509_NAME * const *b)
{
return(X509_NAME_cmp(*a, *b));
}
#endif
server_rec *s, const char *file)
{
int n;
if (!sk) {
return;
}
for (n = 0; n < sk_X509_NAME_num(sk); n++) {
char name_buf[256];
"CA certificate: %s",
/*
* note that SSL_load_client_CA_file() checks for duplicates,
* but since we call it multiple times when reading a directory
* we must also check for duplicates ourselves.
*/
/* this will be freed when ca_list is */
}
else {
/* need to free this ourselves, else it will leak */
}
}
}
const char *ca_file,
const char *ca_path)
{
/*
* entries get added in sorted order.
*/
/*
* Process CA certificate bundle file
*/
if (ca_file) {
}
/*
* Process CA certificate path files
*/
if (ca_path) {
"Failed to open Certificate Path `%s'",
ca_path);
ssl_die();
}
const char *file;
continue; /* don't try to load directories */
}
}
}
/*
* Cleanup
*/
return ca_list;
}
{
/* XXX: there should be an ap_srand() function */
/* open the mutex lockfile */
ssl_mutex_reinit(s, p);
#ifdef HAVE_OCSP_STAPLING
ssl_stapling_mutex_reinit(s, p);
#endif
}
if (item) { \
}
{
}
{
}
}
{
int i;
for (i=0; i < SSL_AIDX_MAX; i++) {
}
}
{
server_rec *s;
/*
* Drop the session cache and mutex
*/
/*
* Destroy the temporary keys and params
*/
/*
* Free the non-pool allocated structures
* in the per-server configurations
*/
for (s = base_server; s; s = s->next) {
sc = mySrvConfig(s);
}
return APR_SUCCESS;
}