source: mod_gnutls/include/mod_gnutls.h.in @ 5e81262

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

Added support for sending more than one certificate.

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