source: mod_gnutls/include/mod_gnutls.h.in @ 7e67487

debian/masterdebian/stretch-backportsjessie-backportsmsvaupstream
Last change on this file since 7e67487 was 7e67487, checked in by Nokis Mavrogiannopoulos <nmav@…>, 10 years ago

Applied patch to allow building with Apache 2.4. Patch by Arfrever Frehtes Taifersar Arahesis <arfrever.fta@…>.

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