source: mod_gnutls/include/mod_gnutls.h.in @ 2246a84

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

Make automatic OCSP cache updates and fuzz time configurable

  • Property mode set to 100644
File size: 15.7 KB
RevLine 
[104e881]1/*
[fcb122d]2 *  Copyright 2004-2005 Paul Querna
[e021722]3 *  Copyright 2014 Nikos Mavrogiannopoulos
[3c123cd]4 *  Copyright 2015-2018 Fiona Klute
[7e2b223]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
[3b4c0d0]19/* Apache Runtime Headers */
[7e2b223]20#include "httpd.h"
21#include "http_config.h"
22#include "http_protocol.h"
23#include "http_connection.h"
[76bd3bf]24#include "http_request.h"
[7e2b223]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"
[482f47f]30#include "ap_release.h"
[9ddaa29]31#include "apr_fnmatch.h"
[3b4c0d0]32/* GnuTLS Library Headers */
[31645b2]33#include <gnutls/gnutls.h>
[031acac]34#include <gnutls/abstract.h>
[e5bbda4]35#include <gnutls/openpgp.h>
[31645b2]36#include <gnutls/x509.h>
37
[05d56ce]38#ifndef __mod_gnutls_h_inc
39#define __mod_gnutls_h_inc
40
[6e0bfd6]41#define HAVE_APR_MEMCACHE    @have_apr_memcache@
[a66e147]42
[6d4de37]43extern module AP_MODULE_DECLARE_DATA gnutls_module;
[7e2b223]44
[3b4c0d0]45/* IO Filter names */
[7e2b223]46#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
47#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
[3b4c0d0]48/* GnuTLS Constants */
[7e2b223]49#define GNUTLS_ENABLED_FALSE 0
50#define GNUTLS_ENABLED_TRUE  1
[040387c]51#define GNUTLS_ENABLED_UNSET  2
[3b4c0d0]52/* Current module version */
[032ff02]53#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
54
[3b4c0d0]55/* Module Debug Mode */
[032ff02]56#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
[3b4c0d0]57
[0e3f8c6]58/** Name of the module-wide singleton watchdog */
59#define MGS_SINGLETON_WATCHDOG "_mod_gnutls_singleton_"
60
61
[3b4c0d0]62/* mod_gnutls Cache Types */
63typedef enum {
64        /* No Cache */
[c301152]65    mgs_cache_none,
[3b4c0d0]66        /* Use Old Berkley DB */
[c301152]67    mgs_cache_dbm,
[3b4c0d0]68        /* Use Gnu's version of Berkley DB */
[d8c7cf4]69    mgs_cache_gdbm,
[fcb122d]70#if HAVE_APR_MEMCACHE
[3b4c0d0]71        /* Use Memcache */
[040387c]72    mgs_cache_memcache,
[2e12226]73#endif
[040387c]74    mgs_cache_unset
[c301152]75} mgs_cache_e;
[2e12226]76
[e809fb3]77/* Internal cache data, defined in gnutls_cache.h */
78typedef struct mgs_cache* mgs_cache_t;
79
[cf2b905]80typedef enum {
81    mgs_cvm_unset,
82    mgs_cvm_cartel,
83    mgs_cvm_msva
84} mgs_client_verification_method_e;
85
86
[3b4c0d0]87/* Directory Configuration Record */
88typedef struct {
[e924ddd]89    int client_verify_mode;
[c301152]90} mgs_dirconf_rec;
[31645b2]91
[7bebb42]92
[cc74801e]93/* Internal per-vhost config for OCSP, defined in gnutls_ocsp.h */
94typedef struct mgs_ocsp_data* mgs_ocsp_data_t;
95
96
[3b4c0d0]97/* The maximum number of certificates to send in a chain */
[5e81262]98#define MAX_CHAIN_SIZE 8
[3b4c0d0]99/* The maximum number of SANs to read from a x509 certificate */
100#define MAX_CERT_SAN 5
[7bebb42]101
[0e3f8c6]102/** Server Configuration Record */
[3b4c0d0]103typedef struct {
[031acac]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
[9ca1f21]112    /* List of PKCS #11 provider modules to load, only valid in the
[87f1ed2]113     * base config, ignored in virtual hosts */
[9ca1f21]114    apr_array_header_t *p11_modules;
[87f1ed2]115
[031acac]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;
[7314438]131
[031acac]132    char *priorities_str;
[4133f2d]133    char *proxy_priorities_str;
[031acac]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;
[e809fb3]143    /* Internal cache data */
144    mgs_cache_t cache;
[031acac]145
146        /* GnuTLS uses Session Tickets */
147    int tickets;
148
[0de1839]149    /* x509 Certificate Structure */
[671b64f]150    gnutls_certificate_credentials_t certs;
[0de1839]151    /* x509 credentials for proxy connections */
152    gnutls_certificate_credentials_t proxy_x509_creds;
[bd24203]153    /* trust list for proxy_x509_creds */
154    gnutls_x509_trust_list_t proxy_x509_tl;
[0de1839]155    const char* proxy_x509_key_file;
156    const char* proxy_x509_cert_file;
157    const char* proxy_x509_ca_file;
[809c422]158    const char* proxy_x509_crl_file;
[f030883]159    /* GnuTLS priorities for proxy connections */
160    gnutls_priority_t proxy_priorities;
[0de1839]161    /* SRP Certificate Structure*/
[7bebb42]162    gnutls_srp_server_credentials_t srp_creds;
[beb14d9]163    /* Anonymous Certificate Structure */
[7bebb42]164    gnutls_anon_server_credentials_t anon_creds;
[beb14d9]165    /* Anonymous Client Certificate Structure, used for proxy
166     * connections */
167    gnutls_anon_client_credentials_t anon_client_creds;
[3b4c0d0]168        /* Current x509 Certificate CN [Common Name] */
[e924ddd]169    char* cert_cn;
[3b4c0d0]170        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
[031acac]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
[3b4c0d0]178        /* Current x509 Certificate Private Key */
[031acac]179    gnutls_privkey_t privkey_x509;
180
[3b4c0d0]181        /* OpenPGP Certificate */
[031acac]182    gnutls_pcert_st *cert_pgp;
183    gnutls_openpgp_crt_t *cert_crt_pgp;
184
[3b4c0d0]185        /* OpenPGP Certificate Private Key */
[031acac]186    gnutls_privkey_t privkey_pgp;
[d04f7da]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. */
[2cde8111]192    gnutls_openpgp_privkey_t privkey_pgp_internal;
[d04f7da]193#endif
[031acac]194
[7d1ab49]195    /* Export full certificates to CGI environment: */
[2aaf4f5]196    int export_certificates_size;
[3b4c0d0]197        /* GnuTLS Priorities */
[7bebb42]198    gnutls_priority_t priorities;
[3b4c0d0]199        /* GnuTLS DH Parameters */
[a3c97d1]200    gnutls_dh_params_t dh_params;
[3b4c0d0]201        /* A list of CA Certificates */
[8663ace]202    gnutls_x509_crt_t *ca_list;
[3b4c0d0]203        /* OpenPGP Key Ring */
[e5bbda4]204    gnutls_openpgp_keyring_t pgp_list;
[3b4c0d0]205        /* CA Certificate list size */
[7bebb42]206    unsigned int ca_list_size;
[3b4c0d0]207        /* Client Certificate Verification Mode */
[e924ddd]208    int client_verify_mode;
[cf2b905]209        /* Client Certificate Verification Method */
210    mgs_client_verification_method_e client_verify_method;
[3b4c0d0]211        /* Last Cache timestamp */
[f10ab4f]212    apr_time_t last_cache_check;
[94cb972]213
[3475e62]214    /* Enable OCSP stapling */
[4d4a406]215    unsigned char ocsp_staple;
[2246a84]216    /* Automatically refresh cached OCSP response? */
217    unsigned char ocsp_auto_refresh;
[b888e8b]218    /* Check nonce in OCSP responses? */
219    unsigned char ocsp_check_nonce;
[3475e62]220    /* Read OCSP response for stapling from this file instead of
221     * sending a request over HTTP */
[94cb972]222    char *ocsp_response_file;
[c6dda6d]223    /* Internal OCSP data for this server */
[cc74801e]224    mgs_ocsp_data_t ocsp;
[d6834e0]225    /* Mutex to prevent parallel OCSP requests */
226    apr_global_mutex_t *ocsp_mutex;
[e1c094c]227    /* Cache timeout for OCSP responses. Note that the nextUpdate
228     * field of the response takes precedence if shorter. */
229    apr_interval_time_t ocsp_cache_time;
[c6dda6d]230    /* If an OCSP request fails wait this long before trying again. */
[0a02378]231    apr_interval_time_t ocsp_failure_timeout;
[2246a84]232    /** How long before a cached OCSP response expires should it be
233     * updated? During configuration parsing this is set to the
234     * maximum, during post configuration the value will be set to
235     * half that. After each update the interval to for the next one
236     * is choosen randomly as `ocsp_fuzz_time + ocsp_fuzz_time *
237     * RANDOM` with `0 <= RANDOM <= 1`. */
238    apr_interval_time_t ocsp_fuzz_time;
[333bbc7]239    /* Socket timeout for OCSP requests */
240    apr_interval_time_t ocsp_socket_timeout;
[0e3f8c6]241
242    /** This module's singleton watchdog, used for async OCSP cache
243     * updates. */
244    struct mgs_watchdog *singleton_wd;
[c301152]245} mgs_srvconf_rec;
[7e2b223]246
[3b4c0d0]247/* Character Buffer */
[dae0aec]248typedef struct {
249    int length;
250    char *value;
[c301152]251} mgs_char_buffer_t;
[dae0aec]252
[3b4c0d0]253/* GnuTLS Handle */
254typedef struct {
255        /* Server configuration record */
[c301152]256    mgs_srvconf_rec *sc;
[3b4c0d0]257        /* Connection record */
[dae0aec]258    conn_rec* c;
[e8acf05]259        /* Is TLS enabled for this connection? */
260    int enabled;
[c1ef069]261    /* Is this a proxy connection? */
262    int is_proxy;
[3b4c0d0]263        /* GnuTLS Session handle */
[7e2b223]264    gnutls_session_t session;
[3b4c0d0]265        /* module input status */
[dae0aec]266    apr_status_t input_rc;
[3b4c0d0]267        /* Input filter */
[7e2b223]268    ap_filter_t *input_filter;
[3b4c0d0]269        /* Input Bucket Brigade */
[7e2b223]270    apr_bucket_brigade *input_bb;
[3b4c0d0]271        /* Input Read Type */
[7e2b223]272    apr_read_type_e input_block;
[3b4c0d0]273        /* Input Mode */
[dae0aec]274    ap_input_mode_t input_mode;
[3b4c0d0]275        /* Input Character Buffer */
[c301152]276    mgs_char_buffer_t input_cbuf;
[3b4c0d0]277        /* Input Character Array */
[dae0aec]278    char input_buffer[AP_IOBUFSIZE];
[3b4c0d0]279        /* module Output status */
[dae0aec]280    apr_status_t output_rc;
[3b4c0d0]281        /* Output filter */
[dae0aec]282    ap_filter_t *output_filter;
[3b4c0d0]283        /* Output Bucket Brigade */
[dae0aec]284    apr_bucket_brigade *output_bb;
[3b4c0d0]285        /* Output character array */
[dae0aec]286    char output_buffer[AP_IOBUFSIZE];
[3b4c0d0]287        /* Output buffer length */
[dae0aec]288    apr_size_t output_blen;
[3b4c0d0]289        /* Output length */
[dae0aec]290    apr_size_t output_length;
[3b4c0d0]291        /* General Status */
[7e2b223]292    int status;
[c301152]293} mgs_handle_t;
[7e2b223]294
[3b4c0d0]295
296
[7e2b223]297/** Functions in gnutls_io.c **/
298
[fb26be5]299/* apr_signal_block() for blocking SIGPIPE */
300apr_status_t apr_signal_block(int signum);
301
[265159d]302/* Proxy Support */
303/** mod_proxy adds a note with this key to the connection->notes table
304 * for client connections */
305#define PROXY_SNI_NOTE "proxy-request-hostname"
[37f8282]306/* An optional function which returns non-zero if the given connection
307is using SSL/TLS. */
308APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
[4cdd4fd]309/* The ssl_var_lookup() optional function retrieves SSL environment
310 * variables. */
311APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
312                        (apr_pool_t *, server_rec *,
313                         conn_rec *, request_rec *,
314                         char *));
[37f8282]315/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
316 * are used by mod_proxy to enable use of SSL for outgoing
317 * connections. */
318APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
319APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
[23e98b3]320APR_DECLARE_OPTIONAL_FN(int, ssl_engine_set, (conn_rec *,
321                                              ap_conf_vector_t *,
322                                              int proxy, int enable));
[4cdd4fd]323mgs_handle_t* get_effective_gnutls_ctxt(conn_rec *c);
[37f8282]324int ssl_is_https(conn_rec *c);
[4cdd4fd]325char* ssl_var_lookup(apr_pool_t *p, server_rec *s, conn_rec *c,
326                     request_rec *r, char *var);
[33826c5]327int ssl_proxy_enable(conn_rec *c);
328int ssl_engine_disable(conn_rec *c);
[37f8282]329const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
[176047e]330                                 const int arg);
[37f8282]331apr_status_t mgs_cleanup_pre_config(void *data);
[33826c5]332
[7e2b223]333/**
[c301152]334 * mgs_filter_input will filter the input data
[7e2b223]335 * by decrypting it using GnuTLS and passes it cleartext.
336 *
337 * @param f     the filter info record
338 * @param bb    the bucket brigade, where to store the result to
339 * @param mode  what shall we read?
340 * @param block a block index we shall read from?
341 * @return result status
342 */
[c301152]343apr_status_t mgs_filter_input(ap_filter_t * f,
[2e12226]344                                     apr_bucket_brigade * bb,
345                                     ap_input_mode_t mode,
346                                     apr_read_type_e block,
347                                     apr_off_t readbytes);
[7e2b223]348
349/**
[c301152]350 * mgs_filter_output will filter the encrypt
[7e2b223]351 * the incoming bucket using GnuTLS and passes it onto the next filter.
352 *
353 * @param f     the filter info record
354 * @param bb    the bucket brigade, where to store the result to
355 * @return result status
356 */
[c301152]357apr_status_t mgs_filter_output(ap_filter_t * f,
[2e12226]358                                      apr_bucket_brigade * bb);
[7e2b223]359
360
361/**
[671b64f]362 * mgs_transport_read is called from GnuTLS to provide encrypted
[7e2b223]363 * data from the client.
364 *
365 * @param ptr     pointer to the filter context
366 * @param buffer  place to put data
367 * @param len     maximum size
368 * @return size   length of the data stored in buffer
369 */
[c301152]370ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
[2e12226]371                                  void *buffer, size_t len);
[7e2b223]372
373/**
[671b64f]374 * mgs_transport_write is called from GnuTLS to
[7e2b223]375 * write data to the client.
376 *
377 * @param ptr     pointer to the filter context
378 * @param buffer  buffer to write to the client
379 * @param len     size of the buffer
380 * @return size   length of the data written
381 */
[c301152]382ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
[2e12226]383                                   const void *buffer, size_t len);
[7e2b223]384
385
[c301152]386int mgs_rehandshake(mgs_handle_t * ctxt);
[e924ddd]387
388
389
[a66e147]390/**
[031acac]391 * Perform any reinitialization required in PKCS #11
392 */
393int mgs_pkcs11_reinit(server_rec * s);
394
[7bebb42]395
[c301152]396
[46b85d8]397/* Configuration Functions */
398
[031acac]399/* Loads all files set in the configuration */
[eee1432]400int mgs_load_files(apr_pool_t *pconf, apr_pool_t *ptemp, server_rec *s)
401    __attribute__((nonnull));
[031acac]402
[7bebb42]403const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
404                                        const char *arg);
405const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
406                                        const char *arg);
407const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
408                                        const char *arg);
[46b85d8]409const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
410                                        const char *arg);
411
412const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
413                             const char *arg);
414
[e5bbda4]415const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
416                                        const char *arg);
417
418const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
419                             const char *arg);
420
[46b85d8]421const char *mgs_set_cache(cmd_parms * parms, void *dummy,
422                          const char *type, const char* arg);
423
[70a1e5a]424const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
[46b85d8]425
426const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
427                                  const char *arg);
428
[cf2b905]429const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
430                                         const char *arg);
431
[46b85d8]432const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
433                                   const char *arg);
[87f1ed2]434
435const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
436                               const char *arg);
437
[031acac]438const char *mgs_set_pin(cmd_parms * parms, void *dummy,
439                                   const char *arg);
440
441const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
442                                   const char *arg);
[46b85d8]443
[e5bbda4]444const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
445                                   const char *arg);
446
[46b85d8]447const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
[176047e]448                            const int arg);
[2aaf4f5]449const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
[7bebb42]450                            const char *arg);
451const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
452                            const char *arg);
[ae233c2]453const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
[176047e]454                            const int arg);
[671b64f]455
[46b85d8]456void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
[040387c]457void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
[46b85d8]458
[84cb5b2]459void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
460
[46b85d8]461void *mgs_config_dir_create(apr_pool_t *p, char *dir);
462
[836417f]463mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
[c301152]464
[0de1839]465const char *mgs_store_cred_path(cmd_parms * parms,
466                                void *dummy __attribute__((unused)),
467                                const char *arg);
468
[c301152]469/* mod_gnutls Hooks. */
470
471int mgs_hook_pre_config(apr_pool_t * pconf,
472                        apr_pool_t * plog, apr_pool_t * ptemp);
473
[64856fd]474int mgs_hook_post_config(apr_pool_t *pconf,
475                         apr_pool_t *plog,
476                         apr_pool_t *ptemp,
477                         server_rec *base_server);
[c301152]478
479void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
480
481const char *mgs_hook_http_scheme(const request_rec * r);
482
483apr_port_t mgs_hook_default_port(const request_rec * r);
484
485int mgs_hook_pre_connection(conn_rec * c, void *csd);
486
[e7cf823]487int mgs_hook_process_connection(conn_rec* c);
488
[c301152]489int mgs_hook_fixups(request_rec *r);
490
491int mgs_hook_authz(request_rec *r);
492
[7e2b223]493#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.