diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gnutls_io.c | 10 | ||||
-rw-r--r-- | src/mod_gnutls.c | 89 |
2 files changed, 52 insertions, 47 deletions
diff --git a/src/gnutls_io.c b/src/gnutls_io.c index 6b0a15b..1cb14a3 100644 --- a/src/gnutls_io.c +++ b/src/gnutls_io.c | |||
@@ -28,9 +28,9 @@ apr_status_t mod_gnutls_filter_input(ap_filter_t * f, | |||
28 | apr_read_type_e block, | 28 | apr_read_type_e block, |
29 | apr_off_t readbytes) | 29 | apr_off_t readbytes) |
30 | { | 30 | { |
31 | apr_bucket* b; | 31 | apr_bucket *b; |
32 | apr_status_t status = APR_SUCCESS; | 32 | apr_status_t status = APR_SUCCESS; |
33 | gnutls_handle_t *ctxt = (gnutls_handle_t *) f->ctx; | 33 | mod_gnutls_handle_t *ctxt = (mod_gnutls_handle_t *) f->ctx; |
34 | 34 | ||
35 | if (f->c->aborted) { | 35 | if (f->c->aborted) { |
36 | apr_bucket *bucket = apr_bucket_eos_create(f->c->bucket_alloc); | 36 | apr_bucket *bucket = apr_bucket_eos_create(f->c->bucket_alloc); |
@@ -61,7 +61,7 @@ apr_status_t mod_gnutls_filter_output(ap_filter_t * f, | |||
61 | int ret, i; | 61 | int ret, i; |
62 | const char *buf = 0; | 62 | const char *buf = 0; |
63 | apr_size_t bytes = 0; | 63 | apr_size_t bytes = 0; |
64 | gnutls_handle_t *ctxt = (gnutls_handle_t *) f->ctx; | 64 | mod_gnutls_handle_t *ctxt = (mod_gnutls_handle_t *) f->ctx; |
65 | apr_status_t status = APR_SUCCESS; | 65 | apr_status_t status = APR_SUCCESS; |
66 | apr_read_type_e rblock = APR_NONBLOCK_READ; | 66 | apr_read_type_e rblock = APR_NONBLOCK_READ; |
67 | 67 | ||
@@ -256,7 +256,7 @@ static apr_status_t brigade_consume(apr_bucket_brigade * bb, | |||
256 | ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, | 256 | ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, |
257 | void *buffer, size_t len) | 257 | void *buffer, size_t len) |
258 | { | 258 | { |
259 | gnutls_handle_t *ctxt = ptr; | 259 | mod_gnutls_handle_t *ctxt = ptr; |
260 | apr_status_t rc; | 260 | apr_status_t rc; |
261 | apr_size_t in = len; | 261 | apr_size_t in = len; |
262 | /* If Len = 0, we don't do anything. */ | 262 | /* If Len = 0, we don't do anything. */ |
@@ -295,7 +295,7 @@ ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, | |||
295 | ssize_t mod_gnutls_transport_write(gnutls_transport_ptr_t ptr, | 295 | ssize_t mod_gnutls_transport_write(gnutls_transport_ptr_t ptr, |
296 | const void *buffer, size_t len) | 296 | const void *buffer, size_t len) |
297 | { | 297 | { |
298 | gnutls_handle_t *ctxt = ptr; | 298 | mod_gnutls_handle_t *ctxt = ptr; |
299 | 299 | ||
300 | // apr_bucket *bucket = apr_bucket_transient_create(in, inl, | 300 | // apr_bucket *bucket = apr_bucket_transient_create(in, inl, |
301 | // outctx->bb-> | 301 | // outctx->bb-> |
diff --git a/src/mod_gnutls.c b/src/mod_gnutls.c index 14bf319..c34da5a 100644 --- a/src/mod_gnutls.c +++ b/src/mod_gnutls.c | |||
@@ -21,14 +21,14 @@ | |||
21 | GCRY_THREAD_OPTION_PTHREAD_IMPL; | 21 | GCRY_THREAD_OPTION_PTHREAD_IMPL; |
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | static apr_status_t gnutls_cleanup_pre_config(void *data) | 24 | static apr_status_t mod_gnutls_cleanup_pre_config(void *data) |
25 | { | 25 | { |
26 | gnutls_global_deinit(); | 26 | gnutls_global_deinit(); |
27 | return APR_SUCCESS; | 27 | return APR_SUCCESS; |
28 | } | 28 | } |
29 | 29 | ||
30 | static int gnutls_hook_pre_config(apr_pool_t * pconf, | 30 | static int mod_gnutls_hook_pre_config(apr_pool_t * pconf, |
31 | apr_pool_t * plog, apr_pool_t * ptemp) | 31 | apr_pool_t * plog, apr_pool_t * ptemp) |
32 | { | 32 | { |
33 | 33 | ||
34 | #if APR_HAS_THREADS | 34 | #if APR_HAS_THREADS |
@@ -37,7 +37,7 @@ static int gnutls_hook_pre_config(apr_pool_t * pconf, | |||
37 | 37 | ||
38 | gnutls_global_init(); | 38 | gnutls_global_init(); |
39 | 39 | ||
40 | apr_pool_cleanup_register(pconf, NULL, gnutls_cleanup_pre_config, | 40 | apr_pool_cleanup_register(pconf, NULL, mod_gnutls_cleanup_pre_config, |
41 | apr_pool_cleanup_null); | 41 | apr_pool_cleanup_null); |
42 | 42 | ||
43 | return OK; | 43 | return OK; |
@@ -46,11 +46,11 @@ static int gnutls_hook_pre_config(apr_pool_t * pconf, | |||
46 | #define DH_BITS 1024 | 46 | #define DH_BITS 1024 |
47 | #define RSA_BITS 512 | 47 | #define RSA_BITS 512 |
48 | 48 | ||
49 | static int gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, | 49 | static int mod_gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, |
50 | apr_pool_t * ptemp, | 50 | apr_pool_t * ptemp, |
51 | server_rec * base_server) | 51 | server_rec * base_server) |
52 | { | 52 | { |
53 | gnutls_srvconf_rec *sc; | 53 | mod_gnutls_srvconf_rec *sc; |
54 | server_rec *s; | 54 | server_rec *s; |
55 | gnutls_dh_params_t dh_params; | 55 | gnutls_dh_params_t dh_params; |
56 | gnutls_rsa_params_t rsa_params; | 56 | gnutls_rsa_params_t rsa_params; |
@@ -63,8 +63,8 @@ static int gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, | |||
63 | // gnutls_rsa_params_generate2(rsa_params, RSA_BITS); | 63 | // gnutls_rsa_params_generate2(rsa_params, RSA_BITS); |
64 | 64 | ||
65 | for (s = base_server; s; s = s->next) { | 65 | for (s = base_server; s; s = s->next) { |
66 | sc = (gnutls_srvconf_rec *) ap_get_module_config(s->module_config, | 66 | sc = (mod_gnutls_srvconf_rec *) ap_get_module_config(s->module_config, |
67 | &gnutls_module); | 67 | &gnutls_module); |
68 | if (sc->cert_file != NULL && sc->key_file != NULL) { | 68 | if (sc->cert_file != NULL && sc->key_file != NULL) { |
69 | gnutls_certificate_set_x509_key_file(sc->certs, sc->cert_file, | 69 | gnutls_certificate_set_x509_key_file(sc->certs, sc->cert_file, |
70 | sc->key_file, | 70 | sc->key_file, |
@@ -84,11 +84,12 @@ static int gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, | |||
84 | return OK; | 84 | return OK; |
85 | } | 85 | } |
86 | 86 | ||
87 | static const char *gnutls_hook_http_method(const request_rec * r) | 87 | static const char *mod_gnutls_hook_http_method(const request_rec * r) |
88 | { | 88 | { |
89 | gnutls_srvconf_rec *sc = | 89 | mod_gnutls_srvconf_rec *sc = |
90 | (gnutls_srvconf_rec *) ap_get_module_config(r->server->module_config, | 90 | (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> |
91 | &gnutls_module); | 91 | module_config, |
92 | &gnutls_module); | ||
92 | 93 | ||
93 | if (sc->enabled == GNUTLS_ENABLED_FALSE) { | 94 | if (sc->enabled == GNUTLS_ENABLED_FALSE) { |
94 | return NULL; | 95 | return NULL; |
@@ -97,11 +98,12 @@ static const char *gnutls_hook_http_method(const request_rec * r) | |||
97 | return "https"; | 98 | return "https"; |
98 | } | 99 | } |
99 | 100 | ||
100 | static apr_port_t gnutls_hook_default_port(const request_rec * r) | 101 | static apr_port_t mod_gnutls_hook_default_port(const request_rec * r) |
101 | { | 102 | { |
102 | gnutls_srvconf_rec *sc = | 103 | mod_gnutls_srvconf_rec *sc = |
103 | (gnutls_srvconf_rec *) ap_get_module_config(r->server->module_config, | 104 | (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> |
104 | &gnutls_module); | 105 | module_config, |
106 | &gnutls_module); | ||
105 | 107 | ||
106 | if (sc->enabled == GNUTLS_ENABLED_FALSE) { | 108 | if (sc->enabled == GNUTLS_ENABLED_FALSE) { |
107 | return 0; | 109 | return 0; |
@@ -110,13 +112,13 @@ static apr_port_t gnutls_hook_default_port(const request_rec * r) | |||
110 | return 443; | 112 | return 443; |
111 | } | 113 | } |
112 | 114 | ||
113 | static int gnutls_hook_pre_connection(conn_rec * c, void *csd) | 115 | static int mod_gnutls_hook_pre_connection(conn_rec * c, void *csd) |
114 | { | 116 | { |
115 | gnutls_handle_t *ctxt; | 117 | mod_gnutls_handle_t *ctxt; |
116 | gnutls_srvconf_rec *sc = | 118 | mod_gnutls_srvconf_rec *sc = |
117 | (gnutls_srvconf_rec *) ap_get_module_config(c->base_server-> | 119 | (mod_gnutls_srvconf_rec *) ap_get_module_config(c->base_server-> |
118 | module_config, | 120 | module_config, |
119 | &gnutls_module); | 121 | &gnutls_module); |
120 | 122 | ||
121 | if (!(sc && (sc->enabled == GNUTLS_ENABLED_TRUE))) { | 123 | if (!(sc && (sc->enabled == GNUTLS_ENABLED_TRUE))) { |
122 | return DECLINED; | 124 | return DECLINED; |
@@ -160,10 +162,10 @@ static int gnutls_hook_pre_connection(conn_rec * c, void *csd) | |||
160 | static const char *gnutls_set_cert_file(cmd_parms * parms, void *dummy, | 162 | static const char *gnutls_set_cert_file(cmd_parms * parms, void *dummy, |
161 | const char *arg) | 163 | const char *arg) |
162 | { | 164 | { |
163 | gnutls_srvconf_rec *sc = | 165 | mod_gnutls_srvconf_rec *sc = |
164 | (gnutls_srvconf_rec *) ap_get_module_config(parms->server-> | 166 | (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> |
165 | module_config, | 167 | module_config, |
166 | &gnutls_module); | 168 | &gnutls_module); |
167 | sc->cert_file = apr_pstrdup(parms->pool, arg); | 169 | sc->cert_file = apr_pstrdup(parms->pool, arg); |
168 | return NULL; | 170 | return NULL; |
169 | } | 171 | } |
@@ -171,10 +173,10 @@ static const char *gnutls_set_cert_file(cmd_parms * parms, void *dummy, | |||
171 | static const char *gnutls_set_key_file(cmd_parms * parms, void *dummy, | 173 | static const char *gnutls_set_key_file(cmd_parms * parms, void *dummy, |
172 | const char *arg) | 174 | const char *arg) |
173 | { | 175 | { |
174 | gnutls_srvconf_rec *sc = | 176 | mod_gnutls_srvconf_rec *sc = |
175 | (gnutls_srvconf_rec *) ap_get_module_config(parms->server-> | 177 | (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> |
176 | module_config, | 178 | module_config, |
177 | &gnutls_module); | 179 | &gnutls_module); |
178 | sc->key_file = apr_pstrdup(parms->pool, arg); | 180 | sc->key_file = apr_pstrdup(parms->pool, arg); |
179 | return NULL; | 181 | return NULL; |
180 | } | 182 | } |
@@ -182,10 +184,10 @@ static const char *gnutls_set_key_file(cmd_parms * parms, void *dummy, | |||
182 | static const char *gnutls_set_enabled(cmd_parms * parms, void *dummy, | 184 | static const char *gnutls_set_enabled(cmd_parms * parms, void *dummy, |
183 | const char *arg) | 185 | const char *arg) |
184 | { | 186 | { |
185 | gnutls_srvconf_rec *sc = | 187 | mod_gnutls_srvconf_rec *sc = |
186 | (gnutls_srvconf_rec *) ap_get_module_config(parms->server-> | 188 | (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> |
187 | module_config, | 189 | module_config, |
188 | &gnutls_module); | 190 | &gnutls_module); |
189 | if (!strcasecmp(arg, "On")) { | 191 | if (!strcasecmp(arg, "On")) { |
190 | sc->enabled = GNUTLS_ENABLED_TRUE; | 192 | sc->enabled = GNUTLS_ENABLED_TRUE; |
191 | } | 193 | } |
@@ -224,13 +226,16 @@ static const command_rec gnutls_cmds[] = { | |||
224 | 226 | ||
225 | static void gnutls_hooks(apr_pool_t * p) | 227 | static void gnutls_hooks(apr_pool_t * p) |
226 | { | 228 | { |
227 | ap_hook_pre_connection(gnutls_hook_pre_connection, NULL, NULL, | 229 | ap_hook_pre_connection(mod_gnutls_hook_pre_connection, NULL, NULL, |
228 | APR_HOOK_MIDDLE); | 230 | APR_HOOK_MIDDLE); |
229 | ap_hook_post_config(gnutls_hook_post_config, NULL, NULL, APR_HOOK_MIDDLE); | 231 | ap_hook_post_config(mod_gnutls_hook_post_config, NULL, NULL, |
230 | ap_hook_http_method(gnutls_hook_http_method, NULL, NULL, APR_HOOK_MIDDLE); | 232 | APR_HOOK_MIDDLE); |
231 | ap_hook_default_port(gnutls_hook_default_port, NULL, NULL, | 233 | ap_hook_http_method(mod_gnutls_hook_http_method, NULL, NULL, |
234 | APR_HOOK_MIDDLE); | ||
235 | ap_hook_default_port(mod_gnutls_hook_default_port, NULL, NULL, | ||
232 | APR_HOOK_MIDDLE); | 236 | APR_HOOK_MIDDLE); |
233 | ap_hook_pre_config(gnutls_hook_pre_config, NULL, NULL, APR_HOOK_MIDDLE); | 237 | ap_hook_pre_config(mod_gnutls_hook_pre_config, NULL, NULL, |
238 | APR_HOOK_MIDDLE); | ||
234 | 239 | ||
235 | /* TODO: HTTP Upgrade Filter */ | 240 | /* TODO: HTTP Upgrade Filter */ |
236 | /* ap_register_output_filter ("UPGRADE_FILTER", | 241 | /* ap_register_output_filter ("UPGRADE_FILTER", |
@@ -247,7 +252,7 @@ static void gnutls_hooks(apr_pool_t * p) | |||
247 | static void *gnutls_config_server_create(apr_pool_t * p, server_rec * s) | 252 | static void *gnutls_config_server_create(apr_pool_t * p, server_rec * s) |
248 | { | 253 | { |
249 | int i; | 254 | int i; |
250 | gnutls_srvconf_rec *sc = apr_pcalloc(p, sizeof(*sc)); | 255 | mod_gnutls_srvconf_rec *sc = apr_pcalloc(p, sizeof(*sc)); |
251 | 256 | ||
252 | sc->enabled = GNUTLS_ENABLED_FALSE; | 257 | sc->enabled = GNUTLS_ENABLED_FALSE; |
253 | 258 | ||