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

debian/masterdebian/stretch-backportsjessie-backportsupstream
Last change on this file since bd24203 was bd24203, checked in by Thomas Klute <thomas2.klute@…>, 5 years ago

Explicitly build trust list for proxy connections

This change provides direct access to the trust list, which is required
for loading a CRL later.

  • Property mode set to 100644
File size: 13.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/* Apache Runtime Headers */
19#include "httpd.h"
20#include "http_config.h"
21#include "http_protocol.h"
22#include "http_connection.h"
23#include "http_request.h"
24#include "http_core.h"
25#include "http_log.h"
26#include "apr_buckets.h"
27#include "apr_strings.h"
28#include "apr_tables.h"
29#include "ap_release.h"
30#include "apr_fnmatch.h"
31/* GnuTLS Library Headers */
32#include <gnutls/gnutls.h>
33#if GNUTLS_VERSION_MAJOR == 2
34#include <gnutls/extra.h>
35#endif
36#include <gnutls/openpgp.h>
37#include <gnutls/x509.h>
38
39#ifndef __mod_gnutls_h_inc
40#define __mod_gnutls_h_inc
41
42#define HAVE_APR_MEMCACHE    @have_apr_memcache@
43
44extern module AP_MODULE_DECLARE_DATA gnutls_module;
45
46/* IO Filter names */
47#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
48#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
49/* GnuTLS Constants */
50#define GNUTLS_ENABLED_FALSE 0
51#define GNUTLS_ENABLED_TRUE  1
52#define GNUTLS_ENABLED_UNSET  2
53/* Current module version */
54#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
55
56/* Module Debug Mode */
57#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
58
59/*
60 * Recent Versions of 2.1 renamed several hooks.
61 * This allows us to compile on 2.0.xx
62 */
63#if AP_SERVER_MINORVERSION_NUMBER >= 2 || (AP_SERVER_MINORVERSION_NUMBER == 1 && AP_SERVER_PATCHLEVEL_NUMBER >= 3)
64        #define USING_2_1_RECENT 1
65#else
66        #define USING_2_1_RECENT 0
67#endif
68
69/* mod_gnutls Cache Types */
70typedef enum {
71        /* No Cache */
72    mgs_cache_none,
73        /* Use Old Berkley DB */
74    mgs_cache_dbm,
75        /* Use Gnu's version of Berkley DB */
76    mgs_cache_gdbm,
77#if HAVE_APR_MEMCACHE
78        /* Use Memcache */
79    mgs_cache_memcache,
80#endif
81    mgs_cache_unset
82} mgs_cache_e;
83
84typedef enum {
85    mgs_cvm_unset,
86    mgs_cvm_cartel,
87    mgs_cvm_msva
88} mgs_client_verification_method_e;
89
90
91/* Directory Configuration Record */
92typedef struct {
93    int client_verify_mode;
94    const char* lua_bytecode;
95    apr_size_t lua_bytecode_len;
96} mgs_dirconf_rec;
97
98
99/* The maximum number of certificates to send in a chain */
100#define MAX_CHAIN_SIZE 8
101/* The maximum number of SANs to read from a x509 certificate */
102#define MAX_CERT_SAN 5
103
104/* Server Configuration Record */
105typedef struct {
106    /* x509 Certificate Structure */
107    gnutls_certificate_credentials_t certs;
108    /* x509 credentials for proxy connections */
109    gnutls_certificate_credentials_t proxy_x509_creds;
110    /* trust list for proxy_x509_creds */
111    gnutls_x509_trust_list_t proxy_x509_tl;
112    const char* proxy_x509_key_file;
113    const char* proxy_x509_cert_file;
114    const char* proxy_x509_ca_file;
115    /* SRP Certificate Structure*/
116    gnutls_srp_server_credentials_t srp_creds;
117    /* Anonymous Certificate Structure */
118    gnutls_anon_server_credentials_t anon_creds;
119    /* Anonymous Client Certificate Structure, used for proxy
120     * connections */
121    gnutls_anon_client_credentials_t anon_client_creds;
122        /* Current x509 Certificate CN [Common Name] */
123    char* cert_cn;
124        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
125        char* cert_san[MAX_CERT_SAN];
126        /* A x509 Certificate Chain */
127    gnutls_x509_crt_t *certs_x509_chain;
128        /* Current x509 Certificate Private Key */
129    gnutls_x509_privkey_t privkey_x509;
130        /* OpenPGP Certificate */
131    gnutls_openpgp_crt_t cert_pgp;
132        /* OpenPGP Certificate Private Key */
133    gnutls_openpgp_privkey_t privkey_pgp;
134        /* Number of Certificates in Chain */
135    unsigned int certs_x509_chain_num;
136        /* Is the module enabled? */
137    int enabled;
138    /* Export full certificates to CGI environment: */
139    int export_certificates_size;
140        /* GnuTLS Priorities */
141    gnutls_priority_t priorities;
142        /* GnuTLS DH Parameters */
143    gnutls_dh_params_t dh_params;
144        /* Cache timeout value */
145    int cache_timeout;
146        /* Chose Cache Type */
147    mgs_cache_e cache_type;
148    const char* cache_config;
149    const char* srp_tpasswd_file;
150    const char* srp_tpasswd_conf_file;
151        /* A list of CA Certificates */
152    gnutls_x509_crt_t *ca_list;
153        /* OpenPGP Key Ring */
154    gnutls_openpgp_keyring_t pgp_list;
155        /* CA Certificate list size */
156    unsigned int ca_list_size;
157        /* Client Certificate Verification Mode */
158    int client_verify_mode;
159        /* Client Certificate Verification Method */
160    mgs_client_verification_method_e client_verify_method;
161        /* Last Cache timestamp */
162    apr_time_t last_cache_check;
163        /* GnuTLS uses Session Tickets */
164    int tickets;
165        /* Is mod_proxy enabled? */
166    int proxy_enabled;
167        /* A Plain HTTP request */
168    int non_ssl_request;
169} mgs_srvconf_rec;
170
171/* Character Buffer */
172typedef struct {
173    int length;
174    char *value;
175} mgs_char_buffer_t;
176
177/* GnuTLS Handle */
178typedef struct {
179        /* Server configuration record */
180    mgs_srvconf_rec *sc;
181        /* Connection record */
182    conn_rec* c;
183        /* Is TLS enabled for this connection? */
184    int enabled;
185    /* Is this a proxy connection? */
186    int is_proxy;
187        /* GnuTLS Session handle */
188    gnutls_session_t session;
189        /* module input status */
190    apr_status_t input_rc;
191        /* Input filter */
192    ap_filter_t *input_filter;
193        /* Input Bucket Brigade */
194    apr_bucket_brigade *input_bb;
195        /* Input Read Type */
196    apr_read_type_e input_block;
197        /* Input Mode */
198    ap_input_mode_t input_mode;
199        /* Input Character Buffer */
200    mgs_char_buffer_t input_cbuf;
201        /* Input Character Array */
202    char input_buffer[AP_IOBUFSIZE];
203        /* module Output status */
204    apr_status_t output_rc;
205        /* Output filter */
206    ap_filter_t *output_filter;
207        /* Output Bucket Brigade */
208    apr_bucket_brigade *output_bb;
209        /* Output character array */
210    char output_buffer[AP_IOBUFSIZE];
211        /* Output buffer length */
212    apr_size_t output_blen;
213        /* Output length */
214    apr_size_t output_length;
215        /* General Status */
216    int status;
217} mgs_handle_t;
218
219
220
221/** Functions in gnutls_io.c **/
222
223/* apr_signal_block() for blocking SIGPIPE */
224apr_status_t apr_signal_block(int signum);
225
226 /* Proxy Support */
227/* An optional function which returns non-zero if the given connection
228is using SSL/TLS. */
229APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
230/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
231 * are used by mod_proxy to enable use of SSL for outgoing
232 * connections. */
233APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
234APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
235int ssl_is_https(conn_rec *c);
236int ssl_proxy_enable(conn_rec *c);
237int ssl_engine_disable(conn_rec *c);
238const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
239    const char *arg);
240apr_status_t mgs_cleanup_pre_config(void *data);
241
242/**
243 * mgs_filter_input will filter the input data
244 * by decrypting it using GnuTLS and passes it cleartext.
245 *
246 * @param f     the filter info record
247 * @param bb    the bucket brigade, where to store the result to
248 * @param mode  what shall we read?
249 * @param block a block index we shall read from?
250 * @return result status
251 */
252apr_status_t mgs_filter_input(ap_filter_t * f,
253                                     apr_bucket_brigade * bb,
254                                     ap_input_mode_t mode,
255                                     apr_read_type_e block,
256                                     apr_off_t readbytes);
257
258/**
259 * mgs_filter_output will filter the encrypt
260 * the incoming bucket using GnuTLS and passes it onto the next filter.
261 *
262 * @param f     the filter info record
263 * @param bb    the bucket brigade, where to store the result to
264 * @return result status
265 */
266apr_status_t mgs_filter_output(ap_filter_t * f,
267                                      apr_bucket_brigade * bb);
268
269
270/**
271 * mgs_transport_read is called from GnuTLS to provide encrypted
272 * data from the client.
273 *
274 * @param ptr     pointer to the filter context
275 * @param buffer  place to put data
276 * @param len     maximum size
277 * @return size   length of the data stored in buffer
278 */
279ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
280                                  void *buffer, size_t len);
281
282/**
283 * mgs_transport_write is called from GnuTLS to
284 * write data to the client.
285 *
286 * @param ptr     pointer to the filter context
287 * @param buffer  buffer to write to the client
288 * @param len     size of the buffer
289 * @return size   length of the data written
290 */
291ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
292                                   const void *buffer, size_t len);
293
294
295int mgs_rehandshake(mgs_handle_t * ctxt);
296
297
298
299/**
300 * Init the Cache after Configuration is done
301 */
302int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
303                                 mgs_srvconf_rec *sc);
304/**
305 * Init the Cache inside each Process
306 */
307int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
308                                mgs_srvconf_rec *sc);
309/**
310 * Setup the Session Caching
311 */
312int mgs_cache_session_init(mgs_handle_t *ctxt);
313
314#define GNUTLS_SESSION_ID_STRING_LEN \
315    ((GNUTLS_MAX_SESSION_ID + 1) * 2)
316
317/**
318 * Convert a SSL Session ID into a Null Terminated Hex Encoded String
319 * @param id raw SSL Session ID
320 * @param idlen Length of the raw Session ID
321 * @param str Location to store the Hex Encoded String
322 * @param strsize The Maximum Length that can be stored in str
323 */
324char *mgs_session_id2sz(unsigned char *id, int idlen,
325                                char *str, int strsize);
326
327/**
328 * Convert a time_t into a Null Terminated String
329 * @param t time_t time
330 * @param str Location to store the Hex Encoded String
331 * @param strsize The Maximum Length that can be stored in str
332 */
333char *mgs_time2sz(time_t t, char *str, int strsize);
334
335
336/* Configuration Functions */
337
338const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
339                                        const char *arg);
340const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
341                                        const char *arg);
342const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
343                                        const char *arg);
344const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
345                                        const char *arg);
346
347const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
348                             const char *arg);
349
350const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
351                                        const char *arg);
352
353const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
354                             const char *arg);
355
356const char *mgs_set_cache(cmd_parms * parms, void *dummy,
357                          const char *type, const char* arg);
358
359const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy,
360                                  const char *arg);
361
362const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
363                                  const char *arg);
364
365const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
366                                         const char *arg);
367
368const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
369                                   const char *arg);
370
371const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
372                                   const char *arg);
373
374const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
375                            const char *arg);
376const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
377                            const char *arg);
378const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
379                            const char *arg);
380const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
381                            const char *arg);
382
383const char *mgs_set_require_section(cmd_parms *cmd,
384                                    void *mconfig, const char *arg);
385void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
386void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
387
388void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
389
390void *mgs_config_dir_create(apr_pool_t *p, char *dir);
391
392const char *mgs_set_require_bytecode(cmd_parms *cmd,
393                                    void *mconfig, const char *arg);
394
395mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
396
397const char *mgs_store_cred_path(cmd_parms * parms,
398                                void *dummy __attribute__((unused)),
399                                const char *arg);
400
401/* mod_gnutls Hooks. */
402
403int mgs_hook_pre_config(apr_pool_t * pconf,
404                        apr_pool_t * plog, apr_pool_t * ptemp);
405
406int mgs_hook_post_config(apr_pool_t * p, apr_pool_t * plog,
407                         apr_pool_t * ptemp,
408                         server_rec * base_server);
409
410void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
411
412const char *mgs_hook_http_scheme(const request_rec * r);
413
414apr_port_t mgs_hook_default_port(const request_rec * r);
415
416int mgs_hook_pre_connection(conn_rec * c, void *csd);
417
418int mgs_hook_fixups(request_rec *r);
419
420int mgs_hook_authz(request_rec *r);
421
422#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.