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 | #include "ap_release.h" |
---|
29 | |
---|
30 | #ifndef __mod_gnutls_h_inc |
---|
31 | #define __mod_gnutls_h_inc |
---|
32 | |
---|
33 | #define HAVE_APR_MEMCACHE @have_apr_memcache@ |
---|
34 | |
---|
35 | #include <gcrypt.h> |
---|
36 | #include <gnutls/gnutls.h> |
---|
37 | |
---|
38 | module AP_MODULE_DECLARE_DATA gnutls_module; |
---|
39 | |
---|
40 | #define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter" |
---|
41 | #define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter" |
---|
42 | |
---|
43 | #define GNUTLS_ENABLED_FALSE 0 |
---|
44 | #define GNUTLS_ENABLED_TRUE 1 |
---|
45 | |
---|
46 | #define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@" |
---|
47 | |
---|
48 | #define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@ |
---|
49 | |
---|
50 | /* Recent Versions of 2.1 renamed several hooks. This allows us to |
---|
51 | compile on 2.0.xx */ |
---|
52 | #if AP_SERVER_MINORVERSION_NUMBER >= 1 |
---|
53 | #if AP_SERVER_PATCHLEVEL_NUMBER >= 3 |
---|
54 | #define USING_2_1_RECENT 1 |
---|
55 | #endif |
---|
56 | #endif |
---|
57 | |
---|
58 | #ifndef USING_2_1_RECENT |
---|
59 | #define USING_2_1_RECENT 0 |
---|
60 | #endif |
---|
61 | |
---|
62 | typedef enum |
---|
63 | { |
---|
64 | mod_gnutls_cache_none, |
---|
65 | mod_gnutls_cache_dbm, |
---|
66 | #if HAVE_APR_MEMCACHE |
---|
67 | mod_gnutls_cache_memcache |
---|
68 | #endif |
---|
69 | } mod_gnutls_cache_e; |
---|
70 | |
---|
71 | typedef struct |
---|
72 | { |
---|
73 | gnutls_certificate_credentials_t certs; |
---|
74 | char *key_file; |
---|
75 | char *cert_file; |
---|
76 | int enabled; |
---|
77 | int ciphers[16]; |
---|
78 | int key_exchange[16]; |
---|
79 | int macs[16]; |
---|
80 | int protocol[16]; |
---|
81 | int compression[16]; |
---|
82 | int cert_types[16]; |
---|
83 | apr_time_t cache_timeout; |
---|
84 | mod_gnutls_cache_e cache_type; |
---|
85 | const char* cache_config; |
---|
86 | const char* rsa_params_file; |
---|
87 | const char* dh_params_file; |
---|
88 | } mod_gnutls_srvconf_rec; |
---|
89 | |
---|
90 | typedef struct { |
---|
91 | int length; |
---|
92 | char *value; |
---|
93 | } mod_gnutls_char_buffer_t; |
---|
94 | |
---|
95 | typedef struct |
---|
96 | { |
---|
97 | mod_gnutls_srvconf_rec *sc; |
---|
98 | conn_rec* c; |
---|
99 | gnutls_session_t session; |
---|
100 | |
---|
101 | apr_status_t input_rc; |
---|
102 | ap_filter_t *input_filter; |
---|
103 | apr_bucket_brigade *input_bb; |
---|
104 | apr_read_type_e input_block; |
---|
105 | ap_input_mode_t input_mode; |
---|
106 | mod_gnutls_char_buffer_t input_cbuf; |
---|
107 | char input_buffer[AP_IOBUFSIZE]; |
---|
108 | |
---|
109 | apr_status_t output_rc; |
---|
110 | ap_filter_t *output_filter; |
---|
111 | apr_bucket_brigade *output_bb; |
---|
112 | char output_buffer[AP_IOBUFSIZE]; |
---|
113 | apr_size_t output_blen; |
---|
114 | apr_size_t output_length; |
---|
115 | |
---|
116 | int status; |
---|
117 | int non_https; |
---|
118 | } mod_gnutls_handle_t; |
---|
119 | |
---|
120 | /** Functions in gnutls_io.c **/ |
---|
121 | |
---|
122 | /** |
---|
123 | * mod_gnutls_filter_input will filter the input data |
---|
124 | * by decrypting it using GnuTLS and passes it cleartext. |
---|
125 | * |
---|
126 | * @param f the filter info record |
---|
127 | * @param bb the bucket brigade, where to store the result to |
---|
128 | * @param mode what shall we read? |
---|
129 | * @param block a block index we shall read from? |
---|
130 | * @return result status |
---|
131 | */ |
---|
132 | apr_status_t mod_gnutls_filter_input(ap_filter_t * f, |
---|
133 | apr_bucket_brigade * bb, |
---|
134 | ap_input_mode_t mode, |
---|
135 | apr_read_type_e block, |
---|
136 | apr_off_t readbytes); |
---|
137 | |
---|
138 | /** |
---|
139 | * mod_gnutls_filter_output will filter the encrypt |
---|
140 | * the incoming bucket using GnuTLS and passes it onto the next filter. |
---|
141 | * |
---|
142 | * @param f the filter info record |
---|
143 | * @param bb the bucket brigade, where to store the result to |
---|
144 | * @return result status |
---|
145 | */ |
---|
146 | apr_status_t mod_gnutls_filter_output(ap_filter_t * f, |
---|
147 | apr_bucket_brigade * bb); |
---|
148 | |
---|
149 | |
---|
150 | /** |
---|
151 | * mod_gnutls_transport_read is called from GnuTLS to provide encrypted |
---|
152 | * data from the client. |
---|
153 | * |
---|
154 | * @param ptr pointer to the filter context |
---|
155 | * @param buffer place to put data |
---|
156 | * @param len maximum size |
---|
157 | * @return size length of the data stored in buffer |
---|
158 | */ |
---|
159 | ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, |
---|
160 | void *buffer, size_t len); |
---|
161 | |
---|
162 | /** |
---|
163 | * mod_gnutls_transport_write is called from GnuTLS to |
---|
164 | * write data to the client. |
---|
165 | * |
---|
166 | * @param ptr pointer to the filter context |
---|
167 | * @param buffer buffer to write to the client |
---|
168 | * @param len size of the buffer |
---|
169 | * @return size length of the data written |
---|
170 | */ |
---|
171 | ssize_t mod_gnutls_transport_write(gnutls_transport_ptr_t ptr, |
---|
172 | const void *buffer, size_t len); |
---|
173 | |
---|
174 | |
---|
175 | /** |
---|
176 | * Init the Cache after Configuration is done |
---|
177 | */ |
---|
178 | int mod_gnutls_cache_post_config(apr_pool_t *p, server_rec *s, |
---|
179 | mod_gnutls_srvconf_rec *sc); |
---|
180 | /** |
---|
181 | * Init the Cache inside each Process |
---|
182 | */ |
---|
183 | int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s, |
---|
184 | mod_gnutls_srvconf_rec *sc); |
---|
185 | /** |
---|
186 | * Setup the Session Caching |
---|
187 | */ |
---|
188 | int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt); |
---|
189 | |
---|
190 | #define GNUTLS_SESSION_ID_STRING_LEN \ |
---|
191 | ((GNUTLS_MAX_SESSION_ID + 1) * 2) |
---|
192 | |
---|
193 | /** |
---|
194 | * Convert a SSL Session ID into a Null Terminated Hex Encoded String |
---|
195 | * @param id raw SSL Session ID |
---|
196 | * @param idlen Length of the raw Session ID |
---|
197 | * @param str Location to store the Hex Encoded String |
---|
198 | * @param strsize The Maximum Length that can be stored in str |
---|
199 | */ |
---|
200 | char *mod_gnutls_session_id2sz(unsigned char *id, int idlen, |
---|
201 | char *str, int strsize); |
---|
202 | |
---|
203 | #endif /* __mod_gnutls_h_inc */ |
---|