Apache HTTPD
ssl_scache.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* _ _
18 * _ __ ___ ___ __| | ___ ___| | mod_ssl
19 * | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
20 * | | | | | | (_) | (_| | \__ \__ \ |
21 * |_| |_| |_|\___/ \__,_|___|___/___/_|
22 * |_____|
23 * ssl_scache.c
24 * Session Cache Abstraction
25 */
26 /* ``Open-Source Software: generous
27 programmers from around the world all
28 join forces to help you shoot
29 yourself in the foot for free.''
30 -- Unknown */
31#include "ssl_private.h"
32#include "mod_status.h"
33
34/* _________________________________________________________________
35**
36** Session Cache: Common Abstraction Layer
37** _________________________________________________________________
38*/
39
41{
43 apr_status_t rv;
45
46 /* The very first invocation of this function will be the
47 * post_config invocation during server startup; do nothing for
48 * this first (and only the first) time through, since the pool
49 * will be immediately cleared anyway. For every subsequent
50 * invocation, initialize the configured cache. */
52 return APR_SUCCESS;
53
54#ifdef HAVE_OCSP_STAPLING
55 if (mc->stapling_cache) {
56 memset(&hints, 0, sizeof hints);
57 hints.avg_obj_size = 1500;
58 hints.avg_id_len = 20;
59 hints.expiry_interval = 300;
60
61 rv = mc->stapling_cache->init(mc->stapling_cache_context,
62 "mod_ssl-staple", &hints, s, p);
63 if (rv) {
65 "Could not initialize stapling cache. Exiting.");
66 return ssl_die(s);
67 }
68 }
69#endif
70
71 /*
72 * Warn the user that he should use the session cache.
73 * But we can operate without it, of course.
74 */
75 if (mc->sesscache == NULL) {
77 "Init: Session Cache is not configured "
78 "[hint: SSLSessionCache]");
79 return APR_SUCCESS;
80 }
81
82 memset(&hints, 0, sizeof hints);
83 hints.avg_obj_size = 150;
84 hints.avg_id_len = 30;
85 hints.expiry_interval = 30;
86
87 rv = mc->sesscache->init(mc->sesscache_context, "mod_ssl-sess", &hints, s, p);
88 if (rv) {
90 "Could not initialize session cache. Exiting.");
91 return ssl_die(s);
92 }
93
94 return APR_SUCCESS;
95}
96
98{
100
101 if (mc->sesscache) {
102 mc->sesscache->destroy(mc->sesscache_context, s);
103 }
104
105#ifdef HAVE_OCSP_STAPLING
106 if (mc->stapling_cache) {
107 mc->stapling_cache->destroy(mc->stapling_cache_context, s);
108 }
109#endif
110
111}
112
114 apr_time_t expiry, SSL_SESSION *sess,
115 apr_pool_t *p)
116{
118 unsigned char encoded[MODSSL_SESSION_MAX_DER], *ptr;
119 unsigned int len;
120 apr_status_t rv;
121
122 /* Serialise the session. */
124 if (len > sizeof encoded) {
126 "session is too big (%u bytes)", len);
127 return FALSE;
128 }
129
130 ptr = encoded;
131 len = i2d_SSL_SESSION(sess, &ptr);
132
133 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
135 }
136
137 rv = mc->sesscache->store(mc->sesscache_context, s, id, idlen,
138 expiry, encoded, len, p);
139
140 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
142 }
143
144 return rv == APR_SUCCESS ? TRUE : FALSE;
145}
146
148 apr_pool_t *p)
149{
151 unsigned char dest[MODSSL_SESSION_MAX_DER];
152 unsigned int destlen = MODSSL_SESSION_MAX_DER;
153 const unsigned char *ptr;
154 apr_status_t rv;
155
156 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
158 }
159
160 rv = mc->sesscache->retrieve(mc->sesscache_context, s, id, idlen,
161 dest, &destlen, p);
162
163 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
165 }
166
167 if (rv != APR_SUCCESS) {
168 return NULL;
169 }
170
171 ptr = dest;
172
173 return d2i_SSL_SESSION(NULL, &ptr, destlen);
174}
175
177 apr_pool_t *p)
178{
180
181 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
183 }
184
185 mc->sesscache->remove(mc->sesscache_context, s, id, idlen, p);
186
187 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
189 }
190}
191
192/* _________________________________________________________________
193**
194** SSL Extension to mod_status
195** _________________________________________________________________
196*/
198{
200
201 if (mc == NULL || mc->sesscache == NULL)
202 return OK;
203
204 if (!(flags & AP_STATUS_SHORT)) {
205 ap_rputs("<hr>\n", r);
206 ap_rputs("<table cellspacing=0 cellpadding=0>\n", r);
207 ap_rputs("<tr><td bgcolor=\"#000000\">\n", r);
208 ap_rputs("<b><font color=\"#ffffff\" face=\"Arial,Helvetica\">SSL/TLS Session Cache Status:</font></b>\r", r);
209 ap_rputs("</td></tr>\n", r);
210 ap_rputs("<tr><td bgcolor=\"#ffffff\">\n", r);
211 }
212 else {
213 ap_rputs("TLSSessionCacheStatus\n", r);
214 }
215
216 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
218 }
219
220 mc->sesscache->status(mc->sesscache_context, r, flags);
221
222 if (mc->sesscache->flags & AP_SOCACHE_FLAG_NOTMPSAFE) {
224 }
225
226 if (!(flags & AP_STATUS_SHORT)) {
227 ap_rputs("</td></tr>\n", r);
228 ap_rputs("</table>\n", r);
229 }
230
231 return OK;
232}
233
239
const char apr_size_t len
Definition ap_regex.h:187
#define TRUE
Definition abts.h:38
#define FALSE
Definition abts.h:35
request_rec * r
#define OK
Definition httpd.h:456
#define AP_SQ_MS_CREATE_PRE_CONFIG
Definition http_core.h:1047
int ap_state_query(int query_code)
Definition core.c:5378
#define AP_SQ_MAIN_STATE
Definition http_core.h:1030
#define APLOGNO(n)
Definition http_log.h:117
#define APLOG_ERR
Definition http_log.h:67
#define ap_log_error
Definition http_log.h:370
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_WARNING
Definition http_log.h:68
#define APLOG_EMERG
Definition http_log.h:64
static APR_INLINE int ap_rputs(const char *str, request_rec *r)
const char apr_ssize_t int flags
Definition apr_encode.h:168
#define APR_HOOK_MIDDLE
Definition apr_hooks.h:303
apr_memcache_t * mc
#define APR_OPTIONAL_HOOK(ns, name, pfn, aszPre, aszSucc, nOrder)
#define AP_SOCACHE_FLAG_NOTMPSAFE
Definition ap_socache.h:46
apr_status_t ssl_die(server_rec *s)
void ssl_scache_kill(server_rec *s)
Definition ssl_scache.c:97
apr_status_t ssl_scache_init(server_rec *s, apr_pool_t *p)
Definition ssl_scache.c:40
#define IDCONST
void ssl_scache_status_register(apr_pool_t *p)
Definition ssl_scache.c:234
void ssl_scache_remove(server_rec *s, unsigned char *id, int idlen, apr_pool_t *p)
Definition ssl_scache.c:176
SSL_SESSION * ssl_scache_retrieve(server_rec *s, unsigned char *id, int idlen, apr_pool_t *p)
Definition ssl_scache.c:147
#define myModConfig(srv)
int ssl_mutex_off(server_rec *s)
#define UCHAR
unsigned int ssl_scache_store(server_rec *s, unsigned char *id, int idlen, apr_time_t expiry, SSL_SESSION *sess, apr_pool_t *p)
Definition ssl_scache.c:113
#define BOOL
Definition ssl_private.h:81
int ssl_mutex_on(server_rec *s)
#define MODSSL_SESSION_MAX_DER
#define AP_STATUS_SHORT
Definition mod_status.h:32
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_vformatter_buff_t const char va_list ap
Definition apr_lib.h:176
const char * s
Definition apr_strings.h:95
apr_int64_t apr_time_t
Definition apr_time.h:45
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
Status Report Extension Module to Apache.
Internal interfaces private to mod_ssl.
static int ssl_ext_status_hook(request_rec *r, int flags)
Definition ssl_scache.c:197
apr_uint32_t flags
A structure that represents the current request.
Definition httpd.h:845
server_rec * server
Definition httpd.h:851
A structure to store information for each virtual server.
Definition httpd.h:1322