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 "httpd.h" |
---|
19 | #include "http_config.h" |
---|
20 | #include "http_protocol.h" |
---|
21 | #include "http_connection.h" |
---|
22 | #include "http_request.h" |
---|
23 | #include "http_core.h" |
---|
24 | #include "http_log.h" |
---|
25 | #include "apr_buckets.h" |
---|
26 | #include "apr_strings.h" |
---|
27 | #include "apr_tables.h" |
---|
28 | |
---|
29 | #ifndef __mod_gnutls_h_inc |
---|
30 | #define __mod_gnutls_h_inc |
---|
31 | |
---|
32 | #define HAVE_APR_MEMCACHE @have_apr_memcache@ |
---|
33 | |
---|
34 | #include <gcrypt.h> |
---|
35 | #include <gnutls/gnutls.h> |
---|
36 | |
---|
37 | module AP_MODULE_DECLARE_DATA gnutls_module; |
---|
38 | |
---|
39 | #define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter" |
---|
40 | #define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter" |
---|
41 | |
---|
42 | #define GNUTLS_ENABLED_FALSE 0 |
---|
43 | #define GNUTLS_ENABLED_TRUE 1 |
---|
44 | |
---|
45 | typedef enum |
---|
46 | { |
---|
47 | mod_gnutls_cache_none, |
---|
48 | mod_gnutls_cache_dbm, |
---|
49 | #if HAVE_APR_MEMCACHE |
---|
50 | mod_gnutls_cache_memcache |
---|
51 | #endif |
---|
52 | } mod_gnutls_cache_e; |
---|
53 | |
---|
54 | typedef struct |
---|
55 | { |
---|
56 | gnutls_certificate_credentials_t certs; |
---|
57 | gnutls_anon_server_credentials_t anoncred; |
---|
58 | char *key_file; |
---|
59 | char *cert_file; |
---|
60 | int enabled; |
---|
61 | int ciphers[16]; |
---|
62 | int key_exchange[16]; |
---|
63 | int macs[16]; |
---|
64 | int protocol[16]; |
---|
65 | int compression[16]; |
---|
66 | int cert_types[16]; |
---|
67 | apr_time_t cache_timeout; |
---|
68 | mod_gnutls_cache_e cache_type; |
---|
69 | const char* cache_config; |
---|
70 | const char* rsa_params_file; |
---|
71 | const char* dh_params_file; |
---|
72 | } mod_gnutls_srvconf_rec; |
---|
73 | |
---|
74 | typedef struct { |
---|
75 | int length; |
---|
76 | char *value; |
---|
77 | } mod_gnutls_char_buffer_t; |
---|
78 | |
---|
79 | typedef struct |
---|
80 | { |
---|
81 | mod_gnutls_srvconf_rec *sc; |
---|
82 | conn_rec* c; |
---|
83 | gnutls_session_t session; |
---|
84 | |
---|
85 | apr_status_t input_rc; |
---|
86 | ap_filter_t *input_filter; |
---|
87 | apr_bucket_brigade *input_bb; |
---|
88 | apr_read_type_e input_block; |
---|
89 | ap_input_mode_t input_mode; |
---|
90 | mod_gnutls_char_buffer_t input_cbuf; |
---|
91 | char input_buffer[AP_IOBUFSIZE]; |
---|
92 | |
---|
93 | apr_status_t output_rc; |
---|
94 | ap_filter_t *output_filter; |
---|
95 | apr_bucket_brigade *output_bb; |
---|
96 | char output_buffer[AP_IOBUFSIZE]; |
---|
97 | apr_size_t output_blen; |
---|
98 | apr_size_t output_length; |
---|
99 | |
---|
100 | int status; |
---|
101 | int non_https; |
---|
102 | } mod_gnutls_handle_t; |
---|
103 | |
---|
104 | /** Functions in gnutls_io.c **/ |
---|
105 | |
---|
106 | /** |
---|
107 | * mod_gnutls_filter_input will filter the input data |
---|
108 | * by decrypting it using GnuTLS and passes it cleartext. |
---|
109 | * |
---|
110 | * @param f the filter info record |
---|
111 | * @param bb the bucket brigade, where to store the result to |
---|
112 | * @param mode what shall we read? |
---|
113 | * @param block a block index we shall read from? |
---|
114 | * @return result status |
---|
115 | */ |
---|
116 | apr_status_t mod_gnutls_filter_input(ap_filter_t * f, |
---|
117 | apr_bucket_brigade * bb, |
---|
118 | ap_input_mode_t mode, |
---|
119 | apr_read_type_e block, |
---|
120 | apr_off_t readbytes); |
---|
121 | |
---|
122 | /** |
---|
123 | * mod_gnutls_filter_output will filter the encrypt |
---|
124 | * the incoming bucket using GnuTLS and passes it onto the next filter. |
---|
125 | * |
---|
126 | * @param f the filter info record |
---|
127 | * @param bb the bucket brigade, where to store the result to |
---|
128 | * @return result status |
---|
129 | */ |
---|
130 | apr_status_t mod_gnutls_filter_output(ap_filter_t * f, |
---|
131 | apr_bucket_brigade * bb); |
---|
132 | |
---|
133 | |
---|
134 | /** |
---|
135 | * mod_gnutls_transport_read is called from GnuTLS to provide encrypted |
---|
136 | * data from the client. |
---|
137 | * |
---|
138 | * @param ptr pointer to the filter context |
---|
139 | * @param buffer place to put data |
---|
140 | * @param len maximum size |
---|
141 | * @return size length of the data stored in buffer |
---|
142 | */ |
---|
143 | ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, |
---|
144 | void *buffer, size_t len); |
---|
145 | |
---|
146 | /** |
---|
147 | * mod_gnutls_transport_write is called from GnuTLS to |
---|
148 | * write data to the client. |
---|
149 | * |
---|
150 | * @param ptr pointer to the filter context |
---|
151 | * @param buffer buffer to write to the client |
---|
152 | * @param len size of the buffer |
---|
153 | * @return size length of the data written |
---|
154 | */ |
---|
155 | ssize_t mod_gnutls_transport_write(gnutls_transport_ptr_t ptr, |
---|
156 | const void *buffer, size_t len); |
---|
157 | |
---|
158 | |
---|
159 | /** |
---|
160 | * Init the Cache after Configuration is done |
---|
161 | */ |
---|
162 | int mod_gnutls_cache_post_config(apr_pool_t *p, server_rec *s, |
---|
163 | mod_gnutls_srvconf_rec *sc); |
---|
164 | /** |
---|
165 | * Init the Cache inside each Process |
---|
166 | */ |
---|
167 | int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s, |
---|
168 | mod_gnutls_srvconf_rec *sc); |
---|
169 | /** |
---|
170 | * Setup the Session Caching |
---|
171 | */ |
---|
172 | int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt); |
---|
173 | |
---|
174 | #endif /* __mod_gnutls_h_inc */ |
---|