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

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

Simplify wildcard match for virtual host aliases

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