source: mod_gnutls/include/mod_gnutls.h.in @ 9a18e30

debian/masterdebian/stretch-backportsupstream
Last change on this file since 9a18e30 was e1c094c, checked in by Thomas Klute <thomas2.klute@…>, 3 years ago

Replace GnuTLSOCSPGraceTime with GnuTLSOCSPCacheTimeout

Configuring a timeout instead a time relative to the nextUpdate field
of the OCSP response has two main advantages:

  • The maximum cache lifetime is independent of any external data. The OCSP response is signed and the CA generally a trusted entity, but its policy is almost always outside the server admin's control and might change.
  • The principle is a lot simpler and thus less likely to lead to implementation or configuration errors.

Additionally a static timeout policy should make it easier to
implement asynchronous cache updates for MPMs that support it.

  • Property mode set to 100644
File size: 14.4 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;
[c301152]87} mgs_dirconf_rec;
[31645b2]88
[7bebb42]89
[cc74801e]90/* Internal per-vhost config for OCSP, defined in gnutls_ocsp.h */
91typedef struct mgs_ocsp_data* mgs_ocsp_data_t;
92
93
[3b4c0d0]94/* The maximum number of certificates to send in a chain */
[5e81262]95#define MAX_CHAIN_SIZE 8
[3b4c0d0]96/* The maximum number of SANs to read from a x509 certificate */
97#define MAX_CERT_SAN 5
[7bebb42]98
[3b4c0d0]99/* Server Configuration Record */
100typedef struct {
[031acac]101    /* --- Configuration values --- */
102        /* Is the module enabled? */
103    int enabled;
104        /* Is mod_proxy enabled? */
105    int proxy_enabled;
106        /* A Plain HTTP request */
107    int non_ssl_request;
108
[9ca1f21]109    /* List of PKCS #11 provider modules to load, only valid in the
[87f1ed2]110     * base config, ignored in virtual hosts */
[9ca1f21]111    apr_array_header_t *p11_modules;
[87f1ed2]112
[031acac]113    /* PIN used for PKCS #11 operations */
114    char *pin;
115
116    /* the SRK PIN used in TPM operations */
117    char *srk_pin;
118
119    char *x509_cert_file;
120    char *x509_key_file;
121    char *x509_ca_file;
122
123    char *pgp_cert_file;
124    char *pgp_key_file;
125    char *pgp_ring_file;
126
127    char *dh_file;
[7314438]128
[031acac]129    char *priorities_str;
[4133f2d]130    char *proxy_priorities_str;
[031acac]131
132    const char* srp_tpasswd_file;
133    const char* srp_tpasswd_conf_file;
134
135        /* Cache timeout value */
136    int cache_timeout;
137        /* Chose Cache Type */
138    mgs_cache_e cache_type;
139    const char* cache_config;
[e809fb3]140    /* Internal cache data */
141    mgs_cache_t cache;
[031acac]142
143        /* GnuTLS uses Session Tickets */
144    int tickets;
145
146    /* --- Things initialized at _child_init --- */
147
[0de1839]148    /* x509 Certificate Structure */
[671b64f]149    gnutls_certificate_credentials_t certs;
[0de1839]150    /* x509 credentials for proxy connections */
151    gnutls_certificate_credentials_t proxy_x509_creds;
[bd24203]152    /* trust list for proxy_x509_creds */
153    gnutls_x509_trust_list_t proxy_x509_tl;
[0de1839]154    const char* proxy_x509_key_file;
155    const char* proxy_x509_cert_file;
156    const char* proxy_x509_ca_file;
[809c422]157    const char* proxy_x509_crl_file;
[f030883]158    /* GnuTLS priorities for proxy connections */
159    gnutls_priority_t proxy_priorities;
[0de1839]160    /* SRP Certificate Structure*/
[7bebb42]161    gnutls_srp_server_credentials_t srp_creds;
[beb14d9]162    /* Anonymous Certificate Structure */
[7bebb42]163    gnutls_anon_server_credentials_t anon_creds;
[beb14d9]164    /* Anonymous Client Certificate Structure, used for proxy
165     * connections */
166    gnutls_anon_client_credentials_t anon_client_creds;
[3b4c0d0]167        /* Current x509 Certificate CN [Common Name] */
[e924ddd]168    char* cert_cn;
[3b4c0d0]169        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
[031acac]170    char* cert_san[MAX_CERT_SAN];
171        /* An x509 Certificate Chain */
172    gnutls_pcert_st *certs_x509_chain;
173    gnutls_x509_crt_t *certs_x509_crt_chain;
174        /* Number of Certificates in Chain */
175    unsigned int certs_x509_chain_num;
176
[3b4c0d0]177        /* Current x509 Certificate Private Key */
[031acac]178    gnutls_privkey_t privkey_x509;
179
[3b4c0d0]180        /* OpenPGP Certificate */
[031acac]181    gnutls_pcert_st *cert_pgp;
182    gnutls_openpgp_crt_t *cert_crt_pgp;
183
[3b4c0d0]184        /* OpenPGP Certificate Private Key */
[031acac]185    gnutls_privkey_t privkey_pgp;
[d04f7da]186#if GNUTLS_VERSION_NUMBER < 0x030312
187    /* Internal structure for the OpenPGP private key, used in the
188     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
189     * frees memory that is still needed. DO NOT USE for any other
190     * purpose. */
[2cde8111]191    gnutls_openpgp_privkey_t privkey_pgp_internal;
[d04f7da]192#endif
[031acac]193
[7d1ab49]194    /* Export full certificates to CGI environment: */
[2aaf4f5]195    int export_certificates_size;
[3b4c0d0]196        /* GnuTLS Priorities */
[7bebb42]197    gnutls_priority_t priorities;
[3b4c0d0]198        /* GnuTLS DH Parameters */
[a3c97d1]199    gnutls_dh_params_t dh_params;
[3b4c0d0]200        /* A list of CA Certificates */
[8663ace]201    gnutls_x509_crt_t *ca_list;
[3b4c0d0]202        /* OpenPGP Key Ring */
[e5bbda4]203    gnutls_openpgp_keyring_t pgp_list;
[3b4c0d0]204        /* CA Certificate list size */
[7bebb42]205    unsigned int ca_list_size;
[3b4c0d0]206        /* Client Certificate Verification Mode */
[e924ddd]207    int client_verify_mode;
[cf2b905]208        /* Client Certificate Verification Method */
209    mgs_client_verification_method_e client_verify_method;
[3b4c0d0]210        /* Last Cache timestamp */
[f10ab4f]211    apr_time_t last_cache_check;
[94cb972]212
[3475e62]213    /* Enable OCSP stapling */
[4d4a406]214    unsigned char ocsp_staple;
[b888e8b]215    /* Check nonce in OCSP responses? */
216    unsigned char ocsp_check_nonce;
[3475e62]217    /* Read OCSP response for stapling from this file instead of
218     * sending a request over HTTP */
[94cb972]219    char *ocsp_response_file;
[c6dda6d]220    /* Internal OCSP data for this server */
[cc74801e]221    mgs_ocsp_data_t ocsp;
[d6834e0]222    /* Mutex to prevent parallel OCSP requests */
223    apr_global_mutex_t *ocsp_mutex;
[e1c094c]224    /* Cache timeout for OCSP responses. Note that the nextUpdate
225     * field of the response takes precedence if shorter. */
226    apr_interval_time_t ocsp_cache_time;
[c6dda6d]227    /* If an OCSP request fails wait this long before trying again. */
[0a02378]228    apr_interval_time_t ocsp_failure_timeout;
[333bbc7]229    /* Socket timeout for OCSP requests */
230    apr_interval_time_t ocsp_socket_timeout;
[c301152]231} mgs_srvconf_rec;
[7e2b223]232
[3b4c0d0]233/* Character Buffer */
[dae0aec]234typedef struct {
235    int length;
236    char *value;
[c301152]237} mgs_char_buffer_t;
[dae0aec]238
[3b4c0d0]239/* GnuTLS Handle */
240typedef struct {
241        /* Server configuration record */
[c301152]242    mgs_srvconf_rec *sc;
[3b4c0d0]243        /* Connection record */
[dae0aec]244    conn_rec* c;
[e8acf05]245        /* Is TLS enabled for this connection? */
246    int enabled;
[c1ef069]247    /* Is this a proxy connection? */
248    int is_proxy;
[3b4c0d0]249        /* GnuTLS Session handle */
[7e2b223]250    gnutls_session_t session;
[3b4c0d0]251        /* module input status */
[dae0aec]252    apr_status_t input_rc;
[3b4c0d0]253        /* Input filter */
[7e2b223]254    ap_filter_t *input_filter;
[3b4c0d0]255        /* Input Bucket Brigade */
[7e2b223]256    apr_bucket_brigade *input_bb;
[3b4c0d0]257        /* Input Read Type */
[7e2b223]258    apr_read_type_e input_block;
[3b4c0d0]259        /* Input Mode */
[dae0aec]260    ap_input_mode_t input_mode;
[3b4c0d0]261        /* Input Character Buffer */
[c301152]262    mgs_char_buffer_t input_cbuf;
[3b4c0d0]263        /* Input Character Array */
[dae0aec]264    char input_buffer[AP_IOBUFSIZE];
[3b4c0d0]265        /* module Output status */
[dae0aec]266    apr_status_t output_rc;
[3b4c0d0]267        /* Output filter */
[dae0aec]268    ap_filter_t *output_filter;
[3b4c0d0]269        /* Output Bucket Brigade */
[dae0aec]270    apr_bucket_brigade *output_bb;
[3b4c0d0]271        /* Output character array */
[dae0aec]272    char output_buffer[AP_IOBUFSIZE];
[3b4c0d0]273        /* Output buffer length */
[dae0aec]274    apr_size_t output_blen;
[3b4c0d0]275        /* Output length */
[dae0aec]276    apr_size_t output_length;
[3b4c0d0]277        /* General Status */
[7e2b223]278    int status;
[c301152]279} mgs_handle_t;
[7e2b223]280
[3b4c0d0]281
282
[7e2b223]283/** Functions in gnutls_io.c **/
284
[fb26be5]285/* apr_signal_block() for blocking SIGPIPE */
286apr_status_t apr_signal_block(int signum);
287
[33826c5]288 /* Proxy Support */
[37f8282]289/* An optional function which returns non-zero if the given connection
290is using SSL/TLS. */
291APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
292/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
293 * are used by mod_proxy to enable use of SSL for outgoing
294 * connections. */
295APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
296APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
297int ssl_is_https(conn_rec *c);
[33826c5]298int ssl_proxy_enable(conn_rec *c);
299int ssl_engine_disable(conn_rec *c);
[37f8282]300const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
[176047e]301                                 const int arg);
[37f8282]302apr_status_t mgs_cleanup_pre_config(void *data);
[33826c5]303
[7e2b223]304/**
[c301152]305 * mgs_filter_input will filter the input data
[7e2b223]306 * by decrypting it using GnuTLS and passes it cleartext.
307 *
308 * @param f     the filter info record
309 * @param bb    the bucket brigade, where to store the result to
310 * @param mode  what shall we read?
311 * @param block a block index we shall read from?
312 * @return result status
313 */
[c301152]314apr_status_t mgs_filter_input(ap_filter_t * f,
[2e12226]315                                     apr_bucket_brigade * bb,
316                                     ap_input_mode_t mode,
317                                     apr_read_type_e block,
318                                     apr_off_t readbytes);
[7e2b223]319
320/**
[c301152]321 * mgs_filter_output will filter the encrypt
[7e2b223]322 * the incoming bucket using GnuTLS and passes it onto the next filter.
323 *
324 * @param f     the filter info record
325 * @param bb    the bucket brigade, where to store the result to
326 * @return result status
327 */
[c301152]328apr_status_t mgs_filter_output(ap_filter_t * f,
[2e12226]329                                      apr_bucket_brigade * bb);
[7e2b223]330
331
332/**
[671b64f]333 * mgs_transport_read is called from GnuTLS to provide encrypted
[7e2b223]334 * data from the client.
335 *
336 * @param ptr     pointer to the filter context
337 * @param buffer  place to put data
338 * @param len     maximum size
339 * @return size   length of the data stored in buffer
340 */
[c301152]341ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
[2e12226]342                                  void *buffer, size_t len);
[7e2b223]343
344/**
[671b64f]345 * mgs_transport_write is called from GnuTLS to
[7e2b223]346 * write data to the client.
347 *
348 * @param ptr     pointer to the filter context
349 * @param buffer  buffer to write to the client
350 * @param len     size of the buffer
351 * @return size   length of the data written
352 */
[c301152]353ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
[2e12226]354                                   const void *buffer, size_t len);
[7e2b223]355
356
[c301152]357int mgs_rehandshake(mgs_handle_t * ctxt);
[e924ddd]358
359
360
[a66e147]361/**
[031acac]362 * Perform any reinitialization required in PKCS #11
363 */
364int mgs_pkcs11_reinit(server_rec * s);
365
[7bebb42]366
[c301152]367
[46b85d8]368/* Configuration Functions */
369
[031acac]370/* Loads all files set in the configuration */
[eee1432]371int mgs_load_files(apr_pool_t *pconf, apr_pool_t *ptemp, server_rec *s)
372    __attribute__((nonnull));
[031acac]373
[7bebb42]374const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
375                                        const char *arg);
376const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
377                                        const char *arg);
378const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
379                                        const char *arg);
[46b85d8]380const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
381                                        const char *arg);
382
383const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
384                             const char *arg);
385
[e5bbda4]386const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
387                                        const char *arg);
388
389const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
390                             const char *arg);
391
[46b85d8]392const char *mgs_set_cache(cmd_parms * parms, void *dummy,
393                          const char *type, const char* arg);
394
[70a1e5a]395const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
[46b85d8]396
397const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
398                                  const char *arg);
399
[cf2b905]400const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
401                                         const char *arg);
402
[46b85d8]403const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
404                                   const char *arg);
[87f1ed2]405
406const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
407                               const char *arg);
408
[031acac]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);
[46b85d8]414
[e5bbda4]415const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
416                                   const char *arg);
417
[46b85d8]418const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
[176047e]419                            const int arg);
[2aaf4f5]420const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
[7bebb42]421                            const char *arg);
422const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
423                            const char *arg);
[ae233c2]424const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
[176047e]425                            const int arg);
[671b64f]426
427const char *mgs_set_require_section(cmd_parms *cmd,
[84cb5b2]428                                    void *mconfig, const char *arg);
[46b85d8]429void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
[040387c]430void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
[46b85d8]431
[84cb5b2]432void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
433
[46b85d8]434void *mgs_config_dir_create(apr_pool_t *p, char *dir);
435
[671b64f]436const char *mgs_set_require_bytecode(cmd_parms *cmd,
[84cb5b2]437                                    void *mconfig, const char *arg);
438
[836417f]439mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
[c301152]440
[0de1839]441const char *mgs_store_cred_path(cmd_parms * parms,
442                                void *dummy __attribute__((unused)),
443                                const char *arg);
444
[c301152]445/* mod_gnutls Hooks. */
446
447int mgs_hook_pre_config(apr_pool_t * pconf,
448                        apr_pool_t * plog, apr_pool_t * ptemp);
449
[64856fd]450int mgs_hook_post_config(apr_pool_t *pconf,
451                         apr_pool_t *plog,
452                         apr_pool_t *ptemp,
453                         server_rec *base_server);
[c301152]454
455void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
456
457const char *mgs_hook_http_scheme(const request_rec * r);
458
459apr_port_t mgs_hook_default_port(const request_rec * r);
460
461int mgs_hook_pre_connection(conn_rec * c, void *csd);
462
463int mgs_hook_fixups(request_rec *r);
464
465int mgs_hook_authz(request_rec *r);
466
[7e2b223]467#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.