ssl_engine_ext.c revision d86ef5503dcbc38e87c0e03cd3e1f16458cb6323
e8eb2b9d68adc3024eb1aa9899b902ed5a3fb460Christian Maeder** _ __ ___ ___ __| | ___ ___| | mod_ssl
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian Maeder** Extensions to other Apache parts
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder/* ====================================================================
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * The Apache Software License, Version 1.1
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * Redistribution and use in source and binary forms, with or without
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * modification, are permitted provided that the following conditions
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * 1. Redistributions of source code must retain the above copyright
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * notice, this list of conditions and the following disclaimer.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * 2. Redistributions in binary form must reproduce the above copyright
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * notice, this list of conditions and the following disclaimer in
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * the documentation and/or other materials provided with the
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * distribution.
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder * 3. The end-user documentation included with the redistribution,
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * if any, must include the following acknowledgment:
cf31aaf25d0fe96b0578755e7ee18b732e337343Christian Maeder * "This product includes software developed by the
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * Apache Software Foundation (http://www.apache.org/)."
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * Alternately, this acknowledgment may appear in the software itself,
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * if and wherever such third-party acknowledgments normally appear.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * 4. The names "Apache" and "Apache Software Foundation" must
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * not be used to endorse or promote products derived from this
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * software without prior written permission. For written
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * permission, please contact apache@apache.org.
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder * 5. Products derived from this software may not be called "Apache",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * nor may "Apache" appear in their name, without prior written
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * permission of the Apache Software Foundation.
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
df476f3bf7038997303a1760a9c1ce09be40a05eChristian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * SUCH DAMAGE.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * ====================================================================
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* ``Only those who attempt the absurd
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski can achieve the impossible.''
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski -- Unknown */
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder/* _________________________________________________________________
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** SSL Extensions
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** _________________________________________________________________
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic void ssl_ext_mlc_register(void);
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskistatic void ssl_ext_mr_register(void);
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskistatic void ssl_ext_mp_register(void);
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskistatic void ssl_ext_ms_register(void);
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski/* _________________________________________________________________
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** SSL Extension to mod_log_config
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** _________________________________________________________________
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskistatic char *ssl_ext_mlc_log_c(request_rec *r, char *a);
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskistatic char *ssl_ext_mlc_log_x(request_rec *r, char *a);
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * register us for the mod_log_config function registering phase
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * to establish %{...}c and to be able to expand %{...}x variables.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ap_hook_register("ap::mod_log_config::log_x",
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ap_hook_unregister("ap::mod_log_config::log_c",
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ap_hook_unregister("ap::mod_log_config::log_x",
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * implement the %{..}c log function
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * (we are the only function)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic char *ssl_ext_mlc_log_c(request_rec *r, char *a)
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski if (ap_ctx_get(r->connection->client->ctx, "ssl") == NULL)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_PROTOCOL");
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER");
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder else if (strEQ(a, "subjectdn") || strEQ(a, "clientcert"))
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CLIENT_S_DN");
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder else if (strEQ(a, "issuerdn") || strEQ(a, "cacert"))
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CLIENT_I_DN");
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder result = ap_ctx_get(r->connection->client->ctx, "ssl::verify::error");
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * extend the implementation of the %{..}x log function
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * (there can be more functions)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic char *ssl_ext_mlc_log_x(request_rec *r, char *a)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder if (ap_ctx_get(r->connection->client->ctx, "ssl") != NULL)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder result = ssl_var_lookup(r->pool, r->server, r->connection, r, a);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder/* _________________________________________________________________
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder** SSL Extension to mod_rewrite
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder** _________________________________________________________________
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic char *ssl_ext_mr_lookup_variable(request_rec *r, char *var);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * register us for the mod_rewrite lookup_variable() function
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_register("ap::mod_rewrite::lookup_variable",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ssl_ext_mr_lookup_variable, AP_HOOK_NOCTX);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_unregister("ap::mod_rewrite::lookup_variable",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic char *ssl_ext_mr_lookup_variable(request_rec *r, char *var)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder val = ssl_var_lookup(r->pool, r->server, r->connection, r, var);
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu/* _________________________________________________________________
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu** SSL Extension to mod_proxy
c18a07fe36512679e66faa59274bb273e735738aMihai Codescu** _________________________________________________________________
c18a07fe36512679e66faa59274bb273e735738aMihai Codescustatic int ssl_ext_mp_canon(request_rec *, char *);
da955132262baab309a50fdffe228c9efe68251dCui Jianstatic int ssl_ext_mp_handler(request_rec *, void *, char *, char *, int, char *);
c18a07fe36512679e66faa59274bb273e735738aMihai Codescustatic int ssl_ext_mp_set_destport(request_rec *);
da955132262baab309a50fdffe228c9efe68251dCui Jianstatic char *ssl_ext_mp_new_connection(request_rec *, BUFF *, char *);
c18a07fe36512679e66faa59274bb273e735738aMihai Codescustatic void ssl_ext_mp_close_connection(void *);
c18a07fe36512679e66faa59274bb273e735738aMihai Codescustatic int ssl_ext_mp_write_host_header(request_rec *, BUFF *, char *, int, char *);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic void ssl_ext_mp_init(server_rec *, pool *);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic int ssl_ext_mp_verify_cb(int, X509_STORE_CTX *);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic int ssl_ext_mp_clientcert_cb(SSL *, X509 **, EVP_PKEY **);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * register us ...
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_register("ap::mod_proxy::http::handler::set_destport",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_register("ap::mod_proxy::http::handler::new_connection",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_register("ap::mod_proxy::http::handler::write_host_header",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ssl_ext_mp_write_host_header, AP_HOOK_NOCTX);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_unregister("ap::mod_proxy::init", ssl_ext_mp_init);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_unregister("ap::mod_proxy::canon", ssl_ext_mp_canon);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_unregister("ap::mod_proxy::handler", ssl_ext_mp_handler);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_unregister("ap::mod_proxy::http::handler::set_destport",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_unregister("ap::mod_proxy::http::handler::new_connection",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ap_hook_unregister("ap::mod_proxy::http::handler::write_host_header",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * SSL proxy initialization
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederstatic void ssl_ext_mp_init(server_rec *s, pool *p)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * Initialize each virtual server
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu * Create new SSL context and configure callbacks
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu if (sc->nProxyProtocol == SSL_PROTOCOL_NONE) {
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder "Init: (%s) No Proxy SSL protocols available [hint: SSLProxyProtocol]",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder cp = ap_pstrcat(p, (sc->nProxyProtocol & SSL_PROTOCOL_SSLV2 ? "SSLv2, " : ""),
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder (sc->nProxyProtocol & SSL_PROTOCOL_SSLV3 ? "SSLv3, " : ""),
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu (sc->nProxyProtocol & SSL_PROTOCOL_TLSV1 ? "TLSv1, " : ""), NULL);
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu "Init: (%s) Creating new proxy SSL context (protocols: %s)",
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder if (sc->nProxyProtocol == SSL_PROTOCOL_SSLV2)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ctx = SSL_CTX_new(SSLv2_client_method()); /* only SSLv2 is left */
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ctx = SSL_CTX_new(SSLv23_client_method()); /* be more flexible */
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder "Init: (%s) Unable to create SSL Proxy context", cpVHostID);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder if (!(sc->nProxyProtocol & SSL_PROTOCOL_SSLV2))
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder if (!(sc->nProxyProtocol & SSL_PROTOCOL_SSLV3))
c18a07fe36512679e66faa59274bb273e735738aMihai Codescu if (!(sc->nProxyProtocol & SSL_PROTOCOL_TLSV1))
da955132262baab309a50fdffe228c9efe68251dCui Jian if (sc->szProxyClientCertificateFile || sc->szProxyClientCertificatePath) {
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder SSL_load_CrtAndKeyInfo_file(p, sk, sc->szProxyClientCertificateFile);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder SSL_load_CrtAndKeyInfo_path(p, sk, sc->szProxyClientCertificatePath);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder ssl_log(s, SSL_LOG_TRACE, "Init: (%s) loaded %d client certs for SSL proxy",
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu SSL_CTX_set_client_cert_cb(ctx, ssl_ext_mp_clientcert_cb);
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * Calculate OpenSSL verify type for verifying the remote server
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * certificate. We either verify it against our list of CA's, or don't
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder * bother at all.
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder "Init: (%s) SSLProxyVerify set to On but no CA certificates configured",
ssl_die();
ssl_die();
int rc;
return rc;
return DECLINED;
static int ssl_ext_mp_handler(
int rc;
return rc;
return DECLINED;
return DEFAULT_HTTPS_PORT;
return DEFAULT_HTTP_PORT;
#ifndef SSL_EXPERIMENTAL_PROXY
char *errmsg;
int rc;
char *cpVHostID;
char *cpVHostMD5;
#ifdef SSL_EXPERIMENTAL_PROXY
char *cp;
return NULL;
#ifdef SSL_EXPERIMENTAL_PROXY
#ifdef SSL_EXPERIMENTAL_PROXY
return errmsg;
return errmsg;
#ifdef SSL_EXPERIMENTAL_PROXY
#ifdef SSL_EXPERIMENTAL_PROXY
#ifdef SSL_EXPERIMENTAL_PROXY
return NULL;
return errmsg;
return NULL;
#ifndef SSL_EXPERIMENTAL_PROXY
#ifndef SSL_EXPERIMENTAL_PROXY
#ifndef SSL_EXPERIMENTAL_PROXY
static int ssl_ext_mp_write_host_header(
return DECLINED;
return OK;
return DECLINED;
#ifdef SSL_EXPERIMENTAL_PROXY
char *peer;
char *servername;
server_rec *s;
char *cp;
int errnum;
int errdepth;
server_rec *s;
char *peer;
char *servername;
return ok;
if (!ok) {
return ok;
return (ok);
static void ssl_ext_ms_register(void)
static void ssl_ext_ms_unregister(void)
if (short_report)