mod_ssl.c revision caaa9b08da1d1cc30fe9160109b883561e574932
/* _ _
** _ __ ___ ___ __| | ___ ___| | mod_ssl
** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
** |_____|
** mod_ssl.c
** Apache API interface structures
*/
/* ====================================================================
* 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.
* ====================================================================
*/
#include "mod_ssl.h"
#include "util_md5.h"
#include <assert.h>
/*
* the table of configuration directives we provide
*/
#define AP_END_CMD { NULL }
static const command_rec ssl_config_cmds[] = {
/*
* Global (main-server) context configuration directives
*/
"SSL lock for handling internal mutual exclusions "
"SSL dialog mechanism for the pass phrase query "
"SSL Session Cache storage "
#ifdef SSL_EXPERIMENTAL_ENGINE
"SSL external Crypto Device usage "
"(`builtin', `...')")
#endif
"SSL Pseudo Random Number Generator (PRNG) seeding source "
"(`startup|connect builtin|file:/path|exec:/path [bytes]')")
/*
* Per-server context configuration directives
*/
"SSL switch for the protocol engine "
"(`on', `off')")
"Colon-delimited list of permitted SSL Ciphers "
"(`XXX:...:XXX' - see manual)")
"SSL Server Certificate file "
"SSL Server Private Key file "
"SSL Server CA Certificate Chain file "
#ifdef SSL_EXPERIMENTAL_PERDIRCA
"SSL CA Certificate path "
"SSL CA Certificate file "
#else
"SSL CA Certificate path "
"SSL CA Certificate file "
#endif
"SSL CA Certificate Revocation List (CRL) path "
"SSL CA Certificate Revocation List (CRL) file "
"SSL Client verify type "
"(`none', `optional', `require', `optional_no_ca')")
"SSL Client verify depth "
"(`N' - number of intermediate certificates)")
"SSL Session Cache object lifetime "
"(`N' - number of seconds)")
"SSL logfile for SSL-related messages "
"SSL logfile verbosity level "
"(`none', `error', `warn', `info', `debug')")
"Enable or disable various SSL protocols"
"(`[+-][SSLv2|SSLv3|TLSv1] ...' - see manual)")
#ifdef SSL_EXPERIMENTAL_PROXY
/*
* Proxy configuration for remote SSL connections
*/
"SSL Proxy: enable or disable SSL protocol flavors "
"(`[+-][SSLv2|SSLv3|TLSv1] ...' - see manual)")
"SSL Proxy: colon-delimited list of permitted SSL ciphers "
"(`XXX:...:XXX' - see manual)")
"SSL Proxy: whether to verify the remote certificate "
"(`on' or `off')")
"SSL Proxy: maximum certificate verification depth "
"(`N' - number of intermediate certificates)")
"SSL Proxy: file containing server certificates "
"SSL Proxy: directory containing server certificates "
"SSL Proxy: file containing client certificates "
"SSL Proxy: directory containing client certificates "
#endif
/*
* Per-directory context configuration directives
*/
"Set one or more options to configure the SSL engine"
"(`[+-]option[=value] ...' - see manual)")
"Require the SSL protocol for the per-directory context "
"(no arguments)")
"Require a boolean expression to evaluate to true for granting access"
"(arbitrary complex boolean expression - see manual)")
};
/*
* the various processing hooks
*/
static void ssl_hook_pre_config(
{
}
static int ssl_hook_pre_connection(conn_rec *c)
{
unsigned char *cpVHostID;
char *cpVHostMD5;
/*
* Create SSL context
*/
/*
* Immediately stop processing if SSL is disabled for this connection
*/
return DECLINED;
/*
* Remember the connection information for
* later access inside callback functions
*/
/*
* Seed the Pseudo Random Number Generator (PRNG)
*/
/*
* Create a new SSL connection with the configured server SSL context and
* attach this to the socket. Additionally we register this attachment
* so we can detach later.
*/
"Unable to create a new SSL connection from the SSL context");
c->aborted = 1;
return DECLINED; /* XXX */
}
strlen(cpVHostMD5))) {
"Unable to set session id context to `%s'", cpVHostMD5);
c->aborted = 1;
return DECLINED; /* XXX */
}
SSL_set_app_data(ssl, c);
/*
* Configure callbacks for SSL connection
*/
#if 0 /* XXX */
}
#endif
/*
* Predefine some client verification results
*/
/*
* We have to manage a I/O timeout ourself, because Apache
* does it the first time when reading the request, but we're
* working some time before this happens.
*/
#if 0 /* XXX */
#endif
ssl_io_filter_init(c, ssl);
return APR_SUCCESS;
}
{
/*
* try to gracefully shutdown the connection:
* - send an own shutdown message (be gracefully)
* - don't wait for peer's shutdown message (deadloop)
* - kick away the SSL stuff immediately
* - block the socket, so Apache cannot operate any more
*/
c->aborted = 1;
return APR_EGENERAL;
}
/*
* The hook is NOT registered with ap_hook_process_connection. Instead, it is
* called manually from the churn () before it tries to read any data.
* There is some problem if I accept conn_rec *. Still investigating..
* Adv. if conn_rec * can be accepted is we can hook this function using the
* ap_hook_process_connection hook.
*/
{
int n, err;
char *cp;
{
/*
* The case where the connection was closed before any data
* was transferred. That's not a real error and can occur
* sporadically with some clients.
*/
"SSL handshake stopped: connection was closed");
}
else if (err == SSL_ERROR_WANT_READ) {
/*
* This is in addition to what was present earlier. It is
* borrowed from openssl_state_machine.c [mod_tls].
* TBD.
*/
return 0;
}
/*
* The case where OpenSSL has recognized a HTTP request:
* This means the client speaks plain HTTP on our HTTPS port.
* Hmmmm... At least for this error we can be more friendly
* and try to provide him with a HTML error page. We have only
* one problem:OpenSSL has already read some bytes from the HTTP
* request. So we have to skip the request line manually and
* instead provide a faked one in order to continue the internal
* Apache processing.
*
*/
#if 0 /* XXX */
/*
* Still need to be ported to Apache 2.0 style
*/
char ca[2];
int rv;
/* log the situation */
"SSL handshake failed: HTTP spoken on HTTPS port; "
"trying to send HTML error page");
/* first: skip the remaining bytes of the request line */
do {
do {
/* second: fake the request line */
#else
"SSL handshake failed: HTTP spoken on HTTPS port");
#endif
}
== (void *)TRUE) {
"SSL handshake timed out (client %s, server %s)",
}
if (errno > 0)
ssl_log(c->base_server,
"SSL handshake interrupted by system "
"[Hint: Stop button pressed in browser?!]");
else
ssl_log(c->base_server,
"Spurious SSL handshake interrupt [Hint: "
"Usually just one of those OpenSSL confusions!?]");
}
else {
/*
* Ok, anything else is a fatal error
*/
ssl_log(c->base_server,
"SSL handshake failed (server %s, client %s)",
}
}
/*
* Check for failed client authentication
*/
"SSL client authentication failed: %s",
}
/*
* Remember the peer certificate's DN
*/
}
/*
* Make really sure that when a peer certificate
* is required we really got one... (be paranoid)
*/
"No acceptable peer certificate available");
}
}
return APR_SUCCESS;
}
static const char *ssl_hook_http_method (const request_rec *r)
{
return NULL;
return "https";
}
{
return 0;
return 443;
}
/*
* the module registration phase
*/
static void ssl_register_hooks(apr_pool_t *p)
{
}
ssl_config_perdir_create, /* create per-dir config structures */
ssl_config_perdir_merge, /* merge per-dir config structures */
ssl_config_server_create, /* create per-server config structures */
ssl_config_server_merge, /* merge per-server config structures */
ssl_config_cmds, /* table of configuration directives */
ssl_register_hooks /* register hooks */
};