2 ** _ __ ___ ___ __| | ___ ___| | mod_ssl
3 ** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
4 ** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
5 ** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
8 ** Session Cache Abstraction
11 /* ====================================================================
12 * The Apache Software License, Version 1.1
14 * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in
26 * the documentation and/or other materials provided with the
29 * 3. The end-user documentation included with the redistribution,
30 * if any, must include the following acknowledgment:
31 * "This product includes software developed by the
32 * Apache Software Foundation (http://www.apache.org/)."
33 * Alternately, this acknowledgment may appear in the software itself,
34 * if and wherever such third-party acknowledgments normally appear.
36 * 4. The names "Apache" and "Apache Software Foundation" must
37 * not be used to endorse or promote products derived from this
38 * software without prior written permission. For written
39 * permission, please contact apache@apache.org.
41 * 5. Products derived from this software may not be called "Apache",
42 * nor may "Apache" appear in their name, without prior written
43 * permission of the Apache Software Foundation.
45 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
49 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * ====================================================================
59 /* ``Open-Source Software: generous
60 programmers from around the world all
61 join forces to help you shoot
62 yourself in the foot for free.''
65 #include "mod_status.h"
67 /* _________________________________________________________________
69 ** Session Cache: Common Abstraction Layer
70 ** _________________________________________________________________
73 void ssl_scache_init(server_rec *s, apr_pool_t *p)
75 SSLModConfigRec *mc = myModConfig(s);
78 * Warn the user that he should use the session cache.
79 * But we can operate without it, of course.
81 if (mc->nSessionCacheMode == SSL_SCMODE_UNSET) {
82 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
83 "Init: Session Cache is not configured "
84 "[hint: SSLSessionCache]");
85 mc->nSessionCacheMode = SSL_SCMODE_NONE;
89 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
90 ssl_scache_dbm_init(s, p);
91 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB) {
93 const char *userdata_key = "ssl_scache_init";
95 apr_pool_userdata_get(&data, userdata_key, s->process->pool);
97 apr_pool_userdata_set((const void *)1, userdata_key,
98 apr_pool_cleanup_null, s->process->pool);
101 ssl_scache_shmcb_init(s, p);
105 void ssl_scache_kill(server_rec *s)
107 SSLModConfigRec *mc = myModConfig(s);
109 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
110 ssl_scache_dbm_kill(s);
111 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
112 ssl_scache_shmcb_kill(s);
116 BOOL ssl_scache_store(server_rec *s, UCHAR *id, int idlen, time_t expiry, SSL_SESSION *sess)
118 SSLModConfigRec *mc = myModConfig(s);
121 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
122 rv = ssl_scache_dbm_store(s, id, idlen, expiry, sess);
123 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
124 rv = ssl_scache_shmcb_store(s, id, idlen, expiry, sess);
128 SSL_SESSION *ssl_scache_retrieve(server_rec *s, UCHAR *id, int idlen)
130 SSLModConfigRec *mc = myModConfig(s);
131 SSL_SESSION *sess = NULL;
133 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
134 sess = ssl_scache_dbm_retrieve(s, id, idlen);
135 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
136 sess = ssl_scache_shmcb_retrieve(s, id, idlen);
140 void ssl_scache_remove(server_rec *s, UCHAR *id, int idlen)
142 SSLModConfigRec *mc = myModConfig(s);
144 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
145 ssl_scache_dbm_remove(s, id, idlen);
146 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
147 ssl_scache_shmcb_remove(s, id, idlen);
151 void ssl_scache_expire(server_rec *s)
153 SSLModConfigRec *mc = myModConfig(s);
155 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
156 ssl_scache_dbm_expire(s);
157 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
158 ssl_scache_shmcb_expire(s);
162 /* _________________________________________________________________
164 ** SSL Extension to mod_status
165 ** _________________________________________________________________
167 static int ssl_ext_status_hook(request_rec *r, int flags)
169 SSLSrvConfigRec *sc = mySrvConfig(r->server);
171 if (sc == NULL || flags & AP_STATUS_SHORT)
174 ap_rputs("<hr>\n", r);
175 ap_rputs("<table cellspacing=0 cellpadding=0>\n", r);
176 ap_rputs("<tr><td bgcolor=\"#000000\">\n", r);
177 ap_rputs("<b><font color=\"#ffffff\" face=\"Arial,Helvetica\">SSL/TLS Session Cache Status:</font></b>\r", r);
178 ap_rputs("</td></tr>\n", r);
179 ap_rputs("<tr><td bgcolor=\"#ffffff\">\n", r);
181 if (sc->mc->nSessionCacheMode == SSL_SCMODE_DBM)
182 ssl_scache_dbm_status(r, flags, r->pool);
183 else if (sc->mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
184 ssl_scache_shmcb_status(r, flags, r->pool);
186 ap_rputs("</td></tr>\n", r);
187 ap_rputs("</table>\n", r);
191 void ssl_scache_status_register(apr_pool_t *p)
193 APR_OPTIONAL_HOOK(ap, status_hook, ssl_ext_status_hook, NULL, NULL,