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

asynciodebian/masterdebian/stretch-backportsproxy-ticketupstream
Last change on this file since d6834e0 was d6834e0, checked in by Thomas Klute <thomas2.klute@…>, 5 years ago

OCSP refresh mutex: Prevent parallel requests

Add a global mutex which a thread must hold before updating a cached
OCSP response. This avoids two threads updating the same response in
parallel. The impact of parallel updates may be small with the
experimental file-based mechanism, but an extra OCSP request over HTTP
would add a lot of overhead.

Note that the new 'gnutls-ocsp' mutex is a global mutex, not one per
virtual host, because a mutex must be registered in pre_config for the
Mutex directive to work.

  • Property mode set to 100644
File size: 14.3 KB
RevLine 
[fcb122d]1/**
2 *  Copyright 2004-2005 Paul Querna
[e021722]3 *  Copyright 2014 Nikos Mavrogiannopoulos
[8913410]4 *  Copyright 2015-2016 Thomas 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 */
19
[3b4c0d0]20/* Apache Runtime Headers */
[7e2b223]21#include "httpd.h"
22#include "http_config.h"
23#include "http_protocol.h"
24#include "http_connection.h"
[76bd3bf]25#include "http_request.h"
[7e2b223]26#include "http_core.h"
27#include "http_log.h"
28#include "apr_buckets.h"
29#include "apr_strings.h"
30#include "apr_tables.h"
[482f47f]31#include "ap_release.h"
[9ddaa29]32#include "apr_fnmatch.h"
[3b4c0d0]33/* GnuTLS Library Headers */
[31645b2]34#include <gnutls/gnutls.h>
[031acac]35#include <gnutls/abstract.h>
[e5bbda4]36#include <gnutls/openpgp.h>
[31645b2]37#include <gnutls/x509.h>
38
[05d56ce]39#ifndef __mod_gnutls_h_inc
40#define __mod_gnutls_h_inc
41
[6e0bfd6]42#define HAVE_APR_MEMCACHE    @have_apr_memcache@
[a66e147]43
[6d4de37]44extern module AP_MODULE_DECLARE_DATA gnutls_module;
[7e2b223]45
[3b4c0d0]46/* IO Filter names */
[7e2b223]47#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
48#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
[3b4c0d0]49/* GnuTLS Constants */
[7e2b223]50#define GNUTLS_ENABLED_FALSE 0
51#define GNUTLS_ENABLED_TRUE  1
[040387c]52#define GNUTLS_ENABLED_UNSET  2
[3b4c0d0]53/* Current module version */
[032ff02]54#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
55
[3b4c0d0]56/* Module Debug Mode */
[032ff02]57#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
[3b4c0d0]58
59/* mod_gnutls Cache Types */
60typedef enum {
61        /* No Cache */
[c301152]62    mgs_cache_none,
[3b4c0d0]63        /* Use Old Berkley DB */
[c301152]64    mgs_cache_dbm,
[3b4c0d0]65        /* Use Gnu's version of Berkley DB */
[d8c7cf4]66    mgs_cache_gdbm,
[fcb122d]67#if HAVE_APR_MEMCACHE
[3b4c0d0]68        /* Use Memcache */
[040387c]69    mgs_cache_memcache,
[2e12226]70#endif
[040387c]71    mgs_cache_unset
[c301152]72} mgs_cache_e;
[2e12226]73
[e809fb3]74/* Internal cache data, defined in gnutls_cache.h */
75typedef struct mgs_cache* mgs_cache_t;
76
[cf2b905]77typedef enum {
78    mgs_cvm_unset,
79    mgs_cvm_cartel,
80    mgs_cvm_msva
81} mgs_client_verification_method_e;
82
83
[3b4c0d0]84/* Directory Configuration Record */
85typedef struct {
[e924ddd]86    int client_verify_mode;
[84cb5b2]87    const char* lua_bytecode;
88    apr_size_t lua_bytecode_len;
[c301152]89} mgs_dirconf_rec;
[31645b2]90
[7bebb42]91
[3b4c0d0]92/* The maximum number of certificates to send in a chain */
[5e81262]93#define MAX_CHAIN_SIZE 8
[3b4c0d0]94/* The maximum number of SANs to read from a x509 certificate */
95#define MAX_CERT_SAN 5
[7bebb42]96
[3b4c0d0]97/* Server Configuration Record */
98typedef struct {
[031acac]99    /* --- Configuration values --- */
100        /* Is the module enabled? */
101    int enabled;
102        /* Is mod_proxy enabled? */
103    int proxy_enabled;
104        /* A Plain HTTP request */
105    int non_ssl_request;
106
[9ca1f21]107    /* List of PKCS #11 provider modules to load, only valid in the
[87f1ed2]108     * base config, ignored in virtual hosts */
[9ca1f21]109    apr_array_header_t *p11_modules;
[87f1ed2]110
[031acac]111    /* PIN used for PKCS #11 operations */
112    char *pin;
113
114    /* the SRK PIN used in TPM operations */
115    char *srk_pin;
116
117    char *x509_cert_file;
118    char *x509_key_file;
119    char *x509_ca_file;
120
121    char *pgp_cert_file;
122    char *pgp_key_file;
123    char *pgp_ring_file;
124
125    char *dh_file;
[7314438]126
[031acac]127    char *priorities_str;
[4133f2d]128    char *proxy_priorities_str;
[031acac]129
130    const char* srp_tpasswd_file;
131    const char* srp_tpasswd_conf_file;
132
133        /* Cache timeout value */
134    int cache_timeout;
135        /* Chose Cache Type */
136    mgs_cache_e cache_type;
137    const char* cache_config;
[e809fb3]138    /* Internal cache data */
139    mgs_cache_t cache;
[031acac]140
141        /* GnuTLS uses Session Tickets */
142    int tickets;
143
144    /* --- Things initialized at _child_init --- */
145
[0de1839]146    /* x509 Certificate Structure */
[671b64f]147    gnutls_certificate_credentials_t certs;
[0de1839]148    /* x509 credentials for proxy connections */
149    gnutls_certificate_credentials_t proxy_x509_creds;
[bd24203]150    /* trust list for proxy_x509_creds */
151    gnutls_x509_trust_list_t proxy_x509_tl;
[0de1839]152    const char* proxy_x509_key_file;
153    const char* proxy_x509_cert_file;
154    const char* proxy_x509_ca_file;
[809c422]155    const char* proxy_x509_crl_file;
[f030883]156    /* GnuTLS priorities for proxy connections */
157    gnutls_priority_t proxy_priorities;
[0de1839]158    /* SRP Certificate Structure*/
[7bebb42]159    gnutls_srp_server_credentials_t srp_creds;
[beb14d9]160    /* Anonymous Certificate Structure */
[7bebb42]161    gnutls_anon_server_credentials_t anon_creds;
[beb14d9]162    /* Anonymous Client Certificate Structure, used for proxy
163     * connections */
164    gnutls_anon_client_credentials_t anon_client_creds;
[3b4c0d0]165        /* Current x509 Certificate CN [Common Name] */
[e924ddd]166    char* cert_cn;
[3b4c0d0]167        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
[031acac]168    char* cert_san[MAX_CERT_SAN];
169        /* An x509 Certificate Chain */
170    gnutls_pcert_st *certs_x509_chain;
171    gnutls_x509_crt_t *certs_x509_crt_chain;
172        /* Number of Certificates in Chain */
173    unsigned int certs_x509_chain_num;
174
[3b4c0d0]175        /* Current x509 Certificate Private Key */
[031acac]176    gnutls_privkey_t privkey_x509;
177
[3b4c0d0]178        /* OpenPGP Certificate */
[031acac]179    gnutls_pcert_st *cert_pgp;
180    gnutls_openpgp_crt_t *cert_crt_pgp;
181
[3b4c0d0]182        /* OpenPGP Certificate Private Key */
[031acac]183    gnutls_privkey_t privkey_pgp;
[d04f7da]184#if GNUTLS_VERSION_NUMBER < 0x030312
185    /* Internal structure for the OpenPGP private key, used in the
186     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
187     * frees memory that is still needed. DO NOT USE for any other
188     * purpose. */
[2cde8111]189    gnutls_openpgp_privkey_t privkey_pgp_internal;
[d04f7da]190#endif
[031acac]191
[7d1ab49]192    /* Export full certificates to CGI environment: */
[2aaf4f5]193    int export_certificates_size;
[3b4c0d0]194        /* GnuTLS Priorities */
[7bebb42]195    gnutls_priority_t priorities;
[3b4c0d0]196        /* GnuTLS DH Parameters */
[a3c97d1]197    gnutls_dh_params_t dh_params;
[3b4c0d0]198        /* A list of CA Certificates */
[8663ace]199    gnutls_x509_crt_t *ca_list;
[3b4c0d0]200        /* OpenPGP Key Ring */
[e5bbda4]201    gnutls_openpgp_keyring_t pgp_list;
[3b4c0d0]202        /* CA Certificate list size */
[7bebb42]203    unsigned int ca_list_size;
[3b4c0d0]204        /* Client Certificate Verification Mode */
[e924ddd]205    int client_verify_mode;
[cf2b905]206        /* Client Certificate Verification Method */
207    mgs_client_verification_method_e client_verify_method;
[3b4c0d0]208        /* Last Cache timestamp */
[f10ab4f]209    apr_time_t last_cache_check;
[94cb972]210
211    /* EXPERIMENTAL: OCSP response file for stapling, will go away
212     * once sending OCSP requests is implemented */
213    char *ocsp_response_file;
[fd6bb19]214    /* OCSP URI extracted from the server certificate. NULL if
215     * unset. */
216    apr_uri_t *ocsp_uri;
[d6834e0]217    /* Mutex to prevent parallel OCSP requests */
218    apr_global_mutex_t *ocsp_mutex;
[fad7695]219    /* Trust list to verify OCSP responses for stapling. Should
220     * usually only contain the CA that signed the server
221     * certificate. */
222    gnutls_x509_trust_list_t *ocsp_trust;
[70a1e5a]223    /* Cached OCSP responses expire this long before their validity
224     * period expires. This way mod_gnutls does not staple barely
225     * valid responses. */
226    apr_time_t ocsp_grace_time;
[c301152]227} mgs_srvconf_rec;
[7e2b223]228
[3b4c0d0]229/* Character Buffer */
[dae0aec]230typedef struct {
231    int length;
232    char *value;
[c301152]233} mgs_char_buffer_t;
[dae0aec]234
[3b4c0d0]235/* GnuTLS Handle */
236typedef struct {
237        /* Server configuration record */
[c301152]238    mgs_srvconf_rec *sc;
[3b4c0d0]239        /* Connection record */
[dae0aec]240    conn_rec* c;
[e8acf05]241        /* Is TLS enabled for this connection? */
242    int enabled;
[c1ef069]243    /* Is this a proxy connection? */
244    int is_proxy;
[3b4c0d0]245        /* GnuTLS Session handle */
[7e2b223]246    gnutls_session_t session;
[3b4c0d0]247        /* module input status */
[dae0aec]248    apr_status_t input_rc;
[3b4c0d0]249        /* Input filter */
[7e2b223]250    ap_filter_t *input_filter;
[3b4c0d0]251        /* Input Bucket Brigade */
[7e2b223]252    apr_bucket_brigade *input_bb;
[3b4c0d0]253        /* Input Read Type */
[7e2b223]254    apr_read_type_e input_block;
[3b4c0d0]255        /* Input Mode */
[dae0aec]256    ap_input_mode_t input_mode;
[3b4c0d0]257        /* Input Character Buffer */
[c301152]258    mgs_char_buffer_t input_cbuf;
[3b4c0d0]259        /* Input Character Array */
[dae0aec]260    char input_buffer[AP_IOBUFSIZE];
[3b4c0d0]261        /* module Output status */
[dae0aec]262    apr_status_t output_rc;
[3b4c0d0]263        /* Output filter */
[dae0aec]264    ap_filter_t *output_filter;
[3b4c0d0]265        /* Output Bucket Brigade */
[dae0aec]266    apr_bucket_brigade *output_bb;
[3b4c0d0]267        /* Output character array */
[dae0aec]268    char output_buffer[AP_IOBUFSIZE];
[3b4c0d0]269        /* Output buffer length */
[dae0aec]270    apr_size_t output_blen;
[3b4c0d0]271        /* Output length */
[dae0aec]272    apr_size_t output_length;
[3b4c0d0]273        /* General Status */
[7e2b223]274    int status;
[c301152]275} mgs_handle_t;
[7e2b223]276
[3b4c0d0]277
278
[7e2b223]279/** Functions in gnutls_io.c **/
280
[fb26be5]281/* apr_signal_block() for blocking SIGPIPE */
282apr_status_t apr_signal_block(int signum);
283
[33826c5]284 /* Proxy Support */
[37f8282]285/* An optional function which returns non-zero if the given connection
286is using SSL/TLS. */
287APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
288/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
289 * are used by mod_proxy to enable use of SSL for outgoing
290 * connections. */
291APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
292APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
293int ssl_is_https(conn_rec *c);
[33826c5]294int ssl_proxy_enable(conn_rec *c);
295int ssl_engine_disable(conn_rec *c);
[37f8282]296const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
[176047e]297                                 const int arg);
[37f8282]298apr_status_t mgs_cleanup_pre_config(void *data);
[33826c5]299
[7e2b223]300/**
[c301152]301 * mgs_filter_input will filter the input data
[7e2b223]302 * by decrypting it using GnuTLS and passes it cleartext.
303 *
304 * @param f     the filter info record
305 * @param bb    the bucket brigade, where to store the result to
306 * @param mode  what shall we read?
307 * @param block a block index we shall read from?
308 * @return result status
309 */
[c301152]310apr_status_t mgs_filter_input(ap_filter_t * f,
[2e12226]311                                     apr_bucket_brigade * bb,
312                                     ap_input_mode_t mode,
313                                     apr_read_type_e block,
314                                     apr_off_t readbytes);
[7e2b223]315
316/**
[c301152]317 * mgs_filter_output will filter the encrypt
[7e2b223]318 * the incoming bucket using GnuTLS and passes it onto the next filter.
319 *
320 * @param f     the filter info record
321 * @param bb    the bucket brigade, where to store the result to
322 * @return result status
323 */
[c301152]324apr_status_t mgs_filter_output(ap_filter_t * f,
[2e12226]325                                      apr_bucket_brigade * bb);
[7e2b223]326
327
328/**
[671b64f]329 * mgs_transport_read is called from GnuTLS to provide encrypted
[7e2b223]330 * data from the client.
331 *
332 * @param ptr     pointer to the filter context
333 * @param buffer  place to put data
334 * @param len     maximum size
335 * @return size   length of the data stored in buffer
336 */
[c301152]337ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
[2e12226]338                                  void *buffer, size_t len);
[7e2b223]339
340/**
[671b64f]341 * mgs_transport_write is called from GnuTLS to
[7e2b223]342 * write data to the client.
343 *
344 * @param ptr     pointer to the filter context
345 * @param buffer  buffer to write to the client
346 * @param len     size of the buffer
347 * @return size   length of the data written
348 */
[c301152]349ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
[2e12226]350                                   const void *buffer, size_t len);
[7e2b223]351
352
[c301152]353int mgs_rehandshake(mgs_handle_t * ctxt);
[e924ddd]354
355
356
[a66e147]357/**
[031acac]358 * Perform any reinitialization required in PKCS #11
359 */
360int mgs_pkcs11_reinit(server_rec * s);
361
[7bebb42]362
[c301152]363
[46b85d8]364/* Configuration Functions */
365
[031acac]366/* Loads all files set in the configuration */
367int mgs_load_files(apr_pool_t * p, server_rec * s);
368
[7bebb42]369const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
370                                        const char *arg);
371const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
372                                        const char *arg);
373const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
374                                        const char *arg);
[46b85d8]375const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
376                                        const char *arg);
377
378const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
379                             const char *arg);
380
[e5bbda4]381const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
382                                        const char *arg);
383
384const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
385                             const char *arg);
386
[46b85d8]387const char *mgs_set_cache(cmd_parms * parms, void *dummy,
388                          const char *type, const char* arg);
389
[70a1e5a]390const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
[46b85d8]391
392const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
393                                  const char *arg);
394
[cf2b905]395const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
396                                         const char *arg);
397
[46b85d8]398const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
399                                   const char *arg);
[87f1ed2]400
401const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
402                               const char *arg);
403
[031acac]404const char *mgs_set_pin(cmd_parms * parms, void *dummy,
405                                   const char *arg);
406
407const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
408                                   const char *arg);
[46b85d8]409
[e5bbda4]410const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
411                                   const char *arg);
412
[46b85d8]413const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
[176047e]414                            const int arg);
[2aaf4f5]415const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
[7bebb42]416                            const char *arg);
417const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
418                            const char *arg);
[ae233c2]419const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
[176047e]420                            const int arg);
[671b64f]421
422const char *mgs_set_require_section(cmd_parms *cmd,
[84cb5b2]423                                    void *mconfig, const char *arg);
[46b85d8]424void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
[040387c]425void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
[46b85d8]426
[84cb5b2]427void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
428
[46b85d8]429void *mgs_config_dir_create(apr_pool_t *p, char *dir);
430
[671b64f]431const char *mgs_set_require_bytecode(cmd_parms *cmd,
[84cb5b2]432                                    void *mconfig, const char *arg);
433
[836417f]434mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
[c301152]435
[0de1839]436const char *mgs_store_cred_path(cmd_parms * parms,
437                                void *dummy __attribute__((unused)),
438                                const char *arg);
439
[c301152]440/* mod_gnutls Hooks. */
441
442int mgs_hook_pre_config(apr_pool_t * pconf,
443                        apr_pool_t * plog, apr_pool_t * ptemp);
444
[64856fd]445int mgs_hook_post_config(apr_pool_t *pconf,
446                         apr_pool_t *plog,
447                         apr_pool_t *ptemp,
448                         server_rec *base_server);
[c301152]449
450void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
451
452const char *mgs_hook_http_scheme(const request_rec * r);
453
454apr_port_t mgs_hook_default_port(const request_rec * r);
455
456int mgs_hook_pre_connection(conn_rec * c, void *csd);
457
458int mgs_hook_fixups(request_rec *r);
459
460int mgs_hook_authz(request_rec *r);
461
[7e2b223]462#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.