]> granicus.if.org Git - apache/blob - modules/ssl/ssl_scache.c
Extend mod_status output to include SSL session cache status
[apache] / modules / ssl / ssl_scache.c
1 /*                      _             _
2 **  _ __ ___   ___   __| |    ___ ___| |  mod_ssl
3 ** | '_ ` _ \ / _ \ / _` |   / __/ __| |  Apache Interface to OpenSSL
4 ** | | | | | | (_) | (_| |   \__ \__ \ |  www.modssl.org
5 ** |_| |_| |_|\___/ \__,_|___|___/___/_|  ftp.modssl.org
6 **                      |_____|
7 **  ssl_scache.c
8 **  Session Cache Abstraction
9 */
10
11 /* ====================================================================
12  * The Apache Software License, Version 1.1
13  *
14  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
15  * reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  *
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  *
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
27  *    distribution.
28  *
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.
35  *
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.
40  *
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.
44  *
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
56  * SUCH DAMAGE.
57  * ====================================================================
58  */
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.''
63                                                  -- Unknown         */
64 #include "mod_ssl.h"
65 #include "mod_status.h"
66
67 /*  _________________________________________________________________
68 **
69 **  Session Cache: Common Abstraction Layer
70 **  _________________________________________________________________
71 */
72
73 void ssl_scache_init(server_rec *s, apr_pool_t *p)
74 {
75     SSLModConfigRec *mc = myModConfig(s);
76
77     /*
78      * Warn the user that he should use the session cache.
79      * But we can operate without it, of course.
80      */
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;
86         return;
87     }
88
89     if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
90         ssl_scache_dbm_init(s, p);
91     else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB) {
92         void *data;
93         const char *userdata_key = "ssl_scache_init";
94
95         apr_pool_userdata_get(&data, userdata_key, s->process->pool);
96         if (!data) {
97             apr_pool_userdata_set((const void *)1, userdata_key,
98                                   apr_pool_cleanup_null, s->process->pool);
99             return;
100         }
101         ssl_scache_shmcb_init(s, p);
102     }
103 }
104
105 void ssl_scache_kill(server_rec *s)
106 {
107     SSLModConfigRec *mc = myModConfig(s);
108
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);
113     return;
114 }
115
116 BOOL ssl_scache_store(server_rec *s, UCHAR *id, int idlen, time_t expiry, SSL_SESSION *sess)
117 {
118     SSLModConfigRec *mc = myModConfig(s);
119     BOOL rv = FALSE;
120
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);
125     return rv;
126 }
127
128 SSL_SESSION *ssl_scache_retrieve(server_rec *s, UCHAR *id, int idlen)
129 {
130     SSLModConfigRec *mc = myModConfig(s);
131     SSL_SESSION *sess = NULL;
132
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);
137     return sess;
138 }
139
140 void ssl_scache_remove(server_rec *s, UCHAR *id, int idlen)
141 {
142     SSLModConfigRec *mc = myModConfig(s);
143
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);
148     return;
149 }
150
151 void ssl_scache_expire(server_rec *s)
152 {
153     SSLModConfigRec *mc = myModConfig(s);
154
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);
159     return;
160 }
161
162 /*  _________________________________________________________________
163 **
164 **  SSL Extension to mod_status
165 **  _________________________________________________________________
166 */
167 static int ssl_ext_status_hook(request_rec *r, int flags)
168 {
169     SSLSrvConfigRec *sc = mySrvConfig(r->server);
170
171     if (sc == NULL || flags & AP_STATUS_SHORT)
172         return OK;
173
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);
180
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);
185     
186     ap_rputs("</td></tr>\n", r);
187     ap_rputs("</table>\n", r);
188     return OK;
189 }
190
191 void ssl_scache_status_register(apr_pool_t *p)
192 {
193     APR_OPTIONAL_HOOK(ap, status_hook, ssl_ext_status_hook, NULL, NULL,
194                       APR_HOOK_MIDDLE);
195 }
196