source: mod_gnutls/include/mod_gnutls.h.in @ 7921dc7

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

Remove OpenPGP authentication

OpenPGP authentication was removed from GnuTLS a while ago, follow suit.

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