summaryrefslogtreecommitdiffstatsabout
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am16
-rw-r--r--src/gnutls_cache.c88
-rw-r--r--src/mod_gnutls.c4
3 files changed, 59 insertions, 49 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1f1860b..30315a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,13 +9,13 @@ lib_LTLIBRARIES = libmod_gnutls.la
9make_so: $(lib_LTLIBRARIES) 9make_so: $(lib_LTLIBRARIES)
10 @if test ! -L mod_gnutls.so ; then ln -s .libs/libmod_gnutls.so mod_gnutls.so ; fi 10 @if test ! -L mod_gnutls.so ; then ln -s .libs/libmod_gnutls.so mod_gnutls.so ; fi
11 11
12clean: 12clean:
13 rm -f mod_gnutls.so 13 rm -f mod_gnutls.so
14 rm -f *.o *.lo *.la 14 rm -f *.o *.lo *.la
15 rm -fr .libs 15 rm -fr .libs
16 16
17install: make_so 17install: make_so
18 @${APXS_BIN} -i -n svn_view mod_gnutls.so 18 @${APXS_BIN} -i -n gnutls mod_gnutls.so
19 @echo "" 19 @echo ""
20 @echo "" 20 @echo ""
21 @echo "***********************************************" 21 @echo "***********************************************"
@@ -27,15 +27,3 @@ install: make_so
27 @echo "***********************************************" 27 @echo "***********************************************"
28 @echo "" 28 @echo ""
29 29
30activate: make_so
31 @${APXS_BIN} -i -a -n svn_view mod_gnutls.so
32 @echo ""
33 @echo ""
34 @echo "***********************************************"
35 @echo ""
36 @echo " Please read the documentation at "
37 @echo " http://www.outoforder.cc/ for "
38 @echo " details on configuration of this module "
39 @echo ""
40 @echo "***********************************************"
41 @echo ""
diff --git a/src/gnutls_cache.c b/src/gnutls_cache.c
index cee30fa..c1a6f37 100644
--- a/src/gnutls_cache.c
+++ b/src/gnutls_cache.c
@@ -16,8 +16,38 @@
16 */ 16 */
17 17
18#include "mod_gnutls.h" 18#include "mod_gnutls.h"
19
20#if HAVE_APR_MEMCACHE
21#include "apr_memcache.h"
22#endif
23
19#include "ap_mpm.h" 24#include "ap_mpm.h"
20 25
26#define GNUTLS_SESSION_ID_STRING_LEN \
27 ((GNUTLS_MAX_SESSION_ID + 1) * 2)
28#define MC_TAG "mod_gnutls:"
29#define MC_TAG_LEN \
30 (sizeof(MC_TAG))
31#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN)
32
33static char *gnutls_session_id2sz(unsigned char *id, int idlen,
34 char *str, int strsize)
35{
36 char *cp;
37 int n;
38
39 cp = apr_cpystrn(str, MC_TAG, MC_TAG_LEN);
40 for (n = 0; n < idlen && n < GNUTLS_MAX_SESSION_ID; n++) {
41 apr_snprintf(cp, strsize - (cp-str), "%02X", id[n]);
42 cp += 2;
43 }
44 *cp = '\0';
45 return str;
46}
47
48
49#if HAVE_APR_MEMCACHE
50
21/** 51/**
22 * GnuTLS Session Cache using libmemcached 52 * GnuTLS Session Cache using libmemcached
23 * 53 *
@@ -26,7 +56,7 @@
26/* The underlying apr_memcache system is thread safe... woohoo */ 56/* The underlying apr_memcache system is thread safe... woohoo */
27static apr_memcache_t* mc; 57static apr_memcache_t* mc;
28 58
29int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s, 59int mc_cache_child_init(apr_pool_t *p, server_rec *s,
30 mod_gnutls_srvconf_rec *sc) 60 mod_gnutls_srvconf_rec *sc)
31{ 61{
32 apr_status_t rv = APR_SUCCESS; 62 apr_status_t rv = APR_SUCCESS;
@@ -109,32 +139,8 @@ int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s,
109 return rv; 139 return rv;
110} 140}
111 141
112/* thanks mod_ssl */ 142static int mc_cache_store(void* baton, gnutls_datum_t key,
113#define GNUTLS_SESSION_ID_STRING_LEN \ 143 gnutls_datum_t data)
114 ((GNUTLS_MAX_SESSION_ID + 1) * 2)
115#define MC_TAG "mod_gnutls:"
116#define MC_TAG_LEN \
117 (sizeof(MC_TAG))
118#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN)
119
120
121static char *gnutls_session_id2sz(unsigned char *id, int idlen,
122 char *str, int strsize)
123{
124 char *cp;
125 int n;
126
127 cp = apr_cpystrn(str, MC_TAG, MC_TAG_LEN);
128 for (n = 0; n < idlen && n < GNUTLS_MAX_SESSION_ID; n++) {
129 apr_snprintf(cp, strsize - (cp-str), "%02X", id[n]);
130 cp += 2;
131 }
132 *cp = '\0';
133 return str;
134}
135
136
137static int cache_store(void* baton, gnutls_datum_t key, gnutls_datum_t data)
138{ 144{
139 apr_status_t rv = APR_SUCCESS; 145 apr_status_t rv = APR_SUCCESS;
140 mod_gnutls_handle_t *ctxt = baton; 146 mod_gnutls_handle_t *ctxt = baton;
@@ -161,7 +167,7 @@ static int cache_store(void* baton, gnutls_datum_t key, gnutls_datum_t data)
161 return 0; 167 return 0;
162} 168}
163 169
164static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key) 170static gnutls_datum_t mc_cache_fetch(void* baton, gnutls_datum_t key)
165{ 171{
166 apr_status_t rv = APR_SUCCESS; 172 apr_status_t rv = APR_SUCCESS;
167 mod_gnutls_handle_t *ctxt = baton; 173 mod_gnutls_handle_t *ctxt = baton;
@@ -190,7 +196,7 @@ static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key)
190 return data; 196 return data;
191 } 197 }
192 198
193 /* TODO: Eliminate this memcpy. ffs. gnutls-- */ 199 /* TODO: Eliminate this memcpy. gnutls-- */
194 data.data = gnutls_malloc(value_len); 200 data.data = gnutls_malloc(value_len);
195 if (data.data == NULL) 201 if (data.data == NULL)
196 return data; 202 return data;
@@ -201,7 +207,7 @@ static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key)
201 return data; 207 return data;
202} 208}
203 209
204static int cache_delete(void* baton, gnutls_datum_t key) 210static int mc_cache_delete(void* baton, gnutls_datum_t key)
205{ 211{
206 apr_status_t rv = APR_SUCCESS; 212 apr_status_t rv = APR_SUCCESS;
207 mod_gnutls_handle_t *ctxt = baton; 213 mod_gnutls_handle_t *ctxt = baton;
@@ -225,11 +231,27 @@ static int cache_delete(void* baton, gnutls_datum_t key)
225 return 0; 231 return 0;
226} 232}
227 233
234#endif /* have_apr_memcache */
235
236int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s,
237 mod_gnutls_srvconf_rec *sc)
238{
239#if HAVE_APR_MEMCACHE
240 return mc_cache_child_init(p, s, sc);
241#else
242 return 0;
243#endif
244}
245
228int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt) 246int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt)
229{ 247{
230 gnutls_db_set_retrieve_function(ctxt->session, cache_fetch); 248#if HAVE_APR_MEMCACHE
231 gnutls_db_set_remove_function(ctxt->session, cache_delete); 249 gnutls_db_set_retrieve_function(ctxt->session, mc_cache_fetch);
232 gnutls_db_set_store_function(ctxt->session, cache_store); 250 gnutls_db_set_remove_function(ctxt->session, mc_cache_delete);
251 gnutls_db_set_store_function(ctxt->session, mc_cache_store);
233 gnutls_db_set_ptr(ctxt->session, ctxt); 252 gnutls_db_set_ptr(ctxt->session, ctxt);
253#else
254 /* TODO: Alternative Cache Backends */
255#endif
234 return 0; 256 return 0;
235} 257}
diff --git a/src/mod_gnutls.c b/src/mod_gnutls.c
index 833edc2..a1668f3 100644
--- a/src/mod_gnutls.c
+++ b/src/mod_gnutls.c
@@ -124,7 +124,7 @@ static void mod_gnutls_hook_child_init(apr_pool_t *p, server_rec *s)
124 } 124 }
125} 125}
126 126
127static const char *mod_gnutls_hook_http_method(const request_rec * r) 127static const char *mod_gnutls_hook_http_scheme(const request_rec * r)
128{ 128{
129 mod_gnutls_srvconf_rec *sc = 129 mod_gnutls_srvconf_rec *sc =
130 (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> 130 (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server->
@@ -340,7 +340,7 @@ static void gnutls_hooks(apr_pool_t * p)
340 APR_HOOK_MIDDLE); 340 APR_HOOK_MIDDLE);
341 ap_hook_child_init(mod_gnutls_hook_child_init, NULL, NULL, 341 ap_hook_child_init(mod_gnutls_hook_child_init, NULL, NULL,
342 APR_HOOK_MIDDLE); 342 APR_HOOK_MIDDLE);
343 ap_hook_http_method(mod_gnutls_hook_http_method, NULL, NULL, 343 ap_hook_http_scheme(mod_gnutls_hook_http_scheme, NULL, NULL,
344 APR_HOOK_MIDDLE); 344 APR_HOOK_MIDDLE);
345 ap_hook_default_port(mod_gnutls_hook_default_port, NULL, NULL, 345 ap_hook_default_port(mod_gnutls_hook_default_port, NULL, NULL,
346 APR_HOOK_MIDDLE); 346 APR_HOOK_MIDDLE);