1 | /* |
---|
2 | * Copyright 2004-2005 Paul Querna |
---|
3 | * Copyright 2014 Nikos Mavrogiannopoulos |
---|
4 | * Copyright 2015-2016 Fiona Klute |
---|
5 | * |
---|
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
7 | * you may not use this file except in compliance with the License. |
---|
8 | * You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | */ |
---|
18 | |
---|
19 | /** |
---|
20 | * @file |
---|
21 | * |
---|
22 | * Generic object cache for mod_gnutls. |
---|
23 | */ |
---|
24 | |
---|
25 | #ifndef __MOD_GNUTLS_CACHE_H__ |
---|
26 | #define __MOD_GNUTLS_CACHE_H__ |
---|
27 | |
---|
28 | #include "mod_gnutls.h" |
---|
29 | #include <httpd.h> |
---|
30 | |
---|
31 | /** Name of the mod_gnutls cache access mutex, for use with Apache's |
---|
32 | * `Mutex` directive */ |
---|
33 | #define MGS_CACHE_MUTEX_NAME "gnutls-cache" |
---|
34 | |
---|
35 | /** |
---|
36 | * Initialize the internal cache configuration structure. This |
---|
37 | * function is called after the configuration file(s) have been |
---|
38 | * parsed. |
---|
39 | * |
---|
40 | * @param p configuration memory pool |
---|
41 | * @param s default server of the Apache configuration, head of the |
---|
42 | * server list |
---|
43 | * @param sc mod_gnutls data associated with `s` |
---|
44 | */ |
---|
45 | int mgs_cache_post_config(apr_pool_t *p, server_rec *s, mgs_srvconf_rec *sc); |
---|
46 | |
---|
47 | /** |
---|
48 | * (Re-)Initialize the cache in a child process after forking. |
---|
49 | * |
---|
50 | * @param p child memory pool provided by Apache |
---|
51 | * @param s default server of the Apache configuration, head of the |
---|
52 | * server list |
---|
53 | * @param sc mod_gnutls data associated with `s` |
---|
54 | */ |
---|
55 | int mgs_cache_child_init(apr_pool_t *p, server_rec *s, mgs_srvconf_rec *sc); |
---|
56 | |
---|
57 | /** |
---|
58 | * Set up caching for the given TLS session. |
---|
59 | * |
---|
60 | * @param ctxt mod_gnutls session context |
---|
61 | * |
---|
62 | * @return 0 |
---|
63 | */ |
---|
64 | int mgs_cache_session_init(mgs_handle_t *ctxt); |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | /** |
---|
69 | * Convert a `time_t` into a null terminated string in a format |
---|
70 | * compatible with OpenSSL's `ASN1_TIME_print()`. |
---|
71 | * |
---|
72 | * @param t time_t time |
---|
73 | * @param str Location to store the time string |
---|
74 | * @param strsize The maximum length that can be stored in `str` |
---|
75 | * |
---|
76 | * @return `str` |
---|
77 | */ |
---|
78 | char *mgs_time2sz(time_t t, char *str, int strsize); |
---|
79 | |
---|
80 | /** |
---|
81 | * Generic store function for the mod_gnutls object cache. |
---|
82 | * |
---|
83 | * @param s server associated with the cache entry |
---|
84 | * @param key key for the cache entry |
---|
85 | * @param data data to be cached |
---|
86 | * @param expiry expiration time |
---|
87 | * |
---|
88 | * @return `-1` on error, `0` on success |
---|
89 | */ |
---|
90 | typedef int (*cache_store_func)(server_rec *s, gnutls_datum_t key, |
---|
91 | gnutls_datum_t data, apr_time_t expiry); |
---|
92 | /** |
---|
93 | * Generic fetch function for the mod_gnutls object cache. |
---|
94 | * |
---|
95 | * *Warning*: The `data` element of the returned `gnutls_datum_t` is |
---|
96 | * allocated using `gnutls_malloc()` for compatibility with the GnuTLS |
---|
97 | * session caching API, and must be released using `gnutls_free()`. |
---|
98 | * |
---|
99 | * @param ctxt mod_gnutls session context for the request |
---|
100 | * @param key key for the cache entry to be fetched |
---|
101 | * |
---|
102 | * @return the requested cache entry, or `{NULL, 0}` |
---|
103 | */ |
---|
104 | typedef gnutls_datum_t (*cache_fetch_func)(mgs_handle_t *ctxt, |
---|
105 | gnutls_datum_t key); |
---|
106 | /** |
---|
107 | * Internal cache configuration structure |
---|
108 | */ |
---|
109 | struct mgs_cache { |
---|
110 | /** Store function for this cache */ |
---|
111 | cache_store_func store; |
---|
112 | /** Fetch function for this cache */ |
---|
113 | cache_fetch_func fetch; |
---|
114 | /** Mutex for cache access (used only if the cache type is not |
---|
115 | * thread-safe) */ |
---|
116 | apr_global_mutex_t *mutex; |
---|
117 | }; |
---|
118 | |
---|
119 | #endif /** __MOD_GNUTLS_CACHE_H__ */ |
---|