source: mod_gnutls/include/mod_gnutls.h.in @ 0e3f8c6

debian/masterproxy-ticket
Last change on this file since 0e3f8c6 was 0e3f8c6, checked in by Fiona Klute <fiona.klute@…>, 3 years ago

Create module-wide singleton watchdog during post_config

  • Property mode set to 100644
File size: 15.2 KB
Line 
1/*
2 *  Copyright 2004-2005 Paul Querna
3 *  Copyright 2014 Nikos Mavrogiannopoulos
4 *  Copyright 2015-2018 Fiona Klute
5 *
6 *  Licensed under the Apache License, Version 2.0 (the "License");
7 *  you may not use this file except in compliance with the License.
8 *  You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *  Unless required by applicable law or agreed to in writing, software
13 *  distributed under the License is distributed on an "AS IS" BASIS,
14 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *  See the License for the specific language governing permissions and
16 *  limitations under the License.
17 */
18
19/* Apache Runtime Headers */
20#include "httpd.h"
21#include "http_config.h"
22#include "http_protocol.h"
23#include "http_connection.h"
24#include "http_request.h"
25#include "http_core.h"
26#include "http_log.h"
27#include "apr_buckets.h"
28#include "apr_strings.h"
29#include "apr_tables.h"
30#include "ap_release.h"
31#include "apr_fnmatch.h"
32/* GnuTLS Library Headers */
33#include <gnutls/gnutls.h>
34#include <gnutls/abstract.h>
35#include <gnutls/openpgp.h>
36#include <gnutls/x509.h>
37
38#ifndef __mod_gnutls_h_inc
39#define __mod_gnutls_h_inc
40
41#define HAVE_APR_MEMCACHE    @have_apr_memcache@
42
43extern module AP_MODULE_DECLARE_DATA gnutls_module;
44
45/* IO Filter names */
46#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
47#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
48/* GnuTLS Constants */
49#define GNUTLS_ENABLED_FALSE 0
50#define GNUTLS_ENABLED_TRUE  1
51#define GNUTLS_ENABLED_UNSET  2
52/* Current module version */
53#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
54
55/* Module Debug Mode */
56#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
57
58/** Name of the module-wide singleton watchdog */
59#define MGS_SINGLETON_WATCHDOG "_mod_gnutls_singleton_"
60
61
62/* mod_gnutls Cache Types */
63typedef enum {
64        /* No Cache */
65    mgs_cache_none,
66        /* Use Old Berkley DB */
67    mgs_cache_dbm,
68        /* Use Gnu's version of Berkley DB */
69    mgs_cache_gdbm,
70#if HAVE_APR_MEMCACHE
71        /* Use Memcache */
72    mgs_cache_memcache,
73#endif
74    mgs_cache_unset
75} mgs_cache_e;
76
77/* Internal cache data, defined in gnutls_cache.h */
78typedef struct mgs_cache* mgs_cache_t;
79
80typedef enum {
81    mgs_cvm_unset,
82    mgs_cvm_cartel,
83    mgs_cvm_msva
84} mgs_client_verification_method_e;
85
86
87/* Directory Configuration Record */
88typedef struct {
89    int client_verify_mode;
90} mgs_dirconf_rec;
91
92
93/* Internal per-vhost config for OCSP, defined in gnutls_ocsp.h */
94typedef struct mgs_ocsp_data* mgs_ocsp_data_t;
95
96
97/* The maximum number of certificates to send in a chain */
98#define MAX_CHAIN_SIZE 8
99/* The maximum number of SANs to read from a x509 certificate */
100#define MAX_CERT_SAN 5
101
102/** Server Configuration Record */
103typedef struct {
104    /* --- Configuration values --- */
105        /* Is the module enabled? */
106    int enabled;
107        /* Is mod_proxy enabled? */
108    int proxy_enabled;
109        /* A Plain HTTP request */
110    int non_ssl_request;
111
112    /* List of PKCS #11 provider modules to load, only valid in the
113     * base config, ignored in virtual hosts */
114    apr_array_header_t *p11_modules;
115
116    /* PIN used for PKCS #11 operations */
117    char *pin;
118
119    /* the SRK PIN used in TPM operations */
120    char *srk_pin;
121
122    char *x509_cert_file;
123    char *x509_key_file;
124    char *x509_ca_file;
125
126    char *pgp_cert_file;
127    char *pgp_key_file;
128    char *pgp_ring_file;
129
130    char *dh_file;
131
132    char *priorities_str;
133    char *proxy_priorities_str;
134
135    const char* srp_tpasswd_file;
136    const char* srp_tpasswd_conf_file;
137
138        /* Cache timeout value */
139    int cache_timeout;
140        /* Chose Cache Type */
141    mgs_cache_e cache_type;
142    const char* cache_config;
143    /* Internal cache data */
144    mgs_cache_t cache;
145
146        /* GnuTLS uses Session Tickets */
147    int tickets;
148
149    /* x509 Certificate Structure */
150    gnutls_certificate_credentials_t certs;
151    /* x509 credentials for proxy connections */
152    gnutls_certificate_credentials_t proxy_x509_creds;
153    /* trust list for proxy_x509_creds */
154    gnutls_x509_trust_list_t proxy_x509_tl;
155    const char* proxy_x509_key_file;
156    const char* proxy_x509_cert_file;
157    const char* proxy_x509_ca_file;
158    const char* proxy_x509_crl_file;
159    /* GnuTLS priorities for proxy connections */
160    gnutls_priority_t proxy_priorities;
161    /* SRP Certificate Structure*/
162    gnutls_srp_server_credentials_t srp_creds;
163    /* Anonymous Certificate Structure */
164    gnutls_anon_server_credentials_t anon_creds;
165    /* Anonymous Client Certificate Structure, used for proxy
166     * connections */
167    gnutls_anon_client_credentials_t anon_client_creds;
168        /* Current x509 Certificate CN [Common Name] */
169    char* cert_cn;
170        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
171    char* cert_san[MAX_CERT_SAN];
172        /* An x509 Certificate Chain */
173    gnutls_pcert_st *certs_x509_chain;
174    gnutls_x509_crt_t *certs_x509_crt_chain;
175        /* Number of Certificates in Chain */
176    unsigned int certs_x509_chain_num;
177
178        /* Current x509 Certificate Private Key */
179    gnutls_privkey_t privkey_x509;
180
181        /* OpenPGP Certificate */
182    gnutls_pcert_st *cert_pgp;
183    gnutls_openpgp_crt_t *cert_crt_pgp;
184
185        /* OpenPGP Certificate Private Key */
186    gnutls_privkey_t privkey_pgp;
187#if GNUTLS_VERSION_NUMBER < 0x030312
188    /* Internal structure for the OpenPGP private key, used in the
189     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
190     * frees memory that is still needed. DO NOT USE for any other
191     * purpose. */
192    gnutls_openpgp_privkey_t privkey_pgp_internal;
193#endif
194
195    /* Export full certificates to CGI environment: */
196    int export_certificates_size;
197        /* GnuTLS Priorities */
198    gnutls_priority_t priorities;
199        /* GnuTLS DH Parameters */
200    gnutls_dh_params_t dh_params;
201        /* A list of CA Certificates */
202    gnutls_x509_crt_t *ca_list;
203        /* OpenPGP Key Ring */
204    gnutls_openpgp_keyring_t pgp_list;
205        /* CA Certificate list size */
206    unsigned int ca_list_size;
207        /* Client Certificate Verification Mode */
208    int client_verify_mode;
209        /* Client Certificate Verification Method */
210    mgs_client_verification_method_e client_verify_method;
211        /* Last Cache timestamp */
212    apr_time_t last_cache_check;
213
214    /* Enable OCSP stapling */
215    unsigned char ocsp_staple;
216    /* Check nonce in OCSP responses? */
217    unsigned char ocsp_check_nonce;
218    /* Read OCSP response for stapling from this file instead of
219     * sending a request over HTTP */
220    char *ocsp_response_file;
221    /* Internal OCSP data for this server */
222    mgs_ocsp_data_t ocsp;
223    /* Mutex to prevent parallel OCSP requests */
224    apr_global_mutex_t *ocsp_mutex;
225    /* Cache timeout for OCSP responses. Note that the nextUpdate
226     * field of the response takes precedence if shorter. */
227    apr_interval_time_t ocsp_cache_time;
228    /* If an OCSP request fails wait this long before trying again. */
229    apr_interval_time_t ocsp_failure_timeout;
230    /* Socket timeout for OCSP requests */
231    apr_interval_time_t ocsp_socket_timeout;
232
233    /** This module's singleton watchdog, used for async OCSP cache
234     * updates. */
235    struct mgs_watchdog *singleton_wd;
236} mgs_srvconf_rec;
237
238/* Character Buffer */
239typedef struct {
240    int length;
241    char *value;
242} mgs_char_buffer_t;
243
244/* GnuTLS Handle */
245typedef struct {
246        /* Server configuration record */
247    mgs_srvconf_rec *sc;
248        /* Connection record */
249    conn_rec* c;
250        /* Is TLS enabled for this connection? */
251    int enabled;
252    /* Is this a proxy connection? */
253    int is_proxy;
254        /* GnuTLS Session handle */
255    gnutls_session_t session;
256        /* module input status */
257    apr_status_t input_rc;
258        /* Input filter */
259    ap_filter_t *input_filter;
260        /* Input Bucket Brigade */
261    apr_bucket_brigade *input_bb;
262        /* Input Read Type */
263    apr_read_type_e input_block;
264        /* Input Mode */
265    ap_input_mode_t input_mode;
266        /* Input Character Buffer */
267    mgs_char_buffer_t input_cbuf;
268        /* Input Character Array */
269    char input_buffer[AP_IOBUFSIZE];
270        /* module Output status */
271    apr_status_t output_rc;
272        /* Output filter */
273    ap_filter_t *output_filter;
274        /* Output Bucket Brigade */
275    apr_bucket_brigade *output_bb;
276        /* Output character array */
277    char output_buffer[AP_IOBUFSIZE];
278        /* Output buffer length */
279    apr_size_t output_blen;
280        /* Output length */
281    apr_size_t output_length;
282        /* General Status */
283    int status;
284} mgs_handle_t;
285
286
287
288/** Functions in gnutls_io.c **/
289
290/* apr_signal_block() for blocking SIGPIPE */
291apr_status_t apr_signal_block(int signum);
292
293/* Proxy Support */
294/** mod_proxy adds a note with this key to the connection->notes table
295 * for client connections */
296#define PROXY_SNI_NOTE "proxy-request-hostname"
297/* An optional function which returns non-zero if the given connection
298is using SSL/TLS. */
299APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
300/* The ssl_var_lookup() optional function retrieves SSL environment
301 * variables. */
302APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
303                        (apr_pool_t *, server_rec *,
304                         conn_rec *, request_rec *,
305                         char *));
306/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
307 * are used by mod_proxy to enable use of SSL for outgoing
308 * connections. */
309APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
310APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
311APR_DECLARE_OPTIONAL_FN(int, ssl_engine_set, (conn_rec *,
312                                              ap_conf_vector_t *,
313                                              int proxy, int enable));
314mgs_handle_t* get_effective_gnutls_ctxt(conn_rec *c);
315int ssl_is_https(conn_rec *c);
316char* ssl_var_lookup(apr_pool_t *p, server_rec *s, conn_rec *c,
317                     request_rec *r, char *var);
318int ssl_proxy_enable(conn_rec *c);
319int ssl_engine_disable(conn_rec *c);
320const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
321                                 const int arg);
322apr_status_t mgs_cleanup_pre_config(void *data);
323
324/**
325 * mgs_filter_input will filter the input data
326 * by decrypting it using GnuTLS and passes it cleartext.
327 *
328 * @param f     the filter info record
329 * @param bb    the bucket brigade, where to store the result to
330 * @param mode  what shall we read?
331 * @param block a block index we shall read from?
332 * @return result status
333 */
334apr_status_t mgs_filter_input(ap_filter_t * f,
335                                     apr_bucket_brigade * bb,
336                                     ap_input_mode_t mode,
337                                     apr_read_type_e block,
338                                     apr_off_t readbytes);
339
340/**
341 * mgs_filter_output will filter the encrypt
342 * the incoming bucket using GnuTLS and passes it onto the next filter.
343 *
344 * @param f     the filter info record
345 * @param bb    the bucket brigade, where to store the result to
346 * @return result status
347 */
348apr_status_t mgs_filter_output(ap_filter_t * f,
349                                      apr_bucket_brigade * bb);
350
351
352/**
353 * mgs_transport_read is called from GnuTLS to provide encrypted
354 * data from the client.
355 *
356 * @param ptr     pointer to the filter context
357 * @param buffer  place to put data
358 * @param len     maximum size
359 * @return size   length of the data stored in buffer
360 */
361ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
362                                  void *buffer, size_t len);
363
364/**
365 * mgs_transport_write is called from GnuTLS to
366 * write data to the client.
367 *
368 * @param ptr     pointer to the filter context
369 * @param buffer  buffer to write to the client
370 * @param len     size of the buffer
371 * @return size   length of the data written
372 */
373ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
374                                   const void *buffer, size_t len);
375
376
377int mgs_rehandshake(mgs_handle_t * ctxt);
378
379
380
381/**
382 * Perform any reinitialization required in PKCS #11
383 */
384int mgs_pkcs11_reinit(server_rec * s);
385
386
387
388/* Configuration Functions */
389
390/* Loads all files set in the configuration */
391int mgs_load_files(apr_pool_t *pconf, apr_pool_t *ptemp, server_rec *s)
392    __attribute__((nonnull));
393
394const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
395                                        const char *arg);
396const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
397                                        const char *arg);
398const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
399                                        const char *arg);
400const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
401                                        const char *arg);
402
403const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
404                             const char *arg);
405
406const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
407                                        const char *arg);
408
409const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
410                             const char *arg);
411
412const char *mgs_set_cache(cmd_parms * parms, void *dummy,
413                          const char *type, const char* arg);
414
415const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
416
417const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
418                                  const char *arg);
419
420const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
421                                         const char *arg);
422
423const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
424                                   const char *arg);
425
426const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
427                               const char *arg);
428
429const char *mgs_set_pin(cmd_parms * parms, void *dummy,
430                                   const char *arg);
431
432const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
433                                   const char *arg);
434
435const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
436                                   const char *arg);
437
438const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
439                            const int arg);
440const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
441                            const char *arg);
442const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
443                            const char *arg);
444const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
445                            const int arg);
446
447void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
448void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
449
450void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
451
452void *mgs_config_dir_create(apr_pool_t *p, char *dir);
453
454mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
455
456const char *mgs_store_cred_path(cmd_parms * parms,
457                                void *dummy __attribute__((unused)),
458                                const char *arg);
459
460/* mod_gnutls Hooks. */
461
462int mgs_hook_pre_config(apr_pool_t * pconf,
463                        apr_pool_t * plog, apr_pool_t * ptemp);
464
465int mgs_hook_post_config(apr_pool_t *pconf,
466                         apr_pool_t *plog,
467                         apr_pool_t *ptemp,
468                         server_rec *base_server);
469
470void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
471
472const char *mgs_hook_http_scheme(const request_rec * r);
473
474apr_port_t mgs_hook_default_port(const request_rec * r);
475
476int mgs_hook_pre_connection(conn_rec * c, void *csd);
477
478int mgs_hook_process_connection(conn_rec* c);
479
480int mgs_hook_fixups(request_rec *r);
481
482int mgs_hook_authz(request_rec *r);
483
484#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.