ssl_scache_dc.c revision cf9ada3713548ca11de76ff801839b79c879d380
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Copyright 2004-2005 The Apache Software Foundation or its licensors, as
842ae4bd224140319ae7feec1872b93dfd491143fielding * applicable.
842ae4bd224140319ae7feec1872b93dfd491143fielding * Licensed under the Apache License, Version 2.0 (the "License");
842ae4bd224140319ae7feec1872b93dfd491143fielding * you may not use this file except in compliance with the License.
842ae4bd224140319ae7feec1872b93dfd491143fielding * You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * _ __ ___ ___ __| | ___ ___| | mod_ssl
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * | | | | | | (_) | (_| | \__ \__ \ |
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * |_| |_| |_|\___/ \__,_|___|___/___/_|
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * Distributed Session Cache (client support)
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* Only build this code if it's enabled at configure-time. */
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding#if !defined(DISTCACHE_CLIENT_API) || (DISTCACHE_CLIENT_API < 0x0001)
2d2eda71267231c2526be701fe655db125852c1ffielding#error "You must compile with a more recent version of the distcache-base package"
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * This cache implementation allows modssl to access 'distcache' servers (or
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * proxies) to facilitate distributed session caching. It is based on code
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * released as open source by Cryptographic Appliances Inc, and was developed by
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * Geoff Thorpe, Steve Robb, and Chris Zimmerman.
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb** High-Level "handlers" as per ssl_scache.c
2d2eda71267231c2526be701fe655db125852c1ffieldingvoid ssl_scache_dc_init(server_rec *s, apr_pool_t *p)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Create a session context
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "SSLSessionCache required");
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz /* If a "persistent connection" mode of operation is preferred, you *must*
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz * also use the PIDCHECK flag to ensure fork()'d processes don't interlace
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz * comms on the same connection as each other. */
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz#define SESSION_CTX_FLAGS SESSION_CTX_FLAG_PERSISTENT | \
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp /* This mode of operation will open a temporary connection to the 'target'
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp * for each cache operation - this makes it safe against fork()
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp * automatically. This mode is preferred when running a local proxy (over
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp * unix domain sockets) because overhead is negligable and it reduces the
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp * performance/stability danger of file-descriptor bloatage. */
bfb62a96023822c56c9120e4ee627d4091cc59c2rbb ctx = DC_CTX_new(mc->szSessionCacheDataFile, SESSION_CTX_FLAGS);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache failed to obtain context");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "distributed scache context initialised");
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * Success ...
2d2eda71267231c2526be701fe655db125852c1ffieldingBOOL ssl_scache_dc_store(server_rec *s, UCHAR *id, int idlen,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* Serialise the SSL_SESSION object */
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein if ((der_len = i2d_SSL_SESSION(pSession, NULL)) > SSL_SESSION_MAX_DER)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* !@#$%^ - why do we deal with *absolute* time anyway??? */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* Send the serialised session to the distributed cache context */
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'add_session' failed");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "distributed scache 'add_session' successful");
61fd0cab072a05b855cbef9c585702401ac5ae29rbbSSL_SESSION *ssl_scache_dc_retrieve(server_rec *s, UCHAR *id, int idlen)
c9a95767fbf0f5fb0976a06b97a256033925e433rbb unsigned int der_len;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb /* Retrieve any corresponding session from the distributed cache context */
c9a95767fbf0f5fb0976a06b97a256033925e433rbb if (!DC_CTX_get_session(ctx, id, idlen, der, SSL_SESSION_MAX_DER,
c9a95767fbf0f5fb0976a06b97a256033925e433rbb ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "distributed scache 'get_session' MISS");
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'get_session' OVERFLOW");
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'get_session' CORRUPT");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "distributed scache 'get_session' HIT");
61fd0cab072a05b855cbef9c585702401ac5ae29rbbvoid ssl_scache_dc_remove(server_rec *s, UCHAR *id, int idlen)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* Remove any corresponding session from the distributed cache context */
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' MISS");
3d96ee83babeec32482c9082c9426340cee8c44dwrowe ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'remove_session' HIT");
61fd0cab072a05b855cbef9c585702401ac5ae29rbbvoid ssl_scache_dc_status(request_rec *r, int flags, apr_pool_t *pool)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb "distributed scache 'ssl_scache_dc_status'");
742318b93e89c311f66b55f426c4d9cf2c14628bjim ap_rprintf(r, "cache type: <b>DC (Distributed Cache)</b>, "