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

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

Use generic cache functions for OCSP response caching

With this, OCSP stapling works with all supported cache types.

  • Property mode set to 100644
File size: 14.3 KB
Line 
1/**
2 *  Copyright 2004-2005 Paul Querna
3 *  Copyright 2014 Nikos Mavrogiannopoulos
4 *  Copyright 2015-2016 Thomas 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
20/* Apache Runtime Headers */
21#include "httpd.h"
22#include "http_config.h"
23#include "http_protocol.h"
24#include "http_connection.h"
25#include "http_request.h"
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"
31#include "ap_release.h"
32#include "apr_fnmatch.h"
33/* GnuTLS Library Headers */
34#include <gnutls/gnutls.h>
35#include <gnutls/abstract.h>
36#include <gnutls/openpgp.h>
37#include <gnutls/x509.h>
38
39#ifndef __mod_gnutls_h_inc
40#define __mod_gnutls_h_inc
41
42#define HAVE_APR_MEMCACHE    @have_apr_memcache@
43
44extern module AP_MODULE_DECLARE_DATA gnutls_module;
45
46/* IO Filter names */
47#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
48#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
49/* GnuTLS Constants */
50#define GNUTLS_ENABLED_FALSE 0
51#define GNUTLS_ENABLED_TRUE  1
52#define GNUTLS_ENABLED_UNSET  2
53/* Current module version */
54#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
55
56/* Module Debug Mode */
57#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
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#if HAVE_APR_MEMCACHE
68        /* Use Memcache */
69    mgs_cache_memcache,
70#endif
71    mgs_cache_unset
72} mgs_cache_e;
73
74/* Internal cache data, defined in gnutls_cache.h */
75typedef struct mgs_cache* mgs_cache_t;
76
77typedef enum {
78    mgs_cvm_unset,
79    mgs_cvm_cartel,
80    mgs_cvm_msva
81} mgs_client_verification_method_e;
82
83
84/* Directory Configuration Record */
85typedef struct {
86    int client_verify_mode;
87    const char* lua_bytecode;
88    apr_size_t lua_bytecode_len;
89} mgs_dirconf_rec;
90
91
92/* The maximum number of certificates to send in a chain */
93#define MAX_CHAIN_SIZE 8
94/* The maximum number of SANs to read from a x509 certificate */
95#define MAX_CERT_SAN 5
96
97/* Server Configuration Record */
98typedef struct {
99    /* --- Configuration values --- */
100        /* Is the module enabled? */
101    int enabled;
102        /* Is mod_proxy enabled? */
103    int proxy_enabled;
104        /* A Plain HTTP request */
105    int non_ssl_request;
106
107    /* List of PKCS #11 provider modules to load, only valid in the
108     * base config, ignored in virtual hosts */
109    apr_array_header_t *p11_modules;
110
111    /* PIN used for PKCS #11 operations */
112    char *pin;
113
114    /* the SRK PIN used in TPM operations */
115    char *srk_pin;
116
117    char *x509_cert_file;
118    char *x509_key_file;
119    char *x509_ca_file;
120
121    char *pgp_cert_file;
122    char *pgp_key_file;
123    char *pgp_ring_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    /* Mutex for cache access (used only if the cache type is not
139     * thread-safe) */
140    apr_global_mutex_t *cache_mutex;
141    /* Internal cache data */
142    mgs_cache_t cache;
143
144        /* GnuTLS uses Session Tickets */
145    int tickets;
146
147    /* --- Things initialized at _child_init --- */
148
149    /* x509 Certificate Structure */
150    gnutls_certificate_credentials_t certs;
151    /* x509 credentials for proxy connections */
152    gnutls_certificate_credentials_t proxy_x509_creds;
153    /* trust list for proxy_x509_creds */
154    gnutls_x509_trust_list_t proxy_x509_tl;
155    const char* proxy_x509_key_file;
156    const char* proxy_x509_cert_file;
157    const char* proxy_x509_ca_file;
158    const char* proxy_x509_crl_file;
159    /* GnuTLS priorities for proxy connections */
160    gnutls_priority_t proxy_priorities;
161    /* SRP Certificate Structure*/
162    gnutls_srp_server_credentials_t srp_creds;
163    /* Anonymous Certificate Structure */
164    gnutls_anon_server_credentials_t anon_creds;
165    /* Anonymous Client Certificate Structure, used for proxy
166     * connections */
167    gnutls_anon_client_credentials_t anon_client_creds;
168        /* Current x509 Certificate CN [Common Name] */
169    char* cert_cn;
170        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
171    char* cert_san[MAX_CERT_SAN];
172        /* An x509 Certificate Chain */
173    gnutls_pcert_st *certs_x509_chain;
174    gnutls_x509_crt_t *certs_x509_crt_chain;
175        /* Number of Certificates in Chain */
176    unsigned int certs_x509_chain_num;
177
178        /* Current x509 Certificate Private Key */
179    gnutls_privkey_t privkey_x509;
180
181        /* OpenPGP Certificate */
182    gnutls_pcert_st *cert_pgp;
183    gnutls_openpgp_crt_t *cert_crt_pgp;
184
185        /* OpenPGP Certificate Private Key */
186    gnutls_privkey_t privkey_pgp;
187#if GNUTLS_VERSION_NUMBER < 0x030312
188    /* Internal structure for the OpenPGP private key, used in the
189     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
190     * frees memory that is still needed. DO NOT USE for any other
191     * purpose. */
192    gnutls_openpgp_privkey_t privkey_pgp_internal;
193#endif
194
195    /* Export full certificates to CGI environment: */
196    int export_certificates_size;
197        /* GnuTLS Priorities */
198    gnutls_priority_t priorities;
199        /* GnuTLS DH Parameters */
200    gnutls_dh_params_t dh_params;
201        /* A list of CA Certificates */
202    gnutls_x509_crt_t *ca_list;
203        /* OpenPGP Key Ring */
204    gnutls_openpgp_keyring_t pgp_list;
205        /* CA Certificate list size */
206    unsigned int ca_list_size;
207        /* Client Certificate Verification Mode */
208    int client_verify_mode;
209        /* Client Certificate Verification Method */
210    mgs_client_verification_method_e client_verify_method;
211        /* Last Cache timestamp */
212    apr_time_t last_cache_check;
213
214    /* EXPERIMENTAL: OCSP response file for stapling, will go away
215     * once sending OCSP requests is implemented */
216    char *ocsp_response_file;
217    /* OCSP URI extracted from the server certificate. NULL if
218     * unset. */
219    apr_uri_t *ocsp_uri;
220    /* Trust list to verify OCSP responses for stapling. Should
221     * usually only contain the CA that signed the server
222     * certificate. */
223    gnutls_x509_trust_list_t *ocsp_trust;
224    /* Cached OCSP responses expire this long before their validity
225     * period expires. This way mod_gnutls does not staple barely
226     * valid responses. */
227    apr_time_t ocsp_grace_time;
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/* An optional function which returns non-zero if the given connection
287is using SSL/TLS. */
288APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
289/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
290 * are used by mod_proxy to enable use of SSL for outgoing
291 * connections. */
292APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
293APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
294int ssl_is_https(conn_rec *c);
295int ssl_proxy_enable(conn_rec *c);
296int ssl_engine_disable(conn_rec *c);
297const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
298                                 const int arg);
299apr_status_t mgs_cleanup_pre_config(void *data);
300
301/**
302 * mgs_filter_input will filter the input data
303 * by decrypting it using GnuTLS and passes it cleartext.
304 *
305 * @param f     the filter info record
306 * @param bb    the bucket brigade, where to store the result to
307 * @param mode  what shall we read?
308 * @param block a block index we shall read from?
309 * @return result status
310 */
311apr_status_t mgs_filter_input(ap_filter_t * f,
312                                     apr_bucket_brigade * bb,
313                                     ap_input_mode_t mode,
314                                     apr_read_type_e block,
315                                     apr_off_t readbytes);
316
317/**
318 * mgs_filter_output will filter the encrypt
319 * the incoming bucket using GnuTLS and passes it onto the next filter.
320 *
321 * @param f     the filter info record
322 * @param bb    the bucket brigade, where to store the result to
323 * @return result status
324 */
325apr_status_t mgs_filter_output(ap_filter_t * f,
326                                      apr_bucket_brigade * bb);
327
328
329/**
330 * mgs_transport_read is called from GnuTLS to provide encrypted
331 * data from the client.
332 *
333 * @param ptr     pointer to the filter context
334 * @param buffer  place to put data
335 * @param len     maximum size
336 * @return size   length of the data stored in buffer
337 */
338ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
339                                  void *buffer, size_t len);
340
341/**
342 * mgs_transport_write is called from GnuTLS to
343 * write data to the client.
344 *
345 * @param ptr     pointer to the filter context
346 * @param buffer  buffer to write to the client
347 * @param len     size of the buffer
348 * @return size   length of the data written
349 */
350ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
351                                   const void *buffer, size_t len);
352
353
354int mgs_rehandshake(mgs_handle_t * ctxt);
355
356
357
358/**
359 * Perform any reinitialization required in PKCS #11
360 */
361int mgs_pkcs11_reinit(server_rec * s);
362
363
364
365/* Configuration Functions */
366
367/* Loads all files set in the configuration */
368int mgs_load_files(apr_pool_t * p, server_rec * s);
369
370const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
371                                        const char *arg);
372const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
373                                        const char *arg);
374const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
375                                        const char *arg);
376const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
377                                        const char *arg);
378
379const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
380                             const char *arg);
381
382const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
383                                        const char *arg);
384
385const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
386                             const char *arg);
387
388const char *mgs_set_cache(cmd_parms * parms, void *dummy,
389                          const char *type, 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_keyring_file(cmd_parms * parms, void *dummy,
412                                   const char *arg);
413
414const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
415                            const int arg);
416const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
417                            const char *arg);
418const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
419                            const char *arg);
420const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
421                            const int arg);
422
423const char *mgs_set_require_section(cmd_parms *cmd,
424                                    void *mconfig, const char *arg);
425void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
426void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
427
428void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
429
430void *mgs_config_dir_create(apr_pool_t *p, char *dir);
431
432const char *mgs_set_require_bytecode(cmd_parms *cmd,
433                                    void *mconfig, const char *arg);
434
435mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
436
437const char *mgs_store_cred_path(cmd_parms * parms,
438                                void *dummy __attribute__((unused)),
439                                const char *arg);
440
441/* mod_gnutls Hooks. */
442
443int mgs_hook_pre_config(apr_pool_t * pconf,
444                        apr_pool_t * plog, apr_pool_t * ptemp);
445
446int mgs_hook_post_config(apr_pool_t *pconf,
447                         apr_pool_t *plog,
448                         apr_pool_t *ptemp,
449                         server_rec *base_server);
450
451void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
452
453const char *mgs_hook_http_scheme(const request_rec * r);
454
455apr_port_t mgs_hook_default_port(const request_rec * r);
456
457int mgs_hook_pre_connection(conn_rec * c, void *csd);
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.