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

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

Remove internal cache type enum

The cache type is now transparently passed to ap_lookup_provider(), so
mod_gnutls does not need to manage available cache types. The new
server variable sc->cache_enable exists to track whether the cache
should be used at all.

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