source: mod_gnutls/include/mod_gnutls.h.in @ 5c62a6a

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

mod_gnutls.h.in: Remove outdated comment

  • Property mode set to 100644
File size: 15.0 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/openpgp.h>
36#include <gnutls/x509.h>
37
38#ifndef __mod_gnutls_h_inc
39#define __mod_gnutls_h_inc
40
41#define HAVE_APR_MEMCACHE    @have_apr_memcache@
42
43extern module AP_MODULE_DECLARE_DATA gnutls_module;
44
45/* IO Filter names */
46#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
47#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
48/* GnuTLS Constants */
49#define GNUTLS_ENABLED_FALSE 0
50#define GNUTLS_ENABLED_TRUE  1
51#define GNUTLS_ENABLED_UNSET  2
52/* Current module version */
53#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
54
55/* Module Debug Mode */
56#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
57
58/* mod_gnutls Cache Types */
59typedef enum {
60        /* No Cache */
61    mgs_cache_none,
62        /* Use Old Berkley DB */
63    mgs_cache_dbm,
64        /* Use Gnu's version of Berkley DB */
65    mgs_cache_gdbm,
66#if HAVE_APR_MEMCACHE
67        /* Use Memcache */
68    mgs_cache_memcache,
69#endif
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 *pgp_cert_file;
123    char *pgp_key_file;
124    char *pgp_ring_file;
125
126    char *dh_file;
127
128    char *priorities_str;
129    char *proxy_priorities_str;
130
131    const char* srp_tpasswd_file;
132    const char* srp_tpasswd_conf_file;
133
134        /* Cache timeout value */
135    int cache_timeout;
136        /* Chose Cache Type */
137    mgs_cache_e cache_type;
138    const char* cache_config;
139    /* Internal cache data */
140    mgs_cache_t cache;
141
142        /* GnuTLS uses Session Tickets */
143    int tickets;
144
145    /* x509 Certificate Structure */
146    gnutls_certificate_credentials_t certs;
147    /* x509 credentials for proxy connections */
148    gnutls_certificate_credentials_t proxy_x509_creds;
149    /* trust list for proxy_x509_creds */
150    gnutls_x509_trust_list_t proxy_x509_tl;
151    const char* proxy_x509_key_file;
152    const char* proxy_x509_cert_file;
153    const char* proxy_x509_ca_file;
154    const char* proxy_x509_crl_file;
155    /* GnuTLS priorities for proxy connections */
156    gnutls_priority_t proxy_priorities;
157    /* SRP Certificate Structure*/
158    gnutls_srp_server_credentials_t srp_creds;
159    /* Anonymous Certificate Structure */
160    gnutls_anon_server_credentials_t anon_creds;
161    /* Anonymous Client Certificate Structure, used for proxy
162     * connections */
163    gnutls_anon_client_credentials_t anon_client_creds;
164        /* Current x509 Certificate CN [Common Name] */
165    char* cert_cn;
166        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
167    char* cert_san[MAX_CERT_SAN];
168        /* An x509 Certificate Chain */
169    gnutls_pcert_st *certs_x509_chain;
170    gnutls_x509_crt_t *certs_x509_crt_chain;
171        /* Number of Certificates in Chain */
172    unsigned int certs_x509_chain_num;
173
174        /* Current x509 Certificate Private Key */
175    gnutls_privkey_t privkey_x509;
176
177        /* OpenPGP Certificate */
178    gnutls_pcert_st *cert_pgp;
179    gnutls_openpgp_crt_t *cert_crt_pgp;
180
181        /* OpenPGP Certificate Private Key */
182    gnutls_privkey_t privkey_pgp;
183#if GNUTLS_VERSION_NUMBER < 0x030312
184    /* Internal structure for the OpenPGP private key, used in the
185     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
186     * frees memory that is still needed. DO NOT USE for any other
187     * purpose. */
188    gnutls_openpgp_privkey_t privkey_pgp_internal;
189#endif
190
191    /* Export full certificates to CGI environment: */
192    int export_certificates_size;
193        /* GnuTLS Priorities */
194    gnutls_priority_t priorities;
195        /* GnuTLS DH Parameters */
196    gnutls_dh_params_t dh_params;
197        /* A list of CA Certificates */
198    gnutls_x509_crt_t *ca_list;
199        /* OpenPGP Key Ring */
200    gnutls_openpgp_keyring_t pgp_list;
201        /* CA Certificate list size */
202    unsigned int ca_list_size;
203        /* Client Certificate Verification Mode */
204    int client_verify_mode;
205        /* Client Certificate Verification Method */
206    mgs_client_verification_method_e client_verify_method;
207        /* Last Cache timestamp */
208    apr_time_t last_cache_check;
209
210    /* Enable OCSP stapling */
211    unsigned char ocsp_staple;
212    /* Check nonce in OCSP responses? */
213    unsigned char ocsp_check_nonce;
214    /* Read OCSP response for stapling from this file instead of
215     * sending a request over HTTP */
216    char *ocsp_response_file;
217    /* Internal OCSP data for this server */
218    mgs_ocsp_data_t ocsp;
219    /* Mutex to prevent parallel OCSP requests */
220    apr_global_mutex_t *ocsp_mutex;
221    /* Cache timeout for OCSP responses. Note that the nextUpdate
222     * field of the response takes precedence if shorter. */
223    apr_interval_time_t ocsp_cache_time;
224    /* If an OCSP request fails wait this long before trying again. */
225    apr_interval_time_t ocsp_failure_timeout;
226    /* Socket timeout for OCSP requests */
227    apr_interval_time_t ocsp_socket_timeout;
228} mgs_srvconf_rec;
229
230/* Character Buffer */
231typedef struct {
232    int length;
233    char *value;
234} mgs_char_buffer_t;
235
236/* GnuTLS Handle */
237typedef struct {
238        /* Server configuration record */
239    mgs_srvconf_rec *sc;
240        /* Connection record */
241    conn_rec* c;
242        /* Is TLS enabled for this connection? */
243    int enabled;
244    /* Is this a proxy connection? */
245    int is_proxy;
246        /* GnuTLS Session handle */
247    gnutls_session_t session;
248        /* module input status */
249    apr_status_t input_rc;
250        /* Input filter */
251    ap_filter_t *input_filter;
252        /* Input Bucket Brigade */
253    apr_bucket_brigade *input_bb;
254        /* Input Read Type */
255    apr_read_type_e input_block;
256        /* Input Mode */
257    ap_input_mode_t input_mode;
258        /* Input Character Buffer */
259    mgs_char_buffer_t input_cbuf;
260        /* Input Character Array */
261    char input_buffer[AP_IOBUFSIZE];
262        /* module Output status */
263    apr_status_t output_rc;
264        /* Output filter */
265    ap_filter_t *output_filter;
266        /* Output Bucket Brigade */
267    apr_bucket_brigade *output_bb;
268        /* Output character array */
269    char output_buffer[AP_IOBUFSIZE];
270        /* Output buffer length */
271    apr_size_t output_blen;
272        /* Output length */
273    apr_size_t output_length;
274        /* General Status */
275    int status;
276} mgs_handle_t;
277
278
279
280/** Functions in gnutls_io.c **/
281
282/* apr_signal_block() for blocking SIGPIPE */
283apr_status_t apr_signal_block(int signum);
284
285/* Proxy Support */
286/** mod_proxy adds a note with this key to the connection->notes table
287 * for client connections */
288#define PROXY_SNI_NOTE "proxy-request-hostname"
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_var_lookup() optional function retrieves SSL environment
293 * variables. */
294APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
295                        (apr_pool_t *, server_rec *,
296                         conn_rec *, request_rec *,
297                         char *));
298/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
299 * are used by mod_proxy to enable use of SSL for outgoing
300 * connections. */
301APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
302APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
303APR_DECLARE_OPTIONAL_FN(int, ssl_engine_set, (conn_rec *,
304                                              ap_conf_vector_t *,
305                                              int proxy, int enable));
306mgs_handle_t* get_effective_gnutls_ctxt(conn_rec *c);
307int ssl_is_https(conn_rec *c);
308char* ssl_var_lookup(apr_pool_t *p, server_rec *s, conn_rec *c,
309                     request_rec *r, char *var);
310int ssl_proxy_enable(conn_rec *c);
311int ssl_engine_disable(conn_rec *c);
312const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
313                                 const int arg);
314apr_status_t mgs_cleanup_pre_config(void *data);
315
316/**
317 * mgs_filter_input will filter the input data
318 * by decrypting it using GnuTLS and passes it cleartext.
319 *
320 * @param f     the filter info record
321 * @param bb    the bucket brigade, where to store the result to
322 * @param mode  what shall we read?
323 * @param block a block index we shall read from?
324 * @return result status
325 */
326apr_status_t mgs_filter_input(ap_filter_t * f,
327                                     apr_bucket_brigade * bb,
328                                     ap_input_mode_t mode,
329                                     apr_read_type_e block,
330                                     apr_off_t readbytes);
331
332/**
333 * mgs_filter_output will filter the encrypt
334 * the incoming bucket using GnuTLS and passes it onto the next filter.
335 *
336 * @param f     the filter info record
337 * @param bb    the bucket brigade, where to store the result to
338 * @return result status
339 */
340apr_status_t mgs_filter_output(ap_filter_t * f,
341                                      apr_bucket_brigade * bb);
342
343
344/**
345 * mgs_transport_read is called from GnuTLS to provide encrypted
346 * data from the client.
347 *
348 * @param ptr     pointer to the filter context
349 * @param buffer  place to put data
350 * @param len     maximum size
351 * @return size   length of the data stored in buffer
352 */
353ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
354                                  void *buffer, size_t len);
355
356/**
357 * mgs_transport_write is called from GnuTLS to
358 * write data to the client.
359 *
360 * @param ptr     pointer to the filter context
361 * @param buffer  buffer to write to the client
362 * @param len     size of the buffer
363 * @return size   length of the data written
364 */
365ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
366                                   const void *buffer, size_t len);
367
368
369int mgs_rehandshake(mgs_handle_t * ctxt);
370
371
372
373/**
374 * Perform any reinitialization required in PKCS #11
375 */
376int mgs_pkcs11_reinit(server_rec * s);
377
378
379
380/* Configuration Functions */
381
382/* Loads all files set in the configuration */
383int mgs_load_files(apr_pool_t *pconf, apr_pool_t *ptemp, server_rec *s)
384    __attribute__((nonnull));
385
386const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
387                                        const char *arg);
388const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
389                                        const char *arg);
390const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
391                                        const char *arg);
392const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
393                                        const char *arg);
394
395const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
396                             const char *arg);
397
398const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
399                                        const char *arg);
400
401const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
402                             const char *arg);
403
404const char *mgs_set_cache(cmd_parms * parms, void *dummy,
405                          const char *type, const char* arg);
406
407const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
408
409const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
410                                  const char *arg);
411
412const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
413                                         const char *arg);
414
415const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
416                                   const char *arg);
417
418const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
419                               const char *arg);
420
421const char *mgs_set_pin(cmd_parms * parms, void *dummy,
422                                   const char *arg);
423
424const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
425                                   const char *arg);
426
427const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
428                                   const char *arg);
429
430const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
431                            const int arg);
432const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
433                            const char *arg);
434const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
435                            const char *arg);
436const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
437                            const int arg);
438
439void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
440void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
441
442void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
443
444void *mgs_config_dir_create(apr_pool_t *p, char *dir);
445
446mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
447
448const char *mgs_store_cred_path(cmd_parms * parms,
449                                void *dummy __attribute__((unused)),
450                                const char *arg);
451
452/* mod_gnutls Hooks. */
453
454int mgs_hook_pre_config(apr_pool_t * pconf,
455                        apr_pool_t * plog, apr_pool_t * ptemp);
456
457int mgs_hook_post_config(apr_pool_t *pconf,
458                         apr_pool_t *plog,
459                         apr_pool_t *ptemp,
460                         server_rec *base_server);
461
462void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
463
464const char *mgs_hook_http_scheme(const request_rec * r);
465
466apr_port_t mgs_hook_default_port(const request_rec * r);
467
468int mgs_hook_pre_connection(conn_rec * c, void *csd);
469
470int mgs_hook_process_connection(conn_rec* c);
471
472int mgs_hook_fixups(request_rec *r);
473
474int mgs_hook_authz(request_rec *r);
475
476#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.