ssl_engine_init.c revision 434ad3e8e769a6a7a78c15f3ae2f7ae3adbfbb49
/* _ _
** _ __ ___ ___ __| | ___ ___| | 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]);
}
"Server: %s, Interface: %s, Library: %s",
}
/*
* Initialize SSL library
*/
static void ssl_init_SSLLibrary(server_rec *s)
{
"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 int ssl_tmp_key_init_rsa(server_rec *s,
{
{
"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,
{
{
"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;
/*
* 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);
}
}
/*
* Create the server host:port string because we need it a lot
*/
#if 0
/* If sc->enabled is UNSET, then SSL is optional on this vhost */
/* Fix up stuff that may not have been set */
}
#endif
}
}
}
}
/*
* SSL external crypto device ("engine") support
*/
#ifdef SSL_EXPERIMENTAL_ENGINE
#endif
#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.
*/
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;
}
/*
* 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.
*/
#ifdef SSL_EXPERIMENTAL_ENGINE
{
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();
}
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
*/
{
"Illegal attempt to re-initialise SSL for server "
"(theoretically shouldn't happen!)");
ssl_die();
}
}
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 {
SSLv23_client_method() : /* proxy */
SSLv23_server_method(); /* server */
}
if (!(protocol & SSL_PROTOCOL_SSLV2)) {
}
if (!(protocol & SSL_PROTOCOL_SSLV3)) {
}
if (!(protocol & SSL_PROTOCOL_TLSV1)) {
}
SSL_CTX_set_app_data(ctx, s);
/*
* Configure additional context ingredients
*/
}
static void ssl_init_ctx_session_cache(server_rec *s,
apr_pool_t *p,
{
long cache_mode = SSL_SESS_CACHE_OFF;
/* SSL_SESS_CACHE_NO_INTERNAL_LOOKUP will force OpenSSL
* to ignore process local-caching and
*/
}
}
static void ssl_init_ctx_callbacks(server_rec *s,
apr_pool_t *p,
{
if (s->loglevel >= APLOG_DEBUG) {
/* this callback only logs if LogLevel >= info */
}
}
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();
}
if (!ca_list) {
"Unable to determine list of available "
"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();
}
}
static void ssl_init_ctx_cert_chain(server_rec *s,
apr_pool_t *p,
{
int i, n;
/*
* 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? */
}
}
static int ssl_server_import_cert(server_rec *s,
const char *id,
int idx)
{
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();
}
return TRUE;
}
static int ssl_server_import_key(server_rec *s,
const char *id,
int idx)
{
unsigned char *ptr;
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) == 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,
{
int i;
"Oops, no RSA or DSA server certificate found?!");
ssl_die();
}
for (i = 0; i < SSL_AIDX_MAX; i++) {
}
"Oops, no RSA or DSA server private key found?!");
ssl_die();
}
}
static void ssl_init_proxy_certs(server_rec *s,
apr_pool_t *p,
{
int ncerts = 0;
return;
}
sk = sk_X509_INFO_new_null();
}
}
"loaded %d client certs for SSL proxy",
ncerts);
}
else {
"no client certs found for SSL proxy");
}
}
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,
{
/* A bit of a hack, but initialize the server if SSL is optional or
* not.
*/
"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) {
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];
"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 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) { \
}
{
}
{
}
}
{
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);
}
/*
* Try to kill the internals of the SSL library.
*/
ERR_remove_state(0);
EVP_cleanup();
return APR_SUCCESS;
}