source: mod_gnutls/include/mod_gnutls.h.in

Last change on this file was 265159d, checked in by Thomas Klute <thomas2.klute@…>, 8 weeks ago

Send SNI for proxy connections

  • 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/* 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    /* --- Things initialized at _child_init --- */
146
147    /* x509 Certificate Structure */
148    gnutls_certificate_credentials_t certs;
149    /* x509 credentials for proxy connections */
150    gnutls_certificate_credentials_t proxy_x509_creds;
151    /* trust list for proxy_x509_creds */
152    gnutls_x509_trust_list_t proxy_x509_tl;
153    const char* proxy_x509_key_file;
154    const char* proxy_x509_cert_file;
155    const char* proxy_x509_ca_file;
156    const char* proxy_x509_crl_file;
157    /* GnuTLS priorities for proxy connections */
158    gnutls_priority_t proxy_priorities;
159    /* SRP Certificate Structure*/
160    gnutls_srp_server_credentials_t srp_creds;
161    /* Anonymous Certificate Structure */
162    gnutls_anon_server_credentials_t anon_creds;
163    /* Anonymous Client Certificate Structure, used for proxy
164     * connections */
165    gnutls_anon_client_credentials_t anon_client_creds;
166        /* Current x509 Certificate CN [Common Name] */
167    char* cert_cn;
168        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
169    char* cert_san[MAX_CERT_SAN];
170        /* An x509 Certificate Chain */
171    gnutls_pcert_st *certs_x509_chain;
172    gnutls_x509_crt_t *certs_x509_crt_chain;
173        /* Number of Certificates in Chain */
174    unsigned int certs_x509_chain_num;
175
176        /* Current x509 Certificate Private Key */
177    gnutls_privkey_t privkey_x509;
178
179        /* OpenPGP Certificate */
180    gnutls_pcert_st *cert_pgp;
181    gnutls_openpgp_crt_t *cert_crt_pgp;
182
183        /* OpenPGP Certificate Private Key */
184    gnutls_privkey_t privkey_pgp;
185#if GNUTLS_VERSION_NUMBER < 0x030312
186    /* Internal structure for the OpenPGP private key, used in the
187     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
188     * frees memory that is still needed. DO NOT USE for any other
189     * purpose. */
190    gnutls_openpgp_privkey_t privkey_pgp_internal;
191#endif
192
193    /* Export full certificates to CGI environment: */
194    int export_certificates_size;
195        /* GnuTLS Priorities */
196    gnutls_priority_t priorities;
197        /* GnuTLS DH Parameters */
198    gnutls_dh_params_t dh_params;
199        /* A list of CA Certificates */
200    gnutls_x509_crt_t *ca_list;
201        /* OpenPGP Key Ring */
202    gnutls_openpgp_keyring_t pgp_list;
203        /* CA Certificate list size */
204    unsigned int ca_list_size;
205        /* Client Certificate Verification Mode */
206    int client_verify_mode;
207        /* Client Certificate Verification Method */
208    mgs_client_verification_method_e client_verify_method;
209        /* Last Cache timestamp */
210    apr_time_t last_cache_check;
211
212    /* Enable OCSP stapling */
213    unsigned char ocsp_staple;
214    /* Check nonce in OCSP responses? */
215    unsigned char ocsp_check_nonce;
216    /* Read OCSP response for stapling from this file instead of
217     * sending a request over HTTP */
218    char *ocsp_response_file;
219    /* Internal OCSP data for this server */
220    mgs_ocsp_data_t ocsp;
221    /* Mutex to prevent parallel OCSP requests */
222    apr_global_mutex_t *ocsp_mutex;
223    /* Cache timeout for OCSP responses. Note that the nextUpdate
224     * field of the response takes precedence if shorter. */
225    apr_interval_time_t ocsp_cache_time;
226    /* If an OCSP request fails wait this long before trying again. */
227    apr_interval_time_t ocsp_failure_timeout;
228    /* Socket timeout for OCSP requests */
229    apr_interval_time_t ocsp_socket_timeout;
230} mgs_srvconf_rec;
231
232/* Character Buffer */
233typedef struct {
234    int length;
235    char *value;
236} mgs_char_buffer_t;
237
238/* GnuTLS Handle */
239typedef struct {
240        /* Server configuration record */
241    mgs_srvconf_rec *sc;
242        /* Connection record */
243    conn_rec* c;
244        /* Is TLS enabled for this connection? */
245    int enabled;
246    /* Is this a proxy connection? */
247    int is_proxy;
248        /* GnuTLS Session handle */
249    gnutls_session_t session;
250        /* module input status */
251    apr_status_t input_rc;
252        /* Input filter */
253    ap_filter_t *input_filter;
254        /* Input Bucket Brigade */
255    apr_bucket_brigade *input_bb;
256        /* Input Read Type */
257    apr_read_type_e input_block;
258        /* Input Mode */
259    ap_input_mode_t input_mode;
260        /* Input Character Buffer */
261    mgs_char_buffer_t input_cbuf;
262        /* Input Character Array */
263    char input_buffer[AP_IOBUFSIZE];
264        /* module Output status */
265    apr_status_t output_rc;
266        /* Output filter */
267    ap_filter_t *output_filter;
268        /* Output Bucket Brigade */
269    apr_bucket_brigade *output_bb;
270        /* Output character array */
271    char output_buffer[AP_IOBUFSIZE];
272        /* Output buffer length */
273    apr_size_t output_blen;
274        /* Output length */
275    apr_size_t output_length;
276        /* General Status */
277    int status;
278} mgs_handle_t;
279
280
281
282/** Functions in gnutls_io.c **/
283
284/* apr_signal_block() for blocking SIGPIPE */
285apr_status_t apr_signal_block(int signum);
286
287/* Proxy Support */
288/** mod_proxy adds a note with this key to the connection->notes table
289 * for client connections */
290#define PROXY_SNI_NOTE "proxy-request-hostname"
291/* An optional function which returns non-zero if the given connection
292is using SSL/TLS. */
293APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
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 *));
299int ssl_is_https(conn_rec *c);
300int ssl_proxy_enable(conn_rec *c);
301int ssl_engine_disable(conn_rec *c);
302const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
303                                 const int arg);
304apr_status_t mgs_cleanup_pre_config(void *data);
305
306/**
307 * mgs_filter_input will filter the input data
308 * by decrypting it using GnuTLS and passes it cleartext.
309 *
310 * @param f     the filter info record
311 * @param bb    the bucket brigade, where to store the result to
312 * @param mode  what shall we read?
313 * @param block a block index we shall read from?
314 * @return result status
315 */
316apr_status_t mgs_filter_input(ap_filter_t * f,
317                                     apr_bucket_brigade * bb,
318                                     ap_input_mode_t mode,
319                                     apr_read_type_e block,
320                                     apr_off_t readbytes);
321
322/**
323 * mgs_filter_output will filter the encrypt
324 * the incoming bucket using GnuTLS and passes it onto the next filter.
325 *
326 * @param f     the filter info record
327 * @param bb    the bucket brigade, where to store the result to
328 * @return result status
329 */
330apr_status_t mgs_filter_output(ap_filter_t * f,
331                                      apr_bucket_brigade * bb);
332
333
334/**
335 * mgs_transport_read is called from GnuTLS to provide encrypted
336 * data from the client.
337 *
338 * @param ptr     pointer to the filter context
339 * @param buffer  place to put data
340 * @param len     maximum size
341 * @return size   length of the data stored in buffer
342 */
343ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
344                                  void *buffer, size_t len);
345
346/**
347 * mgs_transport_write is called from GnuTLS to
348 * write data to the client.
349 *
350 * @param ptr     pointer to the filter context
351 * @param buffer  buffer to write to the client
352 * @param len     size of the buffer
353 * @return size   length of the data written
354 */
355ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
356                                   const void *buffer, size_t len);
357
358
359int mgs_rehandshake(mgs_handle_t * ctxt);
360
361
362
363/**
364 * Perform any reinitialization required in PKCS #11
365 */
366int mgs_pkcs11_reinit(server_rec * s);
367
368
369
370/* Configuration Functions */
371
372/* Loads all files set in the configuration */
373int mgs_load_files(apr_pool_t *pconf, apr_pool_t *ptemp, server_rec *s)
374    __attribute__((nonnull));
375
376const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
377                                        const char *arg);
378const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
379                                        const char *arg);
380const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
381                                        const char *arg);
382const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
383                                        const char *arg);
384
385const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
386                             const char *arg);
387
388const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
389                                        const char *arg);
390
391const char *mgs_set_pgpkey_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_keyring_file(cmd_parms * parms, void *dummy,
418                                   const char *arg);
419
420const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
421                            const int arg);
422const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
423                            const char *arg);
424const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
425                            const char *arg);
426const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
427                            const int arg);
428
429void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
430void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
431
432void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
433
434void *mgs_config_dir_create(apr_pool_t *p, char *dir);
435
436mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
437
438const char *mgs_store_cred_path(cmd_parms * parms,
439                                void *dummy __attribute__((unused)),
440                                const char *arg);
441
442/* mod_gnutls Hooks. */
443
444int mgs_hook_pre_config(apr_pool_t * pconf,
445                        apr_pool_t * plog, apr_pool_t * ptemp);
446
447int mgs_hook_post_config(apr_pool_t *pconf,
448                         apr_pool_t *plog,
449                         apr_pool_t *ptemp,
450                         server_rec *base_server);
451
452void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
453
454const char *mgs_hook_http_scheme(const request_rec * r);
455
456apr_port_t mgs_hook_default_port(const request_rec * r);
457
458int mgs_hook_pre_connection(conn_rec * c, void *csd);
459
460int mgs_hook_fixups(request_rec *r);
461
462int mgs_hook_authz(request_rec *r);
463
464#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.