1 | /** |
---|
2 | * Copyright 2004-2005 Paul Querna |
---|
3 | * |
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
5 | * you may not use this file except in compliance with the License. |
---|
6 | * 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 | #include "mod_gnutls.h" |
---|
19 | |
---|
20 | #if APR_HAS_THREADS |
---|
21 | GCRY_THREAD_OPTION_PTHREAD_IMPL; |
---|
22 | #endif |
---|
23 | |
---|
24 | static apr_file_t* debug_log_fp; |
---|
25 | |
---|
26 | static apr_status_t mod_gnutls_cleanup_pre_config(void *data) |
---|
27 | { |
---|
28 | gnutls_global_deinit(); |
---|
29 | return APR_SUCCESS; |
---|
30 | } |
---|
31 | |
---|
32 | static void gnutls_debug_log_all( int level, const char* str) |
---|
33 | { |
---|
34 | apr_file_printf(debug_log_fp, "<%d> %s\n", level, str); |
---|
35 | } |
---|
36 | |
---|
37 | static int mod_gnutls_hook_pre_config(apr_pool_t * pconf, |
---|
38 | apr_pool_t * plog, apr_pool_t * ptemp) |
---|
39 | { |
---|
40 | |
---|
41 | #if APR_HAS_THREADS |
---|
42 | /* TODO: Check MPM Type here */ |
---|
43 | gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); |
---|
44 | #endif |
---|
45 | |
---|
46 | gnutls_global_init(); |
---|
47 | |
---|
48 | apr_pool_cleanup_register(pconf, NULL, mod_gnutls_cleanup_pre_config, |
---|
49 | apr_pool_cleanup_null); |
---|
50 | |
---|
51 | apr_file_open(&debug_log_fp, "/tmp/gnutls_debug", |
---|
52 | APR_APPEND|APR_WRITE|APR_CREATE, APR_OS_DEFAULT, pconf); |
---|
53 | |
---|
54 | gnutls_global_set_log_level(9); |
---|
55 | gnutls_global_set_log_function(gnutls_debug_log_all); |
---|
56 | |
---|
57 | return OK; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | static gnutls_datum load_params(const char* file, server_rec* s, |
---|
62 | apr_pool_t* pool) |
---|
63 | { |
---|
64 | gnutls_datum ret = { NULL, 0 }; |
---|
65 | apr_file_t* fp; |
---|
66 | apr_finfo_t finfo; |
---|
67 | apr_status_t rv; |
---|
68 | apr_size_t br = 0; |
---|
69 | |
---|
70 | rv = apr_file_open(&fp, file, APR_READ|APR_BINARY, APR_OS_DEFAULT, |
---|
71 | pool); |
---|
72 | if (rv != APR_SUCCESS) { |
---|
73 | ap_log_error(APLOG_MARK, APLOG_STARTUP, rv, s, |
---|
74 | "GnuTLS failed to load params file at: %s", file); |
---|
75 | return ret; |
---|
76 | } |
---|
77 | |
---|
78 | rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, fp); |
---|
79 | |
---|
80 | if (rv != APR_SUCCESS) { |
---|
81 | ap_log_error(APLOG_MARK, APLOG_STARTUP, rv, s, |
---|
82 | "GnuTLS failed to stat params file at: %s", file); |
---|
83 | return ret; |
---|
84 | } |
---|
85 | |
---|
86 | ret.data = apr_palloc(pool, finfo.size+1); |
---|
87 | rv = apr_file_read_full(fp, ret.data, finfo.size, &br); |
---|
88 | |
---|
89 | if (rv != APR_SUCCESS) { |
---|
90 | ap_log_error(APLOG_MARK, APLOG_STARTUP, rv, s, |
---|
91 | "GnuTLS failed to read params file at: %s", file); |
---|
92 | return ret; |
---|
93 | } |
---|
94 | |
---|
95 | ret.data[br] = '\0'; |
---|
96 | ret.size = br; |
---|
97 | |
---|
98 | return ret; |
---|
99 | } |
---|
100 | |
---|
101 | static int mod_gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, |
---|
102 | apr_pool_t * ptemp, |
---|
103 | server_rec * base_server) |
---|
104 | { |
---|
105 | int rv; |
---|
106 | server_rec *s; |
---|
107 | gnutls_dh_params_t dh_params; |
---|
108 | gnutls_rsa_params_t rsa_params; |
---|
109 | mod_gnutls_srvconf_rec *sc; |
---|
110 | mod_gnutls_srvconf_rec *sc_base; |
---|
111 | void *data = NULL; |
---|
112 | int first_run = 0; |
---|
113 | const char *userdata_key = "mod_gnutls_init"; |
---|
114 | |
---|
115 | apr_pool_userdata_get(&data, userdata_key, base_server->process->pool); |
---|
116 | if (data == NULL) { |
---|
117 | first_run = 1; |
---|
118 | apr_pool_userdata_set((const void *)1, userdata_key, |
---|
119 | apr_pool_cleanup_null, |
---|
120 | base_server->process->pool); |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | if (!first_run) { |
---|
125 | gnutls_datum pdata; |
---|
126 | apr_pool_t* tpool; |
---|
127 | s = base_server; |
---|
128 | sc_base = (mod_gnutls_srvconf_rec *) ap_get_module_config(s->module_config, |
---|
129 | &gnutls_module); |
---|
130 | |
---|
131 | apr_pool_create(&tpool, p); |
---|
132 | |
---|
133 | gnutls_dh_params_init(&dh_params); |
---|
134 | |
---|
135 | pdata = load_params(sc_base->dh_params_file, s, tpool); |
---|
136 | |
---|
137 | if (pdata.size != 0) { |
---|
138 | rv = gnutls_dh_params_import_pkcs3(dh_params, &pdata, |
---|
139 | GNUTLS_X509_FMT_PEM); |
---|
140 | if (rv != 0) { |
---|
141 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
142 | "GnuTLS: Unable to load DH Params: (%d) %s", |
---|
143 | rv, gnutls_strerror(rv)); |
---|
144 | exit(rv); |
---|
145 | } |
---|
146 | } |
---|
147 | else { |
---|
148 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
149 | "GnuTLS: Unable to load DH Params." |
---|
150 | " Shutting Down."); |
---|
151 | exit(-1); |
---|
152 | } |
---|
153 | apr_pool_clear(tpool); |
---|
154 | |
---|
155 | gnutls_rsa_params_init(&rsa_params); |
---|
156 | |
---|
157 | pdata = load_params(sc_base->rsa_params_file, s, tpool); |
---|
158 | |
---|
159 | if (pdata.size != 0) { |
---|
160 | rv = gnutls_rsa_params_import_pkcs1(rsa_params, &pdata, |
---|
161 | GNUTLS_X509_FMT_PEM); |
---|
162 | if (rv != 0) { |
---|
163 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
164 | "GnuTLS: Unable to load RSA Params: (%d) %s", |
---|
165 | rv, gnutls_strerror(rv)); |
---|
166 | exit(rv); |
---|
167 | } |
---|
168 | } |
---|
169 | else { |
---|
170 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
171 | "GnuTLS: Unable to load RSA Params." |
---|
172 | " Shutting Down."); |
---|
173 | exit(-1); |
---|
174 | } |
---|
175 | |
---|
176 | apr_pool_destroy(tpool); |
---|
177 | rv = mod_gnutls_cache_post_config(p, s, sc_base); |
---|
178 | if (rv != 0) { |
---|
179 | ap_log_error(APLOG_MARK, APLOG_STARTUP, rv, s, |
---|
180 | "GnuTLS: Post Config for GnuTLSCache Failed." |
---|
181 | " Shutting Down."); |
---|
182 | exit(-1); |
---|
183 | } |
---|
184 | |
---|
185 | for (s = base_server; s; s = s->next) { |
---|
186 | sc = (mod_gnutls_srvconf_rec *) ap_get_module_config(s->module_config, |
---|
187 | &gnutls_module); |
---|
188 | sc->cache_type = sc_base->cache_type; |
---|
189 | sc->cache_config = sc_base->cache_config; |
---|
190 | |
---|
191 | if (sc->cert_file != NULL && sc->key_file != NULL) { |
---|
192 | |
---|
193 | rv = gnutls_certificate_set_x509_key_file(sc->certs, sc->cert_file, |
---|
194 | sc->key_file, |
---|
195 | GNUTLS_X509_FMT_PEM); |
---|
196 | if (rv != 0) { |
---|
197 | ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, |
---|
198 | "[GnuTLS] - Host '%s:%d' has an invalid key or certificate:" |
---|
199 | "(%s,%s) (%d) %s", |
---|
200 | s->server_hostname, s->port, sc->cert_file, sc->key_file, |
---|
201 | rv, gnutls_strerror(rv)); |
---|
202 | } |
---|
203 | else { |
---|
204 | gnutls_certificate_set_rsa_export_params(sc->certs, |
---|
205 | rsa_params); |
---|
206 | gnutls_certificate_set_dh_params(sc->certs, dh_params); |
---|
207 | } |
---|
208 | } |
---|
209 | else if (sc->enabled == GNUTLS_ENABLED_TRUE) { |
---|
210 | ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, |
---|
211 | "[GnuTLS] - Host '%s:%d' is missing a " |
---|
212 | "Cert and Key File!", |
---|
213 | s->server_hostname, s->port); |
---|
214 | } |
---|
215 | } |
---|
216 | } /* first_run */ |
---|
217 | |
---|
218 | ap_add_version_component(p, "mod_gnutls/" MOD_GNUTLS_VERSION); |
---|
219 | |
---|
220 | return OK; |
---|
221 | } |
---|
222 | |
---|
223 | static void mod_gnutls_hook_child_init(apr_pool_t *p, server_rec *s) |
---|
224 | { |
---|
225 | apr_status_t rv = APR_SUCCESS; |
---|
226 | mod_gnutls_srvconf_rec *sc = ap_get_module_config(s->module_config, |
---|
227 | &gnutls_module); |
---|
228 | |
---|
229 | if (sc->cache_type != mod_gnutls_cache_none) { |
---|
230 | rv = mod_gnutls_cache_child_init(p, s, sc); |
---|
231 | if(rv != APR_SUCCESS) { |
---|
232 | ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, |
---|
233 | "[GnuTLS] - Failed to run Cache Init"); |
---|
234 | } |
---|
235 | } |
---|
236 | else { |
---|
237 | ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, |
---|
238 | "[GnuTLS] - No Cache Configured. Hint: GnuTLSCache"); |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | static const char *mod_gnutls_hook_http_scheme(const request_rec * r) |
---|
243 | { |
---|
244 | mod_gnutls_srvconf_rec *sc = |
---|
245 | (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> |
---|
246 | module_config, |
---|
247 | &gnutls_module); |
---|
248 | |
---|
249 | if (sc->enabled == GNUTLS_ENABLED_FALSE) { |
---|
250 | return NULL; |
---|
251 | } |
---|
252 | |
---|
253 | return "https"; |
---|
254 | } |
---|
255 | |
---|
256 | static apr_port_t mod_gnutls_hook_default_port(const request_rec * r) |
---|
257 | { |
---|
258 | mod_gnutls_srvconf_rec *sc = |
---|
259 | (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> |
---|
260 | module_config, |
---|
261 | &gnutls_module); |
---|
262 | |
---|
263 | if (sc->enabled == GNUTLS_ENABLED_FALSE) { |
---|
264 | return 0; |
---|
265 | } |
---|
266 | |
---|
267 | return 443; |
---|
268 | } |
---|
269 | |
---|
270 | /* TODO: Complete support for Server Name Indication */ |
---|
271 | static int cert_retrieve_fn(gnutls_session_t session, gnutls_retr_st* ret) |
---|
272 | { |
---|
273 | char* server_name; |
---|
274 | int server_type; |
---|
275 | int data_len = 256; |
---|
276 | mod_gnutls_handle_t *ctxt; |
---|
277 | ctxt = gnutls_transport_get_ptr(session); |
---|
278 | |
---|
279 | ret->type = GNUTLS_CRT_X509; |
---|
280 | ret->ncerts = 1; |
---|
281 | server_name = apr_palloc(ctxt->c->pool, data_len); |
---|
282 | if (gnutls_server_name_get(ctxt->session, server_name, &data_len, &server_type, 0) == 0) { |
---|
283 | if (server_type == GNUTLS_NAME_DNS) { |
---|
284 | ap_log_error(APLOG_MARK, APLOG_INFO, 0, |
---|
285 | ctxt->c->base_server, |
---|
286 | "GnuTLS: Virtual Host: " |
---|
287 | "%s", server_name); |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | return 0; |
---|
292 | } |
---|
293 | |
---|
294 | static mod_gnutls_handle_t* create_gnutls_handle(apr_pool_t* pool, conn_rec * c) |
---|
295 | { |
---|
296 | mod_gnutls_handle_t *ctxt; |
---|
297 | mod_gnutls_srvconf_rec *sc = |
---|
298 | (mod_gnutls_srvconf_rec *) ap_get_module_config(c->base_server-> |
---|
299 | module_config, |
---|
300 | &gnutls_module); |
---|
301 | |
---|
302 | ctxt = apr_pcalloc(pool, sizeof(*ctxt)); |
---|
303 | ctxt->c = c; |
---|
304 | ctxt->sc = sc; |
---|
305 | ctxt->status = 0; |
---|
306 | |
---|
307 | ctxt->input_rc = APR_SUCCESS; |
---|
308 | ctxt->input_bb = apr_brigade_create(c->pool, c->bucket_alloc); |
---|
309 | ctxt->input_cbuf.length = 0; |
---|
310 | |
---|
311 | ctxt->output_rc = APR_SUCCESS; |
---|
312 | ctxt->output_bb = apr_brigade_create(c->pool, c->bucket_alloc); |
---|
313 | ctxt->output_blen = 0; |
---|
314 | ctxt->output_length = 0; |
---|
315 | |
---|
316 | gnutls_init(&ctxt->session, GNUTLS_SERVER); |
---|
317 | |
---|
318 | gnutls_protocol_set_priority(ctxt->session, sc->protocol); |
---|
319 | gnutls_cipher_set_priority(ctxt->session, sc->ciphers); |
---|
320 | gnutls_compression_set_priority(ctxt->session, sc->compression); |
---|
321 | gnutls_kx_set_priority(ctxt->session, sc->key_exchange); |
---|
322 | gnutls_mac_set_priority(ctxt->session, sc->macs); |
---|
323 | gnutls_certificate_type_set_priority(ctxt->session, sc->cert_types); |
---|
324 | |
---|
325 | gnutls_credentials_set(ctxt->session, GNUTLS_CRD_CERTIFICATE, sc->certs); |
---|
326 | |
---|
327 | gnutls_certificate_server_set_request(ctxt->session, GNUTLS_CERT_IGNORE); |
---|
328 | |
---|
329 | mod_gnutls_cache_session_init(ctxt); |
---|
330 | |
---|
331 | /* TODO: Finish Support for Server Name Indication */ |
---|
332 | /* gnutls_certificate_server_set_retrieve_function(sc->certs, cert_retrieve_fn); */ |
---|
333 | return ctxt; |
---|
334 | } |
---|
335 | |
---|
336 | static int mod_gnutls_hook_pre_connection(conn_rec * c, void *csd) |
---|
337 | { |
---|
338 | mod_gnutls_handle_t *ctxt; |
---|
339 | mod_gnutls_srvconf_rec *sc = |
---|
340 | (mod_gnutls_srvconf_rec *) ap_get_module_config(c->base_server-> |
---|
341 | module_config, |
---|
342 | &gnutls_module); |
---|
343 | |
---|
344 | if (!(sc && (sc->enabled == GNUTLS_ENABLED_TRUE))) { |
---|
345 | return DECLINED; |
---|
346 | } |
---|
347 | |
---|
348 | ctxt = create_gnutls_handle(c->pool, c); |
---|
349 | |
---|
350 | ap_set_module_config(c->conn_config, &gnutls_module, ctxt); |
---|
351 | |
---|
352 | gnutls_transport_set_pull_function(ctxt->session, |
---|
353 | mod_gnutls_transport_read); |
---|
354 | gnutls_transport_set_push_function(ctxt->session, |
---|
355 | mod_gnutls_transport_write); |
---|
356 | gnutls_transport_set_ptr(ctxt->session, ctxt); |
---|
357 | |
---|
358 | ctxt->input_filter = ap_add_input_filter(GNUTLS_INPUT_FILTER_NAME, ctxt, |
---|
359 | NULL, c); |
---|
360 | ctxt->output_filter = ap_add_output_filter(GNUTLS_OUTPUT_FILTER_NAME, ctxt, |
---|
361 | NULL, c); |
---|
362 | |
---|
363 | return OK; |
---|
364 | } |
---|
365 | |
---|
366 | static int mod_gnutls_hook_fixups(request_rec *r) |
---|
367 | { |
---|
368 | unsigned char sbuf[GNUTLS_MAX_SESSION_ID]; |
---|
369 | char buf[GNUTLS_SESSION_ID_STRING_LEN]; |
---|
370 | const char* tmp; |
---|
371 | int len; |
---|
372 | mod_gnutls_handle_t *ctxt; |
---|
373 | apr_table_t *env = r->subprocess_env; |
---|
374 | |
---|
375 | ctxt = ap_get_module_config(r->connection->conn_config, &gnutls_module); |
---|
376 | |
---|
377 | if(!ctxt) { |
---|
378 | return DECLINED; |
---|
379 | } |
---|
380 | |
---|
381 | apr_table_setn(env, "HTTPS", "on"); |
---|
382 | |
---|
383 | apr_table_setn(env, "GNUTLS_VERSION_INTERFACE", MOD_GNUTLS_VERSION); |
---|
384 | apr_table_setn(env, "GNUTLS_VERSION_LIBRARY", LIBGNUTLS_VERSION); |
---|
385 | |
---|
386 | apr_table_setn(env, "SSL_PROTOCOL", |
---|
387 | gnutls_protocol_get_name(gnutls_protocol_get_version(ctxt->session))); |
---|
388 | |
---|
389 | apr_table_setn(env, "SSL_CIPHER", |
---|
390 | gnutls_cipher_get_name(gnutls_cipher_get(ctxt->session))); |
---|
391 | |
---|
392 | apr_table_setn(env, "SSL_CLIENT_VERIFY", "NONE"); |
---|
393 | |
---|
394 | tmp = apr_psprintf(r->pool, "%d", |
---|
395 | 8 * gnutls_cipher_get_key_size(gnutls_cipher_get(ctxt->session))); |
---|
396 | |
---|
397 | apr_table_setn(env, "SSL_CIPHER_USEKEYSIZE", tmp); |
---|
398 | |
---|
399 | apr_table_setn(env, "SSL_CIPHER_ALGKEYSIZE", tmp); |
---|
400 | |
---|
401 | len = sizeof(sbuf); |
---|
402 | gnutls_session_get_id(ctxt->session, sbuf, &len); |
---|
403 | tmp = mod_gnutls_session_id2sz(sbuf, len, buf, sizeof(buf)); |
---|
404 | apr_table_setn(env, "SSL_SESSION_ID", tmp); |
---|
405 | |
---|
406 | return OK; |
---|
407 | } |
---|
408 | |
---|
409 | static const char *gnutls_set_cert_file(cmd_parms * parms, void *dummy, |
---|
410 | const char *arg) |
---|
411 | { |
---|
412 | mod_gnutls_srvconf_rec *sc = |
---|
413 | (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
414 | module_config, |
---|
415 | &gnutls_module); |
---|
416 | sc->cert_file = ap_server_root_relative(parms->pool, arg); |
---|
417 | return NULL; |
---|
418 | } |
---|
419 | |
---|
420 | static const char *gnutls_set_key_file(cmd_parms * parms, void *dummy, |
---|
421 | const char *arg) |
---|
422 | { |
---|
423 | mod_gnutls_srvconf_rec *sc = |
---|
424 | (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
425 | module_config, |
---|
426 | &gnutls_module); |
---|
427 | |
---|
428 | sc->key_file = ap_server_root_relative(parms->pool, arg); |
---|
429 | return NULL; |
---|
430 | } |
---|
431 | |
---|
432 | static const char *gnutls_set_cache(cmd_parms * parms, void *dummy, |
---|
433 | const char *type, const char* arg) |
---|
434 | { |
---|
435 | const char* err; |
---|
436 | mod_gnutls_srvconf_rec *sc = ap_get_module_config(parms->server-> |
---|
437 | module_config, |
---|
438 | &gnutls_module); |
---|
439 | if ((err = ap_check_cmd_context(parms, GLOBAL_ONLY))) { |
---|
440 | return err; |
---|
441 | } |
---|
442 | |
---|
443 | if (strcasecmp("none", type) == 0) { |
---|
444 | sc->cache_type = mod_gnutls_cache_none; |
---|
445 | } |
---|
446 | else if (strcasecmp("dbm", type) == 0) { |
---|
447 | sc->cache_type = mod_gnutls_cache_dbm; |
---|
448 | } |
---|
449 | #if HAVE_APR_MEMCACHE |
---|
450 | else if (strcasecmp("memcache", type) == 0) { |
---|
451 | sc->cache_type = mod_gnutls_cache_memcache; |
---|
452 | } |
---|
453 | #endif |
---|
454 | else { |
---|
455 | return "Invalid Type for GnuTLSCache!"; |
---|
456 | } |
---|
457 | |
---|
458 | if (sc->cache_type == mod_gnutls_cache_dbm) { |
---|
459 | sc->cache_config = ap_server_root_relative(parms->pool, arg); |
---|
460 | } |
---|
461 | else { |
---|
462 | sc->cache_config = apr_pstrdup(parms->pool, arg); |
---|
463 | } |
---|
464 | |
---|
465 | return NULL; |
---|
466 | } |
---|
467 | |
---|
468 | static const char *gnutls_set_enabled(cmd_parms * parms, void *dummy, |
---|
469 | const char *arg) |
---|
470 | { |
---|
471 | mod_gnutls_srvconf_rec *sc = |
---|
472 | (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
473 | module_config, |
---|
474 | &gnutls_module); |
---|
475 | if (!strcasecmp(arg, "On")) { |
---|
476 | sc->enabled = GNUTLS_ENABLED_TRUE; |
---|
477 | } |
---|
478 | else if (!strcasecmp(arg, "Off")) { |
---|
479 | sc->enabled = GNUTLS_ENABLED_FALSE; |
---|
480 | } |
---|
481 | else { |
---|
482 | return "GnuTLSEnable must be set to 'On' or 'Off'"; |
---|
483 | } |
---|
484 | |
---|
485 | return NULL; |
---|
486 | } |
---|
487 | |
---|
488 | static const command_rec gnutls_cmds[] = { |
---|
489 | AP_INIT_TAKE1("GnuTLSCertificateFile", gnutls_set_cert_file, |
---|
490 | NULL, |
---|
491 | RSRC_CONF, |
---|
492 | "SSL Server Key file"), |
---|
493 | AP_INIT_TAKE1("GnuTLSKeyFile", gnutls_set_key_file, |
---|
494 | NULL, |
---|
495 | RSRC_CONF, |
---|
496 | "SSL Server Certificate file"), |
---|
497 | AP_INIT_TAKE2("GnuTLSCache", gnutls_set_cache, |
---|
498 | NULL, |
---|
499 | RSRC_CONF, |
---|
500 | "Cache Configuration"), |
---|
501 | AP_INIT_TAKE1("GnuTLSEnable", gnutls_set_enabled, |
---|
502 | NULL, RSRC_CONF, |
---|
503 | "Whether this server has GnuTLS Enabled. Default: Off"), |
---|
504 | |
---|
505 | {NULL} |
---|
506 | }; |
---|
507 | |
---|
508 | /* TODO: CACertificateFile & Client Authentication |
---|
509 | * AP_INIT_TAKE1("GnuTLSCACertificateFile", ap_set_server_string_slot, |
---|
510 | * (void *) APR_OFFSETOF(gnutls_srvconf_rec, key_file), NULL, |
---|
511 | * RSRC_CONF, |
---|
512 | * "CA"), |
---|
513 | */ |
---|
514 | |
---|
515 | static void gnutls_hooks(apr_pool_t * p) |
---|
516 | { |
---|
517 | ap_hook_pre_connection(mod_gnutls_hook_pre_connection, NULL, NULL, |
---|
518 | APR_HOOK_MIDDLE); |
---|
519 | ap_hook_post_config(mod_gnutls_hook_post_config, NULL, NULL, |
---|
520 | APR_HOOK_MIDDLE); |
---|
521 | ap_hook_child_init(mod_gnutls_hook_child_init, NULL, NULL, |
---|
522 | APR_HOOK_MIDDLE); |
---|
523 | ap_hook_http_scheme(mod_gnutls_hook_http_scheme, NULL, NULL, |
---|
524 | APR_HOOK_MIDDLE); |
---|
525 | ap_hook_default_port(mod_gnutls_hook_default_port, NULL, NULL, |
---|
526 | APR_HOOK_MIDDLE); |
---|
527 | ap_hook_pre_config(mod_gnutls_hook_pre_config, NULL, NULL, |
---|
528 | APR_HOOK_MIDDLE); |
---|
529 | |
---|
530 | ap_hook_fixups(mod_gnutls_hook_fixups, NULL, NULL, APR_HOOK_MIDDLE); |
---|
531 | |
---|
532 | /* TODO: HTTP Upgrade Filter */ |
---|
533 | /* ap_register_output_filter ("UPGRADE_FILTER", |
---|
534 | * ssl_io_filter_Upgrade, NULL, AP_FTYPE_PROTOCOL + 5); |
---|
535 | */ |
---|
536 | ap_register_input_filter(GNUTLS_INPUT_FILTER_NAME, |
---|
537 | mod_gnutls_filter_input, NULL, |
---|
538 | AP_FTYPE_CONNECTION + 5); |
---|
539 | ap_register_output_filter(GNUTLS_OUTPUT_FILTER_NAME, |
---|
540 | mod_gnutls_filter_output, NULL, |
---|
541 | AP_FTYPE_CONNECTION + 5); |
---|
542 | } |
---|
543 | |
---|
544 | static void *gnutls_config_server_create(apr_pool_t * p, server_rec * s) |
---|
545 | { |
---|
546 | int i; |
---|
547 | mod_gnutls_srvconf_rec *sc = apr_pcalloc(p, sizeof(*sc)); |
---|
548 | |
---|
549 | sc->enabled = GNUTLS_ENABLED_FALSE; |
---|
550 | |
---|
551 | gnutls_certificate_allocate_credentials(&sc->certs); |
---|
552 | sc->key_file = NULL; |
---|
553 | sc->cert_file = NULL; |
---|
554 | sc->cache_timeout = apr_time_from_sec(3600); |
---|
555 | sc->cache_type = mod_gnutls_cache_dbm; |
---|
556 | sc->cache_config = ap_server_root_relative(p, "conf/gnutls_cache"); |
---|
557 | |
---|
558 | /* TODO: Make this Configurable ! */ |
---|
559 | sc->dh_params_file = ap_server_root_relative(p, "conf/dhfile"); |
---|
560 | sc->rsa_params_file = ap_server_root_relative(p, "conf/rsafile"); |
---|
561 | |
---|
562 | /* TODO: Make this Configurable ! */ |
---|
563 | /* meh. mod_ssl uses a flex based parser for this part.. sigh */ |
---|
564 | i = 0; |
---|
565 | sc->ciphers[i++] = GNUTLS_CIPHER_AES_256_CBC; |
---|
566 | sc->ciphers[i++] = GNUTLS_CIPHER_AES_128_CBC; |
---|
567 | sc->ciphers[i++] = GNUTLS_CIPHER_ARCFOUR_128; |
---|
568 | sc->ciphers[i++] = GNUTLS_CIPHER_3DES_CBC; |
---|
569 | sc->ciphers[i++] = GNUTLS_CIPHER_ARCFOUR_40; |
---|
570 | sc->ciphers[i] = 0; |
---|
571 | |
---|
572 | i = 0; |
---|
573 | sc->key_exchange[i++] = GNUTLS_KX_RSA; |
---|
574 | sc->key_exchange[i++] = GNUTLS_KX_RSA_EXPORT; |
---|
575 | sc->key_exchange[i++] = GNUTLS_KX_DHE_DSS; |
---|
576 | sc->key_exchange[i++] = GNUTLS_KX_DHE_RSA; |
---|
577 | sc->key_exchange[i++] = GNUTLS_KX_ANON_DH; |
---|
578 | sc->key_exchange[i++] = GNUTLS_KX_SRP; |
---|
579 | sc->key_exchange[i++] = GNUTLS_KX_SRP_RSA; |
---|
580 | sc->key_exchange[i++] = GNUTLS_KX_SRP_DSS; |
---|
581 | sc->key_exchange[i] = 0; |
---|
582 | |
---|
583 | i = 0; |
---|
584 | sc->macs[i++] = GNUTLS_MAC_SHA; |
---|
585 | sc->macs[i++] = GNUTLS_MAC_MD5; |
---|
586 | sc->macs[i++] = GNUTLS_MAC_RMD160; |
---|
587 | sc->macs[i] = 0; |
---|
588 | |
---|
589 | i = 0; |
---|
590 | sc->protocol[i++] = GNUTLS_TLS1_1; |
---|
591 | sc->protocol[i++] = GNUTLS_TLS1; |
---|
592 | sc->protocol[i++] = GNUTLS_SSL3; |
---|
593 | sc->protocol[i] = 0; |
---|
594 | |
---|
595 | i = 0; |
---|
596 | sc->compression[i++] = GNUTLS_COMP_NULL; |
---|
597 | sc->compression[i++] = GNUTLS_COMP_ZLIB; |
---|
598 | sc->compression[i++] = GNUTLS_COMP_LZO; |
---|
599 | sc->compression[i] = 0; |
---|
600 | |
---|
601 | i = 0; |
---|
602 | sc->cert_types[i++] = GNUTLS_CRT_X509; |
---|
603 | sc->cert_types[i] = 0; |
---|
604 | |
---|
605 | return sc; |
---|
606 | } |
---|
607 | |
---|
608 | |
---|
609 | |
---|
610 | module AP_MODULE_DECLARE_DATA gnutls_module = { |
---|
611 | STANDARD20_MODULE_STUFF, |
---|
612 | NULL, |
---|
613 | NULL, |
---|
614 | gnutls_config_server_create, |
---|
615 | NULL, |
---|
616 | /* gnutls_config_server_merge, */ |
---|
617 | gnutls_cmds, |
---|
618 | gnutls_hooks |
---|
619 | }; |
---|