source: mod_gnutls/include/mod_gnutls.h.in @ 70a1e5a

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

Introduce OCSP caching grace time

A cached OCSP response must be updated before it expires, or time skew
might cause a client to receive a response it considers expired. In
some corner cases even network transmission delay might have the same
effect. To prevent this problem let the response cache entry expire a
configurable grace time before the response does, so a fresh response
will be fetched.

  • Property mode set to 100644
File size: 14.2 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
74typedef enum {
75    mgs_cvm_unset,
76    mgs_cvm_cartel,
77    mgs_cvm_msva
78} mgs_client_verification_method_e;
79
80
81/* Directory Configuration Record */
82typedef struct {
83    int client_verify_mode;
84    const char* lua_bytecode;
85    apr_size_t lua_bytecode_len;
86} mgs_dirconf_rec;
87
88
89/* The maximum number of certificates to send in a chain */
90#define MAX_CHAIN_SIZE 8
91/* The maximum number of SANs to read from a x509 certificate */
92#define MAX_CERT_SAN 5
93
94/* Server Configuration Record */
95typedef struct {
96    /* --- Configuration values --- */
97        /* Is the module enabled? */
98    int enabled;
99        /* Is mod_proxy enabled? */
100    int proxy_enabled;
101        /* A Plain HTTP request */
102    int non_ssl_request;
103
104    /* List of PKCS #11 provider modules to load, only valid in the
105     * base config, ignored in virtual hosts */
106    apr_array_header_t *p11_modules;
107
108    /* PIN used for PKCS #11 operations */
109    char *pin;
110
111    /* the SRK PIN used in TPM operations */
112    char *srk_pin;
113
114    char *x509_cert_file;
115    char *x509_key_file;
116    char *x509_ca_file;
117
118    char *pgp_cert_file;
119    char *pgp_key_file;
120    char *pgp_ring_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    /* Mutex for cache access (used only if the cache type is not
136     * thread-safe) */
137    apr_global_mutex_t *cache_mutex;
138
139        /* GnuTLS uses Session Tickets */
140    int tickets;
141
142    /* --- Things initialized at _child_init --- */
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        /* OpenPGP Certificate */
177    gnutls_pcert_st *cert_pgp;
178    gnutls_openpgp_crt_t *cert_crt_pgp;
179
180        /* OpenPGP Certificate Private Key */
181    gnutls_privkey_t privkey_pgp;
182#if GNUTLS_VERSION_NUMBER < 0x030312
183    /* Internal structure for the OpenPGP private key, used in the
184     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
185     * frees memory that is still needed. DO NOT USE for any other
186     * purpose. */
187    gnutls_openpgp_privkey_t privkey_pgp_internal;
188#endif
189
190    /* Export full certificates to CGI environment: */
191    int export_certificates_size;
192        /* GnuTLS Priorities */
193    gnutls_priority_t priorities;
194        /* GnuTLS DH Parameters */
195    gnutls_dh_params_t dh_params;
196        /* A list of CA Certificates */
197    gnutls_x509_crt_t *ca_list;
198        /* OpenPGP Key Ring */
199    gnutls_openpgp_keyring_t pgp_list;
200        /* CA Certificate list size */
201    unsigned int ca_list_size;
202        /* Client Certificate Verification Mode */
203    int client_verify_mode;
204        /* Client Certificate Verification Method */
205    mgs_client_verification_method_e client_verify_method;
206        /* Last Cache timestamp */
207    apr_time_t last_cache_check;
208
209    /* EXPERIMENTAL: OCSP response file for stapling, will go away
210     * once sending OCSP requests is implemented */
211    char *ocsp_response_file;
212    /* OCSP URI extracted from the server certificate. NULL if
213     * unset. */
214    apr_uri_t *ocsp_uri;
215    /* Trust list to verify OCSP responses for stapling. Should
216     * usually only contain the CA that signed the server
217     * certificate. */
218    gnutls_x509_trust_list_t *ocsp_trust;
219    /* Cached OCSP responses expire this long before their validity
220     * period expires. This way mod_gnutls does not staple barely
221     * valid responses. */
222    apr_time_t ocsp_grace_time;
223} mgs_srvconf_rec;
224
225/* Character Buffer */
226typedef struct {
227    int length;
228    char *value;
229} mgs_char_buffer_t;
230
231/* GnuTLS Handle */
232typedef struct {
233        /* Server configuration record */
234    mgs_srvconf_rec *sc;
235        /* Connection record */
236    conn_rec* c;
237        /* Is TLS enabled for this connection? */
238    int enabled;
239    /* Is this a proxy connection? */
240    int is_proxy;
241        /* GnuTLS Session handle */
242    gnutls_session_t session;
243        /* module input status */
244    apr_status_t input_rc;
245        /* Input filter */
246    ap_filter_t *input_filter;
247        /* Input Bucket Brigade */
248    apr_bucket_brigade *input_bb;
249        /* Input Read Type */
250    apr_read_type_e input_block;
251        /* Input Mode */
252    ap_input_mode_t input_mode;
253        /* Input Character Buffer */
254    mgs_char_buffer_t input_cbuf;
255        /* Input Character Array */
256    char input_buffer[AP_IOBUFSIZE];
257        /* module Output status */
258    apr_status_t output_rc;
259        /* Output filter */
260    ap_filter_t *output_filter;
261        /* Output Bucket Brigade */
262    apr_bucket_brigade *output_bb;
263        /* Output character array */
264    char output_buffer[AP_IOBUFSIZE];
265        /* Output buffer length */
266    apr_size_t output_blen;
267        /* Output length */
268    apr_size_t output_length;
269        /* General Status */
270    int status;
271} mgs_handle_t;
272
273
274
275/** Functions in gnutls_io.c **/
276
277/* apr_signal_block() for blocking SIGPIPE */
278apr_status_t apr_signal_block(int signum);
279
280 /* Proxy Support */
281/* An optional function which returns non-zero if the given connection
282is using SSL/TLS. */
283APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
284/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
285 * are used by mod_proxy to enable use of SSL for outgoing
286 * connections. */
287APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
288APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
289int ssl_is_https(conn_rec *c);
290int ssl_proxy_enable(conn_rec *c);
291int ssl_engine_disable(conn_rec *c);
292const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
293                                 const int arg);
294apr_status_t mgs_cleanup_pre_config(void *data);
295
296/**
297 * mgs_filter_input will filter the input data
298 * by decrypting it using GnuTLS and passes it cleartext.
299 *
300 * @param f     the filter info record
301 * @param bb    the bucket brigade, where to store the result to
302 * @param mode  what shall we read?
303 * @param block a block index we shall read from?
304 * @return result status
305 */
306apr_status_t mgs_filter_input(ap_filter_t * f,
307                                     apr_bucket_brigade * bb,
308                                     ap_input_mode_t mode,
309                                     apr_read_type_e block,
310                                     apr_off_t readbytes);
311
312/**
313 * mgs_filter_output will filter the encrypt
314 * the incoming bucket using GnuTLS and passes it onto the next filter.
315 *
316 * @param f     the filter info record
317 * @param bb    the bucket brigade, where to store the result to
318 * @return result status
319 */
320apr_status_t mgs_filter_output(ap_filter_t * f,
321                                      apr_bucket_brigade * bb);
322
323
324/**
325 * mgs_transport_read is called from GnuTLS to provide encrypted
326 * data from the client.
327 *
328 * @param ptr     pointer to the filter context
329 * @param buffer  place to put data
330 * @param len     maximum size
331 * @return size   length of the data stored in buffer
332 */
333ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
334                                  void *buffer, size_t len);
335
336/**
337 * mgs_transport_write is called from GnuTLS to
338 * write data to the client.
339 *
340 * @param ptr     pointer to the filter context
341 * @param buffer  buffer to write to the client
342 * @param len     size of the buffer
343 * @return size   length of the data written
344 */
345ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
346                                   const void *buffer, size_t len);
347
348
349int mgs_rehandshake(mgs_handle_t * ctxt);
350
351
352
353/**
354 * Perform any reinitialization required in PKCS #11
355 */
356int mgs_pkcs11_reinit(server_rec * s);
357
358
359
360/* Configuration Functions */
361
362/* Loads all files set in the configuration */
363int mgs_load_files(apr_pool_t * p, server_rec * s);
364
365const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
366                                        const char *arg);
367const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
368                                        const char *arg);
369const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
370                                        const char *arg);
371const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
372                                        const char *arg);
373
374const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
375                             const char *arg);
376
377const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
378                                        const char *arg);
379
380const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
381                             const char *arg);
382
383const char *mgs_set_cache(cmd_parms * parms, void *dummy,
384                          const char *type, const char* arg);
385
386const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
387
388const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
389                                  const char *arg);
390
391const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
392                                         const char *arg);
393
394const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
395                                   const char *arg);
396
397const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
398                               const char *arg);
399
400const char *mgs_set_pin(cmd_parms * parms, void *dummy,
401                                   const char *arg);
402
403const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
404                                   const char *arg);
405
406const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
407                                   const char *arg);
408
409const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
410                            const int arg);
411const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
412                            const char *arg);
413const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
414                            const char *arg);
415const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
416                            const int arg);
417
418const char *mgs_set_require_section(cmd_parms *cmd,
419                                    void *mconfig, const char *arg);
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
427const char *mgs_set_require_bytecode(cmd_parms *cmd,
428                                    void *mconfig, const char *arg);
429
430mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
431
432const char *mgs_store_cred_path(cmd_parms * parms,
433                                void *dummy __attribute__((unused)),
434                                const char *arg);
435
436/* mod_gnutls Hooks. */
437
438int mgs_hook_pre_config(apr_pool_t * pconf,
439                        apr_pool_t * plog, apr_pool_t * ptemp);
440
441int mgs_hook_post_config(apr_pool_t *pconf,
442                         apr_pool_t *plog,
443                         apr_pool_t *ptemp,
444                         server_rec *base_server);
445
446void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
447
448const char *mgs_hook_http_scheme(const request_rec * r);
449
450apr_port_t mgs_hook_default_port(const request_rec * r);
451
452int mgs_hook_pre_connection(conn_rec * c, void *csd);
453
454int mgs_hook_fixups(request_rec *r);
455
456int mgs_hook_authz(request_rec *r);
457
458#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.