ssl_engine_init.c revision bc8fd1b0b1afdf89b8d28eefa8cd74e26ba97986
/* _ _
** _ __ ___ ___ __| | ___ ___| | 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-2002 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
** _________________________________________________________________
*/
static char *ssl_add_version_component(apr_pool_t *p,
server_rec *s,
char *name)
{
}
return val;
}
static char *version_components[] = {
"SSL_VERSION_PRODUCT",
"SSL_VERSION_INTERFACE",
"SSL_VERSION_LIBRARY",
};
static void ssl_add_version_components(apr_pool_t *p,
server_rec *s)
{
char *vals[sizeof(version_components)/sizeof(char *)];
int i;
for (i=0; version_components[i]; i++) {
vals[i] = ssl_add_version_component(p, s,
version_components[i]);
}
ssl_log(s, SSL_LOG_INFO,
"Server: %s, Interface: %s, Library: %s",
}
/*
* Initialize SSL library
*/
static void ssl_init_SSLLibrary(server_rec *s)
{
ssl_log(s, SSL_LOG_INFO,
"Init: Initializing %s library", SSL_LIBRARY_NAME);
}
/*
* Handle the Temporary RSA Keys and DH Params
*/
}
static void ssl_tmp_keys_free(server_rec *s)
{
}
static void ssl_tmp_key_init_rsa(server_rec *s,
{
{
ssl_log(s, SSL_LOG_ERROR,
"Init: Failed to generate temporary "
"%d bit RSA private key", bits);
ssl_die();
}
}
static void ssl_tmp_key_init_dh(server_rec *s,
{
{
ssl_log(s, SSL_LOG_ERROR,
"Init: Failed to generate temporary "
"%d bit DH parameters", bits);
ssl_die();
}
}
#define MODSSL_TMP_KEY_INIT_RSA(s, bits) \
#define MODSSL_TMP_KEY_INIT_DH(s, bits) \
static void ssl_tmp_keys_init(server_rec *s)
{
ssl_log(s, SSL_LOG_INFO,
"Init: Generating temporary RSA private keys (512/1024 bits)");
MODSSL_TMP_KEY_INIT_RSA(s, 512);
MODSSL_TMP_KEY_INIT_RSA(s, 1024);
ssl_log(s, SSL_LOG_INFO,
"Init: Generating temporary DH parameters (512/1024 bits)");
MODSSL_TMP_KEY_INIT_DH(s, 512);
MODSSL_TMP_KEY_INIT_DH(s, 1024);
}
/*
* Per-module initialization
*/
{
server_rec *s;
/*
* Let us cleanup on restarts and exists
*/
/*
* 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);
/* Fix up stuff that may not have been set */
}
}
}
#ifdef SSL_EXPERIMENTAL_PROXY
}
#endif
}
}
/* Open the dedicated SSL logfile */
ssl_log_open(base_server, s, p);
}
#if APR_HAS_THREADS
#endif
/*
* 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().
*/
/*
* 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.
*/
/*
* SSL external crypto device ("engine") support
*/
#ifdef SSL_EXPERIMENTAL_ENGINE
#endif
/*
* Warn the user that he should use the session cache.
* But we can operate without it, of course.
*/
"Init: Session Cache is not configured "
"[hint: SSLSessionCache]");
}
/*
* initialize the mutex handling
*/
if (!ssl_mutex_init(base_server, p)) {
return HTTP_INTERNAL_SERVER_ERROR;
}
/*
* 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.
*/
continue;
}
ssl_log(s, SSL_LOG_INFO,
"Init: Configuring server %s for SSL protocol",
ssl_util_vhostid(p, s));
/*
* 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.
*/
#ifdef SSL_EXPERIMENTAL_ENGINE
{
ENGINE *e;
if (mc->szCryptoDevice) {
ssl_log(s, SSL_LOG_ERROR,
"Init: Failed to load Crypto Device API `%s'",
mc->szCryptoDevice);
ssl_die();
}
}
if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
ssl_log(s, SSL_LOG_ERROR,
"Init: Failed to enable Crypto Device API `%s'",
mc->szCryptoDevice);
ssl_die();
}
ENGINE_free(e);
}
}
#endif
/*
* Configure a particular server
*/
void ssl_init_ConfigureServer(server_rec *s,
apr_pool_t *p,
{
int verify = SSL_VERIFY_NONE;
char *cp;
unsigned char *ptr;
int i, n;
long cache_mode;
/*
* Create the server host:port string because we need it a lot
*/
/*
* Now check for important parameters and the
* possibility that the user forgot to set them.
*/
if (!sc->szPublicCertFile[0]) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) No SSL Certificate set [hint: SSLCertificateFile]",
vhost_id);
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!)", vhost_id);
ssl_die();
}
/*
* Create the new per-server SSL context
*/
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) No SSL protocols available [hint: SSLProtocol]",
vhost_id);
ssl_die();
}
cp = apr_pstrcat(p,
NULL);
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Creating new SSL context (protocols: %s)",
}
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
*/
}
{
}
/* this callback only logs if SSLLogLevel >= info */
}
/*
* Configure SSL Cipher Suite
*/
if (sc->szCipherSuite) {
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring permitted SSL ciphers [%s]",
"Init: (%s) Unable to configure permitted SSL ciphers",
vhost_id);
ssl_die();
}
}
/*
* Configure Client Authentication details
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring client authentication", vhost_id);
{
"Init: (%s) Unable to configure verify locations "
"for client authentication", vhost_id);
ssl_die();
}
if (!ca_list) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Unable to determine list of available "
"CA certificates for client authentication",
vhost_id);
ssl_die();
}
}
/*
* Configure Certificate Revocation List (CRL) Details
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring certificate revocation facility",
vhost_id);
(char *)sc->szCARevocationPath);
if (!sc->pRevocationStore) {
"Init: (%s) Unable to configure X.509 CRL storage "
"for certificate revocation",
vhost_id);
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) {
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",
vhost_id);
{
"Init: (%s) Unable to import RSA server certificate",
vhost_id);
ssl_die();
}
"Init: (%s) Unable to configure RSA server certificate",
vhost_id);
ssl_die();
}
}
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring DSA server certificate",
vhost_id);
{
"Init: (%s) Unable to import DSA server certificate",
vhost_id);
ssl_die();
}
"Init: (%s) Unable to configure DSA server certificate",
vhost_id);
ssl_die();
}
}
if (!ok) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Ops, no RSA or DSA server certificate found?!",
vhost_id);
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) You have to perform a *full* server restart "
vhost_id);
ssl_die();
}
/*
* Some information about the certificate(s)
*/
for (i = 0; i < SSL_AIDX_MAX; i++) {
if (sc->pPublicCert[i]) {
ssl_log(s, SSL_LOG_INFO,
"Init: (%s) %s server certificate enables "
"Server Gated Cryptography (SGC)",
vhost_id, ssl_asn1_keystr(i));
}
if (is_ca) {
ssl_log(s, SSL_LOG_WARN,
"Init: (%s) %s server certificate "
"is a CA certificate "
"(BasicConstraints: CA == TRUE !?)",
vhost_id, ssl_asn1_keystr(i));
}
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) &&
fnm_flags) == FNM_NOMATCH))
{
ssl_log(s, SSL_LOG_WARN,
"Init: (%s) %s server certificate "
"wildcard CommonName (CN) `%s' "
"does NOT match server name!?",
}
ssl_log(s, SSL_LOG_WARN,
"Init: (%s) %s server certificate "
"CommonName (CN) `%s' "
"does NOT match server name!?",
}
}
}
}
/*
* Configure server private key(s)
*/
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring RSA server private key",
vhost_id);
{
"Init: (%s) Unable to import RSA server private key",
vhost_id);
ssl_die();
}
"Init: (%s) Unable to configure RSA server private key",
vhost_id);
ssl_die();
}
}
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring DSA server private key",
vhost_id);
{
"Init: (%s) Unable to import DSA server private key",
vhost_id);
ssl_die();
}
"Init: (%s) Unable to configure DSA server private key",
vhost_id);
ssl_die();
}
}
if (!ok) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Ops, no RSA or DSA server private key found?!",
vhost_id);
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.
*/
if (sc->szCertificateChain) {
skip_first = TRUE;
break;
}
}
(char *)sc->szCertificateChain,
skip_first, NULL);
if (n < 0) {
ssl_log(s, SSL_LOG_ERROR,
"Init: (%s) Failed to configure CA certificate chain!",
vhost_id);
ssl_die();
}
ssl_log(s, SSL_LOG_TRACE,
"Init: (%s) Configuring server certificate chain "
"(%d CA certificate%s)",
}
}
{
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) {
sc = mySrvConfig(s);
continue;
}
"%s (%s:%d) vs. %s (%s:%d)",
ssl_util_vhostid(p, s),
s->defn_line_number,
ssl_util_vhostid(p, ps),
continue;
}
}
if (conflict) {
"Init: You should not use name-based "
"virtual hosts in conjunction with SSL!!");
}
}
{
return(X509_NAME_cmp(*a, *b));
}
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];
ssl_log(s, SSL_LOG_TRACE,
"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) {
"Init: Failed to open SSLCACertificatePath `%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);
}
if (item) { \
}
{
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) {
int i;
sc = mySrvConfig(s);
for (i=0; i < SSL_AIDX_MAX; i++) {
sc->pPublicCert[i]);
sc->pPrivateKey[i]);
}
}
/*
* Try to kill the internals of the SSL library.
*/
ERR_remove_state(0);
EVP_cleanup();
return APR_SUCCESS;
}