ssl_engine_init.c revision 726be39314e1b2ede8378630efccce4cdeb88a31
/* _ _
** _ __ ___ ___ __| | ___ ___| | mod_ssl
** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
** |_____|
** Initialization of Servers
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*/
/* ``Recursive, adj.;
see Recursive.''
-- Unknown */
#include "mod_ssl.h"
/* _________________________________________________________________
**
** Module Initialization
** _________________________________________________________________
*/
/*
* Per-module initialization
*/
{
server_rec *s2;
char *cp;
/*
* Let us cleanup on restarts and exists
*/
/*
* Any init round fixes the global config
*/
ssl_config_global_create(s); /* just to avoid problems */
mc->nInitCount++;
/*
* try to fix the configuration and open the dedicated SSL
* logfile as early as possible
*/
/* Fix up stuff that may not have been set */
#ifdef SSL_EXPERIMENTAL_PROXY
#endif
/* Open the dedicated SSL logfile */
ssl_log_open(s, s2, p);
}
/*
* Identification
*/
}
/*
* Initialization round information
*/
else
/*
* The initialization phase inside the Apache API is totally bogus.
* We actually have three non-trivial problems:
*
* 1. Under Unix the API does a 2-round initialization of modules while
* under Win32 it doesn't. This means we have to make sure that at
* least the pass phrase dialog doesn't occur twice. We overcome this
* problem by using a counter (mc->nInitCount) which has to
* survive the init rounds.
*
* 2. Between the first and the second round Apache detaches from
* the terminal under Unix. This means that our pass phrase dialog
* _has_ to be done in the first round and _cannot_ be done in the
* second round.
*
* 3. When Dynamic Shared Object (DSO) mechanism is used under Unix the
* module segment (code & data) gets unloaded and re-loaded between
* the first and the second round. This means no global data survives
* between first and the second init round. We overcome this by using
* an entry ("ssl_module") inside the process_rec->pool->user_data.
*
* The situation as a table:
*
* (-DSHARED_MODULE) (-DWIN32)
* ----------- ----------------- --------- -----------------------------------
* - load module - -
* init init init SSL library init, Pass Phrase Dialog
* detach detach - -
* - reload module - -
* init init - SSL library init, mod_ssl init
*
* Ok, now try to solve this totally ugly situation...
*/
#ifdef SHARED_MODULE
#else
}
#endif
#if APR_HAS_THREADS
ssl_util_thread_setup(s, p);
#endif
ssl_pphrase_Handle(s, p);
ssl_init_TmpKeysHandle(SSL_TKP_GEN, s, p);
return;
}
/*
* SSL external crypto device ("engine") support
*/
#ifdef SSL_EXPERIMENTAL_ENGINE
ssl_init_Engine(s, p);
#endif
/*
* Warn the user that he should use the session cache.
* But we can operate without it, of course.
*/
ssl_log(s, SSL_LOG_WARN,
"Init: Session Cache is not configured [hint: SSLSessionCache]");
}
/*
* initialize the mutex handling and session caching
*/
ssl_mutex_init(s, p);
ssl_scache_init(s, p);
/*
* Seed the Pseudo Random Number Generator (PRNG)
*/
/*
* allocate the temporary RSA keys and DH params
*/
ssl_init_TmpKeysHandle(SSL_TKP_ALLOC, s, p);
/*
* initialize servers
*/
/*
* Either now skip this server when SSL is disabled for
* it or give out some information about what we're
* configuring.
*/
continue;
"Init: Configuring server %s for SSL protocol",
ssl_util_vhostid(p, s2));
/*
* Read the server certificate and key
*/
}
/*
* Configuration consistency checks
*/
ssl_init_CheckServers(s, p);
/*
* Announce mod_ssl and SSL library in HTTP Server field
*/
SSL_init_app_data2_idx(); /* for SSL_get_app_data2() at request time */
return;
}
/*
* Initialize SSL library (also already needed for the pass phrase dialog)
*/
void ssl_init_SSLLibrary(void)
{
/* XXX CRYPTO_set_locking_callback(); */
return;
}
/*
* Support for external a Crypto Device ("engine"), usually
* a hardware accellerator card for crypto operations.
*/
#ifdef SSL_EXPERIMENTAL_ENGINE
{
ENGINE *e;
mc->szCryptoDevice);
ssl_die();
}
if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
mc->szCryptoDevice);
ssl_die();
}
ENGINE_free(e);
}
return;
}
#endif
#if SSL_LIBRARY_VERSION >= 0x00907000
#else
#endif
/*
* Handle the Temporary RSA Keys and DH Params
*/
{
unsigned char *ucp;
/* Generate Keys and Params */
if (action == SSL_TKP_GEN) {
/* seed PRNG */
/* generate 512 bit RSA key */
"Init: Failed to generate temporary 512 bit RSA private key");
ssl_die();
}
/* generate 1024 bit RSA key */
"Init: Failed to generate temporary 1024 bit RSA private key");
ssl_die();
}
/* import 512 bit DH param */
ssl_die();
}
/* no need to free dh, it's static */
/* import 1024 bit DH param */
ssl_die();
}
/* no need to free dh, it's static */
}
/* Allocate Keys and Params */
else if (action == SSL_TKP_ALLOC) {
/* allocate 512 bit RSA key */
ssl_die();
}
}
/* allocate 1024 bit RSA key */
ssl_die();
}
}
/* allocate 512 bit DH param */
ssl_die();
}
}
/* allocate 1024 bit DH param */
ssl_die();
}
}
}
/* Free Keys and Params */
else if (action == SSL_TKP_FREE) {
}
}
}
}
}
return;
}
/*
* Configure a particular server
*/
{
int nVerify;
char *cpVHostID;
unsigned char *ucp;
char *cp;
int i, n;
long cache_mode;
/*
* Create the server host:port string because we need it a lot
*/
cpVHostID = ssl_util_vhostid(p, s);
/*
* Now check for important parameters and the
* possibility that the user forgot to set them.
*/
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) No SSL Certificate set [hint: SSLCertificateFile]",
ssl_die();
}
/*
* Check for problematic re-initializations
*/
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Illegal attempt to re-initialise SSL for server "
"(theoretically shouldn't happen!)", cpVHostID);
ssl_die();
}
/*
* Create the new per-server SSL context
*/
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) No SSL protocols available [hint: SSLProtocol]",
ssl_die();
}
ssl_log(s, SSL_LOG_TRACE,
else
SSL_CTX_set_app_data(ctx, s);
/*
* Configure additional context ingredients
*/
}
else {
/* SSL_SESS_CACHE_NO_INTERNAL_LOOKUP will force OpenSSL
* to ignore process local-caching and
*/
}
/*
* Configure callbacks for SSL context
*/
/*
* Configure SSL Cipher Suite
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring permitted SSL ciphers [%s]",
"Init: (%s) Unable to configure permitted SSL ciphers",
ssl_die();
}
}
/*
* Configure Client Authentication details
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring client authentication", cpVHostID);
sc->szCACertificatePath)) {
"Init: (%s) Unable to configure verify locations "
"for client authentication", cpVHostID);
ssl_die();
}
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Unable to determine list of available "
"CA certificates for client authentication", cpVHostID);
ssl_die();
}
}
/*
* Configure Certificate Revocation List (CRL) Details
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring certificate revocation facility", cpVHostID);
if ((sc->pRevocationStore =
"Init: (%s) Unable to configure X.509 CRL storage "
"for certificate revocation", cpVHostID);
ssl_die();
}
}
/*
* Give a warning when no CAs were configured but client authentication
* should take place. This cannot work.
*/
if (sk_X509_NAME_num(skCAList) == 0)
ssl_log(s, SSL_LOG_WARN,
"Init: Ops, you want to request client authentication, "
"but no CAs are known for verification!? "
"[Hint: SSLCACertificate*]");
}
/*
* Configure server certificate(s)
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring RSA server certificate", cpVHostID);
"Init: (%s) Unable to import RSA server certificate",
ssl_die();
}
"Init: (%s) Unable to configure RSA server certificate",
ssl_die();
}
}
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring DSA server certificate", cpVHostID);
"Init: (%s) Unable to import DSA server certificate",
ssl_die();
}
"Init: (%s) Unable to configure DSA server certificate",
ssl_die();
}
}
if (!ok) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Ops, no RSA or DSA server certificate found?!", cpVHostID);
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) You have to perform a *full* server restart when you added or removed a certificate and/or key file", cpVHostID);
ssl_die();
}
/*
* Some information about the certificate(s)
*/
for (i = 0; i < SSL_AIDX_MAX; i++) {
ssl_log(s, SSL_LOG_INFO,
"Init: (%s) %s server certificate enables "
"Server Gated Cryptography (SGC)",
}
if (isca)
ssl_log(s, SSL_LOG_WARN,
"Init: (%s) %s server certificate is a CA certificate "
"(BasicConstraints: CA == TRUE !?)",
if (pathlen > 0)
ssl_log(s, SSL_LOG_WARN,
"Init: (%s) %s server certificate is not a leaf certificate "
"(BasicConstraints: pathlen == %d > 0 !?)",
}
if (apr_is_fnmatch(cp) &&
ssl_log(s, SSL_LOG_WARN,
"Init: (%s) %s server certificate wildcard CommonName (CN) `%s' "
"does NOT match server name!?", cpVHostID,
}
ssl_log(s, SSL_LOG_WARN,
"Init: (%s) %s server certificate CommonName (CN) `%s' "
"does NOT match server name!?", cpVHostID,
}
}
}
}
/*
* Configure server private key(s)
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring RSA server private key", cpVHostID);
"Init: (%s) Unable to import RSA server private key",
ssl_die();
}
"Init: (%s) Unable to configure RSA server private key",
ssl_die();
}
}
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring DSA server private key", cpVHostID);
"Init: (%s) Unable to import DSA server private key",
ssl_die();
}
"Init: (%s) Unable to configure DSA server private key",
ssl_die();
}
}
if (!ok) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Ops, no RSA or DSA server private key found?!", cpVHostID);
ssl_die();
}
/*
* Optionally copy DSA parameters for certificate from private key
*/
}
/*
* 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.
*/
bSkipFirst = FALSE;
bSkipFirst = TRUE;
break;
}
}
bSkipFirst, NULL)) < 0) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Failed to configure CA certificate chain!", cpVHostID);
ssl_die();
}
"server certificate chain (%d CA certificate%s)", cpVHostID,
n, n == 1 ? "" : "s");
}
return;
}
{
server_rec *s;
server_rec **ps;
ssl_ds_table *t;
apr_pool_t *sp;
char *key;
/*
* Give out warnings when a server has HTTPS configured
* for the HTTP port or vice versa
*/
sc = mySrvConfig(s);
"Init: (%s) You configured HTTPS(%d) on the standard HTTP(%d) port!",
"Init: (%s) You configured HTTP(%d) on the standard HTTPS(%d) port!",
}
/*
* 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).
*/
apr_pool_create(&sp, p);
sc = mySrvConfig(s);
continue;
ssl_util_vhostid(p, s),
s->defn_line_number,
ssl_util_vhostid(p, *ps),
(*ps)->defn_line_number);
continue;
}
*ps = s;
}
/* XXX - It was giving some problem earlier - check it out - TBD */
if (bConflict)
"Init: You should not use name-based virtual hosts in conjunction with SSL!!");
return;
}
{
return(X509_NAME_cmp(*a, *b));
}
STACK_OF(X509_NAME) *ssl_init_FindCAList(server_rec *s, apr_pool_t *pp, const char *cpCAfile, const char *cpCApath)
{
char *cp;
apr_pool_t *p;
int n;
/*
* Use a subpool so we don't bloat up the server pool which
* is remains in memory for the complete operation time of
* the server.
*/
/*
* entries get added in sorted order.
*/
/*
* Process CA certificate bundle file
*/
ssl_log(s, SSL_LOG_TRACE,
"CA certificate: %s",
}
}
/*
* Process CA certificate path files
*/
ssl_log(s, SSL_LOG_TRACE,
"CA certificate: %s",
}
}
}
/*
* Cleanup
*/
apr_pool_destroy(p);
return skCAList;
}
{
/* open the mutex lockfile */
ssl_mutex_reinit(s, p);
return;
}
{
/* server_rec *s = (server_rec *)data; */
/* currently nothing to do */
return APR_SUCCESS;
}
{
/*
* Drop the session cache and mutex
*/
ssl_scache_kill(s);
#if 0 /* XXX */
ssl_mutex_kill(s);
#endif
/*
* Destroy the temporary keys and params
*/
/*
* Free the non-pool allocated structures
* in the per-server configurations
*/
sc = mySrvConfig(s);
}
}
}
}
}
}
/*
* Try to kill the internals of the SSL library.
*/
#ifdef SHARED_MODULE
ERR_remove_state(0);
EVP_cleanup();
#endif
return APR_SUCCESS;
}