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

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

Replace internal cache implementation with mod_socache

Massively simplifies mod_gnutls code, and using mod_socache_shmcb will
allow for extremely simple cache setup (no configuration needed as
long as the module is available, not implemented yet).

  • Property mode set to 100644
File size: 14.6 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/x509.h>
36
37#ifndef __mod_gnutls_h_inc
38#define __mod_gnutls_h_inc
39
40#define HAVE_APR_MEMCACHE    @have_apr_memcache@
41
42extern module AP_MODULE_DECLARE_DATA gnutls_module;
43
44/* IO Filter names */
45#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
46#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
47/* GnuTLS Constants */
48#define GNUTLS_ENABLED_FALSE 0
49#define GNUTLS_ENABLED_TRUE  1
50#define GNUTLS_ENABLED_UNSET  2
51/* Current module version */
52#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
53
54/* Module Debug Mode */
55#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
56
57/** Name of the module-wide singleton watchdog */
58#define MGS_SINGLETON_WATCHDOG "_mod_gnutls_singleton_"
59
60
61/* mod_gnutls Cache Types */
62typedef enum {
63        /* No Cache */
64    mgs_cache_none,
65        /* Use Old Berkley DB */
66    mgs_cache_dbm,
67        /* Use Gnu's version of Berkley DB */
68    mgs_cache_gdbm,
69#if HAVE_APR_MEMCACHE
70        /* Use Memcache */
71    mgs_cache_memcache,
72#endif
73    mgs_cache_shmcb,
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 *dh_file;
127
128    char *priorities_str;
129    char *proxy_priorities_str;
130
131    const char* srp_tpasswd_file;
132    const char* srp_tpasswd_conf_file;
133
134        /* Cache timeout value */
135    int cache_timeout;
136        /* Chose Cache Type */
137    mgs_cache_e cache_type;
138    const char* cache_config;
139    /* Internal cache data */
140    mgs_cache_t cache;
141
142        /* GnuTLS uses Session Tickets */
143    int tickets;
144
145    /* x509 Certificate Structure */
146    gnutls_certificate_credentials_t certs;
147    /* x509 credentials for proxy connections */
148    gnutls_certificate_credentials_t proxy_x509_creds;
149    /* trust list for proxy_x509_creds */
150    gnutls_x509_trust_list_t proxy_x509_tl;
151    const char* proxy_x509_key_file;
152    const char* proxy_x509_cert_file;
153    const char* proxy_x509_ca_file;
154    const char* proxy_x509_crl_file;
155    /* GnuTLS priorities for proxy connections */
156    gnutls_priority_t proxy_priorities;
157    /* SRP Certificate Structure*/
158    gnutls_srp_server_credentials_t srp_creds;
159    /* Anonymous Certificate Structure */
160    gnutls_anon_server_credentials_t anon_creds;
161    /* Anonymous Client Certificate Structure, used for proxy
162     * connections */
163    gnutls_anon_client_credentials_t anon_client_creds;
164        /* Current x509 Certificate CN [Common Name] */
165    char* cert_cn;
166        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
167    char* cert_san[MAX_CERT_SAN];
168        /* An x509 Certificate Chain */
169    gnutls_pcert_st *certs_x509_chain;
170    gnutls_x509_crt_t *certs_x509_crt_chain;
171        /* Number of Certificates in Chain */
172    unsigned int certs_x509_chain_num;
173
174        /* Current x509 Certificate Private Key */
175    gnutls_privkey_t privkey_x509;
176
177    /* Export full certificates to CGI environment: */
178    int export_certificates_size;
179        /* GnuTLS Priorities */
180    gnutls_priority_t priorities;
181        /* GnuTLS DH Parameters */
182    gnutls_dh_params_t dh_params;
183        /* A list of CA Certificates */
184    gnutls_x509_crt_t *ca_list;
185        /* CA Certificate list size */
186    unsigned int ca_list_size;
187        /* Client Certificate Verification Mode */
188    int client_verify_mode;
189        /* Client Certificate Verification Method */
190    mgs_client_verification_method_e client_verify_method;
191        /* Last Cache timestamp */
192    apr_time_t last_cache_check;
193
194    /* Enable OCSP stapling */
195    unsigned char ocsp_staple;
196    /* Automatically refresh cached OCSP response? */
197    unsigned char ocsp_auto_refresh;
198    /* Check nonce in OCSP responses? */
199    unsigned char ocsp_check_nonce;
200    /* Read OCSP response for stapling from this file instead of
201     * sending a request over HTTP */
202    char *ocsp_response_file;
203    /* Internal OCSP data for this server */
204    mgs_ocsp_data_t ocsp;
205    /* Mutex to prevent parallel OCSP requests */
206    apr_global_mutex_t *ocsp_mutex;
207    /* Cache timeout for OCSP responses. Note that the nextUpdate
208     * field of the response takes precedence if shorter. */
209    apr_interval_time_t ocsp_cache_time;
210    /* If an OCSP request fails wait this long before trying again. */
211    apr_interval_time_t ocsp_failure_timeout;
212    /** How long before a cached OCSP response expires should it be
213     * updated? During configuration parsing this is set to the
214     * maximum, during post configuration the value will be set to
215     * half that. After each update the interval to for the next one
216     * is choosen randomly as `ocsp_fuzz_time + ocsp_fuzz_time *
217     * RANDOM` with `0 <= RANDOM <= 1`. */
218    apr_interval_time_t ocsp_fuzz_time;
219    /* Socket timeout for OCSP requests */
220    apr_interval_time_t ocsp_socket_timeout;
221
222    /** This module's singleton watchdog, used for async OCSP cache
223     * updates. */
224    struct mgs_watchdog *singleton_wd;
225} mgs_srvconf_rec;
226
227/* Character Buffer */
228typedef struct {
229    int length;
230    char *value;
231} mgs_char_buffer_t;
232
233/* GnuTLS Handle */
234typedef struct {
235        /* Server configuration record */
236    mgs_srvconf_rec *sc;
237        /* Connection record */
238    conn_rec* c;
239        /* Is TLS enabled for this connection? */
240    int enabled;
241    /* Is this a proxy connection? */
242    int is_proxy;
243        /* GnuTLS Session handle */
244    gnutls_session_t session;
245        /* module input status */
246    apr_status_t input_rc;
247        /* Input filter */
248    ap_filter_t *input_filter;
249        /* Input Bucket Brigade */
250    apr_bucket_brigade *input_bb;
251        /* Input Read Type */
252    apr_read_type_e input_block;
253        /* Input Mode */
254    ap_input_mode_t input_mode;
255        /* Input Character Buffer */
256    mgs_char_buffer_t input_cbuf;
257        /* Input Character Array */
258    char input_buffer[AP_IOBUFSIZE];
259        /* module Output status */
260    apr_status_t output_rc;
261        /* Output filter */
262    ap_filter_t *output_filter;
263        /* Output Bucket Brigade */
264    apr_bucket_brigade *output_bb;
265        /* Output character array */
266    char output_buffer[AP_IOBUFSIZE];
267        /* Output buffer length */
268    apr_size_t output_blen;
269        /* Output length */
270    apr_size_t output_length;
271        /* General Status */
272    int status;
273} mgs_handle_t;
274
275
276
277/** Functions in gnutls_io.c **/
278
279/* apr_signal_block() for blocking SIGPIPE */
280apr_status_t apr_signal_block(int signum);
281
282/* Proxy Support */
283/** mod_proxy adds a note with this key to the connection->notes table
284 * for client connections */
285#define PROXY_SNI_NOTE "proxy-request-hostname"
286/* An optional function which returns non-zero if the given connection
287is using SSL/TLS. */
288APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
289/* The ssl_var_lookup() optional function retrieves SSL environment
290 * variables. */
291APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
292                        (apr_pool_t *, server_rec *,
293                         conn_rec *, request_rec *,
294                         char *));
295/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
296 * are used by mod_proxy to enable use of SSL for outgoing
297 * connections. */
298APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
299APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
300APR_DECLARE_OPTIONAL_FN(int, ssl_engine_set, (conn_rec *,
301                                              ap_conf_vector_t *,
302                                              int proxy, int enable));
303mgs_handle_t* get_effective_gnutls_ctxt(conn_rec *c);
304int ssl_is_https(conn_rec *c);
305char* ssl_var_lookup(apr_pool_t *p, server_rec *s, conn_rec *c,
306                     request_rec *r, char *var);
307int ssl_proxy_enable(conn_rec *c);
308int ssl_engine_disable(conn_rec *c);
309const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
310                                 const int arg);
311apr_status_t mgs_cleanup_pre_config(void *data);
312
313/**
314 * mgs_filter_input will filter the input data
315 * by decrypting it using GnuTLS and passes it cleartext.
316 *
317 * @param f     the filter info record
318 * @param bb    the bucket brigade, where to store the result to
319 * @param mode  what shall we read?
320 * @param block a block index we shall read from?
321 * @return result status
322 */
323apr_status_t mgs_filter_input(ap_filter_t * f,
324                                     apr_bucket_brigade * bb,
325                                     ap_input_mode_t mode,
326                                     apr_read_type_e block,
327                                     apr_off_t readbytes);
328
329/**
330 * mgs_filter_output will filter the encrypt
331 * the incoming bucket using GnuTLS and passes it onto the next filter.
332 *
333 * @param f     the filter info record
334 * @param bb    the bucket brigade, where to store the result to
335 * @return result status
336 */
337apr_status_t mgs_filter_output(ap_filter_t * f,
338                                      apr_bucket_brigade * bb);
339
340
341/**
342 * mgs_transport_read is called from GnuTLS to provide encrypted
343 * data from the client.
344 *
345 * @param ptr     pointer to the filter context
346 * @param buffer  place to put data
347 * @param len     maximum size
348 * @return size   length of the data stored in buffer
349 */
350ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
351                                  void *buffer, size_t len);
352
353/**
354 * mgs_transport_write is called from GnuTLS to
355 * write data to the client.
356 *
357 * @param ptr     pointer to the filter context
358 * @param buffer  buffer to write to the client
359 * @param len     size of the buffer
360 * @return size   length of the data written
361 */
362ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
363                                   const void *buffer, size_t len);
364
365
366int mgs_rehandshake(mgs_handle_t * ctxt);
367
368
369
370/**
371 * Perform any reinitialization required in PKCS #11
372 */
373int mgs_pkcs11_reinit(server_rec * s);
374
375
376
377/* Configuration Functions */
378
379/* Loads all files set in the configuration */
380int mgs_load_files(apr_pool_t *pconf, apr_pool_t *ptemp, server_rec *s)
381    __attribute__((nonnull));
382
383const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
384                                        const char *arg);
385const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
386                                        const char *arg);
387const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
388                                        const char *arg);
389const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
390                                        const char *arg);
391
392const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
393                             const char *arg);
394
395const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
396
397const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
398                                  const char *arg);
399
400const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
401                                         const char *arg);
402
403const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
404                                   const char *arg);
405
406const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
407                               const char *arg);
408
409const char *mgs_set_pin(cmd_parms * parms, void *dummy,
410                                   const char *arg);
411
412const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
413                                   const char *arg);
414
415const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
416                            const int arg);
417const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
418                            const char *arg);
419const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
420                            const char *arg);
421const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
422                            const int arg);
423
424void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
425void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
426
427void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
428
429void *mgs_config_dir_create(apr_pool_t *p, char *dir);
430
431mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
432
433const char *mgs_store_cred_path(cmd_parms * parms,
434                                void *dummy __attribute__((unused)),
435                                const char *arg);
436
437/* mod_gnutls Hooks. */
438
439int mgs_hook_pre_config(apr_pool_t * pconf,
440                        apr_pool_t * plog, apr_pool_t * ptemp);
441
442int mgs_hook_post_config(apr_pool_t *pconf,
443                         apr_pool_t *plog,
444                         apr_pool_t *ptemp,
445                         server_rec *base_server);
446
447void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
448
449const char *mgs_hook_http_scheme(const request_rec * r);
450
451apr_port_t mgs_hook_default_port(const request_rec * r);
452
453int mgs_hook_pre_connection(conn_rec * c, void *csd);
454
455int mgs_hook_process_connection(conn_rec* c);
456
457int mgs_hook_fixups(request_rec *r);
458
459int mgs_hook_authz(request_rec *r);
460
461#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.