source: mod_gnutls/include/mod_gnutls.h.in @ 6bbd378

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

Remove special handling for APR memcache and leftover includes

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