source: mod_gnutls/include/mod_gnutls.h.in @ 0499540

debian/masterdebian/stretch-backportsjessie-backportsmsvaupstream
Last change on this file since 0499540 was 0499540, checked in by Nikos Mavrogiannopoulos <nmav@…>, 9 years ago

Use libgcrypt calls only if gnutls is older than 2.11.0

  • Property mode set to 100644
File size: 9.5 KB
Line 
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#include <gnutls/gnutls.h>
31#include <gnutls/extra.h>
32#include <gnutls/openpgp.h>
33#include <gnutls/x509.h>
34
35#ifndef __mod_gnutls_h_inc
36#define __mod_gnutls_h_inc
37
38#define HAVE_APR_MEMCACHE    @have_apr_memcache@
39
40extern module AP_MODULE_DECLARE_DATA gnutls_module;
41
42#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
43#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
44
45#define GNUTLS_ENABLED_FALSE 0
46#define GNUTLS_ENABLED_TRUE  1
47
48#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
49
50#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
51
52/* Recent Versions of 2.1 renamed several hooks. This allows us to
53   compile on 2.0.xx  */
54#if AP_SERVER_MINORVERSION_NUMBER >= 2 || (AP_SERVER_MINORVERSION_NUMBER == 1 && AP_SERVER_PATCHLEVEL_NUMBER >= 3)
55#define USING_2_1_RECENT 1
56#endif
57
58#ifndef USING_2_1_RECENT
59#define USING_2_1_RECENT 0
60#endif
61
62typedef enum
63{
64    mgs_cache_none,
65    mgs_cache_dbm,
66#if HAVE_APR_MEMCACHE
67    mgs_cache_memcache
68#endif
69} mgs_cache_e;
70
71typedef struct
72{
73    int client_verify_mode;
74    const char* lua_bytecode;
75    apr_size_t lua_bytecode_len;
76} mgs_dirconf_rec;
77
78
79/* The maximum number of certificates to send in a chain
80 */
81#define MAX_CHAIN_SIZE 8
82
83typedef struct
84{
85    gnutls_certificate_credentials_t certs;
86    gnutls_srp_server_credentials_t srp_creds;
87    gnutls_anon_server_credentials_t anon_creds;
88    char* cert_cn;
89    gnutls_x509_crt_t certs_x509[MAX_CHAIN_SIZE]; /* A certificate chain */
90    unsigned int certs_x509_num;
91    gnutls_x509_privkey_t privkey_x509;
92    gnutls_openpgp_crt_t cert_pgp; /* A certificate chain */
93    gnutls_openpgp_privkey_t privkey_pgp;
94    int enabled;
95    /* whether to send the PEM encoded certificates
96     * to CGIs
97     */
98    int export_certificates_enabled;
99    gnutls_priority_t priorities;
100    gnutls_rsa_params_t rsa_params;
101    gnutls_dh_params_t dh_params;
102    int cache_timeout;
103    mgs_cache_e cache_type;
104    const char* cache_config;
105    const char* srp_tpasswd_file;
106    const char* srp_tpasswd_conf_file;
107    gnutls_x509_crt_t *ca_list;
108    gnutls_openpgp_keyring_t pgp_list;
109    unsigned int ca_list_size;
110    int client_verify_mode;
111} mgs_srvconf_rec;
112
113typedef struct {
114    int length;
115    char *value;
116} mgs_char_buffer_t;
117
118typedef struct
119{
120    mgs_srvconf_rec *sc;
121    conn_rec* c;
122    gnutls_session_t session;
123
124    apr_status_t input_rc;
125    ap_filter_t *input_filter;
126    apr_bucket_brigade *input_bb;
127    apr_read_type_e input_block;
128    ap_input_mode_t input_mode;
129    mgs_char_buffer_t input_cbuf;
130    char input_buffer[AP_IOBUFSIZE];
131
132    apr_status_t output_rc;
133    ap_filter_t *output_filter;
134    apr_bucket_brigade *output_bb;
135    char output_buffer[AP_IOBUFSIZE];
136    apr_size_t output_blen;
137    apr_size_t output_length;
138
139    int status;
140    int non_https;
141} mgs_handle_t;
142
143/** Functions in gnutls_io.c **/
144
145/**
146 * mgs_filter_input will filter the input data
147 * by decrypting it using GnuTLS and passes it cleartext.
148 *
149 * @param f     the filter info record
150 * @param bb    the bucket brigade, where to store the result to
151 * @param mode  what shall we read?
152 * @param block a block index we shall read from?
153 * @return result status
154 */
155apr_status_t mgs_filter_input(ap_filter_t * f,
156                                     apr_bucket_brigade * bb,
157                                     ap_input_mode_t mode,
158                                     apr_read_type_e block,
159                                     apr_off_t readbytes);
160
161/**
162 * mgs_filter_output will filter the encrypt
163 * the incoming bucket using GnuTLS and passes it onto the next filter.
164 *
165 * @param f     the filter info record
166 * @param bb    the bucket brigade, where to store the result to
167 * @return result status
168 */
169apr_status_t mgs_filter_output(ap_filter_t * f,
170                                      apr_bucket_brigade * bb);
171
172
173/**
174 * mgs_transport_read is called from GnuTLS to provide encrypted
175 * data from the client.
176 *
177 * @param ptr     pointer to the filter context
178 * @param buffer  place to put data
179 * @param len     maximum size
180 * @return size   length of the data stored in buffer
181 */
182ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
183                                  void *buffer, size_t len);
184
185/**
186 * mgs_transport_write is called from GnuTLS to
187 * write data to the client.
188 *
189 * @param ptr     pointer to the filter context
190 * @param buffer  buffer to write to the client
191 * @param len     size of the buffer
192 * @return size   length of the data written
193 */
194ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
195                                   const void *buffer, size_t len);
196
197
198int mgs_rehandshake(mgs_handle_t * ctxt);
199
200
201
202/**
203 * Init the Cache after Configuration is done
204 */
205int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
206                                 mgs_srvconf_rec *sc);
207/**
208 * Init the Cache inside each Process
209 */
210int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
211                                mgs_srvconf_rec *sc);
212/**
213 * Setup the Session Caching
214 */
215int mgs_cache_session_init(mgs_handle_t *ctxt);
216
217#define GNUTLS_SESSION_ID_STRING_LEN \
218    ((GNUTLS_MAX_SESSION_ID + 1) * 2)
219   
220/**
221 * Convert a SSL Session ID into a Null Terminated Hex Encoded String
222 * @param id raw SSL Session ID
223 * @param idlen Length of the raw Session ID
224 * @param str Location to store the Hex Encoded String
225 * @param strsize The Maximum Length that can be stored in str
226 */
227char *mgs_session_id2sz(unsigned char *id, int idlen,
228                                char *str, int strsize);
229
230/**
231 * Convert a time_t into a Null Terminated String
232 * @param t time_t time
233 * @param str Location to store the Hex Encoded String
234 * @param strsize The Maximum Length that can be stored in str
235 */
236char *mgs_time2sz(time_t t, char *str, int strsize);
237
238
239/* Configuration Functions */
240
241const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
242                                        const char *arg);
243const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
244                                        const char *arg);
245const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
246                                        const char *arg);
247const char *mgs_set_rsa_export_file(cmd_parms * parms, void *dummy,
248                                        const char *arg);
249const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
250                                        const char *arg);
251
252const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
253                             const char *arg);
254
255const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
256                                        const char *arg);
257
258const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
259                             const char *arg);
260
261const char *mgs_set_cache(cmd_parms * parms, void *dummy,
262                          const char *type, const char* arg);
263
264const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy,
265                                  const char *arg);
266
267const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
268                                  const char *arg);
269
270const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
271                                   const char *arg);
272
273const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
274                                   const char *arg);
275
276const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
277                            const char *arg);
278const char *mgs_set_export_certificates_enabled(cmd_parms * parms, void *dummy,
279                            const char *arg);
280const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
281                            const char *arg);
282                           
283const char *mgs_set_require_section(cmd_parms *cmd,
284                                    void *mconfig, const char *arg);
285void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
286
287void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
288
289void *mgs_config_dir_create(apr_pool_t *p, char *dir);
290
291const char *mgs_set_require_bytecode(cmd_parms *cmd,
292                                    void *mconfig, const char *arg);
293
294mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
295
296/* mod_gnutls Hooks. */
297
298int mgs_hook_pre_config(apr_pool_t * pconf,
299                        apr_pool_t * plog, apr_pool_t * ptemp);
300
301int mgs_hook_post_config(apr_pool_t * p, apr_pool_t * plog,
302                         apr_pool_t * ptemp,
303                         server_rec * base_server);
304
305void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
306
307const char *mgs_hook_http_scheme(const request_rec * r);
308
309apr_port_t mgs_hook_default_port(const request_rec * r);
310
311int mgs_hook_pre_connection(conn_rec * c, void *csd);
312
313int mgs_hook_fixups(request_rec *r);
314
315int mgs_hook_authz(request_rec *r);
316
317int mgs_authz_lua(request_rec* r);
318
319#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.