source: mod_gnutls/include/mod_gnutls.h.in @ 7511bfa

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

Update copyright headers

  • 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-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#if GNUTLS_VERSION_MAJOR == 2
36#include <gnutls/extra.h>
37#endif
38#include <gnutls/abstract.h>
39#include <gnutls/openpgp.h>
40#include <gnutls/x509.h>
41
42#ifndef __mod_gnutls_h_inc
43#define __mod_gnutls_h_inc
44
45#define HAVE_APR_MEMCACHE    @have_apr_memcache@
46
47extern module AP_MODULE_DECLARE_DATA gnutls_module;
48
49/* IO Filter names */
50#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
51#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
52/* GnuTLS Constants */
53#define GNUTLS_ENABLED_FALSE 0
54#define GNUTLS_ENABLED_TRUE  1
55#define GNUTLS_ENABLED_UNSET  2
56/* Current module version */
57#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
58
59/* Module Debug Mode */
60#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
61
62/* mod_gnutls Cache Types */
63typedef enum {
64        /* No Cache */
65    mgs_cache_none,
66        /* Use Old Berkley DB */
67    mgs_cache_dbm,
68        /* Use Gnu's version of Berkley DB */
69    mgs_cache_gdbm,
70#if HAVE_APR_MEMCACHE
71        /* Use Memcache */
72    mgs_cache_memcache,
73#endif
74    mgs_cache_unset
75} mgs_cache_e;
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
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} mgs_srvconf_rec;
220
221/* Character Buffer */
222typedef struct {
223    int length;
224    char *value;
225} mgs_char_buffer_t;
226
227/* GnuTLS Handle */
228typedef struct {
229        /* Server configuration record */
230    mgs_srvconf_rec *sc;
231        /* Connection record */
232    conn_rec* c;
233        /* Is TLS enabled for this connection? */
234    int enabled;
235    /* Is this a proxy connection? */
236    int is_proxy;
237        /* GnuTLS Session handle */
238    gnutls_session_t session;
239        /* module input status */
240    apr_status_t input_rc;
241        /* Input filter */
242    ap_filter_t *input_filter;
243        /* Input Bucket Brigade */
244    apr_bucket_brigade *input_bb;
245        /* Input Read Type */
246    apr_read_type_e input_block;
247        /* Input Mode */
248    ap_input_mode_t input_mode;
249        /* Input Character Buffer */
250    mgs_char_buffer_t input_cbuf;
251        /* Input Character Array */
252    char input_buffer[AP_IOBUFSIZE];
253        /* module Output status */
254    apr_status_t output_rc;
255        /* Output filter */
256    ap_filter_t *output_filter;
257        /* Output Bucket Brigade */
258    apr_bucket_brigade *output_bb;
259        /* Output character array */
260    char output_buffer[AP_IOBUFSIZE];
261        /* Output buffer length */
262    apr_size_t output_blen;
263        /* Output length */
264    apr_size_t output_length;
265        /* General Status */
266    int status;
267} mgs_handle_t;
268
269
270
271/** Functions in gnutls_io.c **/
272
273/* apr_signal_block() for blocking SIGPIPE */
274apr_status_t apr_signal_block(int signum);
275
276 /* Proxy Support */
277/* An optional function which returns non-zero if the given connection
278is using SSL/TLS. */
279APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
280/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
281 * are used by mod_proxy to enable use of SSL for outgoing
282 * connections. */
283APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
284APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
285int ssl_is_https(conn_rec *c);
286int ssl_proxy_enable(conn_rec *c);
287int ssl_engine_disable(conn_rec *c);
288const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
289                                 const int arg);
290apr_status_t mgs_cleanup_pre_config(void *data);
291
292/**
293 * mgs_filter_input will filter the input data
294 * by decrypting it using GnuTLS and passes it cleartext.
295 *
296 * @param f     the filter info record
297 * @param bb    the bucket brigade, where to store the result to
298 * @param mode  what shall we read?
299 * @param block a block index we shall read from?
300 * @return result status
301 */
302apr_status_t mgs_filter_input(ap_filter_t * f,
303                                     apr_bucket_brigade * bb,
304                                     ap_input_mode_t mode,
305                                     apr_read_type_e block,
306                                     apr_off_t readbytes);
307
308/**
309 * mgs_filter_output will filter the encrypt
310 * the incoming bucket using GnuTLS and passes it onto the next filter.
311 *
312 * @param f     the filter info record
313 * @param bb    the bucket brigade, where to store the result to
314 * @return result status
315 */
316apr_status_t mgs_filter_output(ap_filter_t * f,
317                                      apr_bucket_brigade * bb);
318
319
320/**
321 * mgs_transport_read is called from GnuTLS to provide encrypted
322 * data from the client.
323 *
324 * @param ptr     pointer to the filter context
325 * @param buffer  place to put data
326 * @param len     maximum size
327 * @return size   length of the data stored in buffer
328 */
329ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
330                                  void *buffer, size_t len);
331
332/**
333 * mgs_transport_write is called from GnuTLS to
334 * write data to the client.
335 *
336 * @param ptr     pointer to the filter context
337 * @param buffer  buffer to write to the client
338 * @param len     size of the buffer
339 * @return size   length of the data written
340 */
341ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
342                                   const void *buffer, size_t len);
343
344
345int mgs_rehandshake(mgs_handle_t * ctxt);
346
347
348
349/**
350 * Init the Cache after Configuration is done
351 */
352int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
353                                 mgs_srvconf_rec *sc);
354/**
355 * Init the Cache inside each Process
356 */
357int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
358                                mgs_srvconf_rec *sc);
359/**
360 * Setup the Session Caching
361 */
362int mgs_cache_session_init(mgs_handle_t *ctxt);
363
364#define GNUTLS_SESSION_ID_STRING_LEN \
365    ((GNUTLS_MAX_SESSION_ID + 1) * 2)
366
367/**
368 * Perform any reinitialization required in PKCS #11
369 */
370int mgs_pkcs11_reinit(server_rec * s);
371
372/**
373 * Convert a SSL Session ID into a Null Terminated Hex Encoded String
374 * @param id raw SSL Session ID
375 * @param idlen Length of the raw Session ID
376 * @param str Location to store the Hex Encoded String
377 * @param strsize The Maximum Length that can be stored in str
378 */
379char *mgs_session_id2sz(unsigned char *id, int idlen,
380                                char *str, int strsize);
381
382/**
383 * Convert a time_t into a Null Terminated String
384 * @param t time_t time
385 * @param str Location to store the Hex Encoded String
386 * @param strsize The Maximum Length that can be stored in str
387 */
388char *mgs_time2sz(time_t t, char *str, int strsize);
389
390
391/* Configuration Functions */
392
393/* Loads all files set in the configuration */
394int mgs_load_files(apr_pool_t * p, server_rec * s);
395
396const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
397                                        const char *arg);
398const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
399                                        const char *arg);
400const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
401                                        const char *arg);
402const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
403                                        const char *arg);
404
405const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
406                             const char *arg);
407
408const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
409                                        const char *arg);
410
411const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
412                             const char *arg);
413
414const char *mgs_set_cache(cmd_parms * parms, void *dummy,
415                          const char *type, const char* arg);
416
417const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy,
418                                  const char *arg);
419
420const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
421                                  const char *arg);
422
423const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
424                                         const char *arg);
425
426const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
427                                   const char *arg);
428
429const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
430                               const char *arg);
431
432const char *mgs_set_pin(cmd_parms * parms, void *dummy,
433                                   const char *arg);
434
435const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
436                                   const char *arg);
437
438const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
439                                   const char *arg);
440
441const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
442                            const int arg);
443const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
444                            const char *arg);
445const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
446                            const char *arg);
447const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
448                            const int arg);
449
450const char *mgs_set_require_section(cmd_parms *cmd,
451                                    void *mconfig, const char *arg);
452void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
453void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
454
455void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
456
457void *mgs_config_dir_create(apr_pool_t *p, char *dir);
458
459const char *mgs_set_require_bytecode(cmd_parms *cmd,
460                                    void *mconfig, const char *arg);
461
462mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
463
464const char *mgs_store_cred_path(cmd_parms * parms,
465                                void *dummy __attribute__((unused)),
466                                const char *arg);
467
468/* mod_gnutls Hooks. */
469
470int mgs_hook_pre_config(apr_pool_t * pconf,
471                        apr_pool_t * plog, apr_pool_t * ptemp);
472
473int mgs_hook_post_config(apr_pool_t *pconf,
474                         apr_pool_t *plog,
475                         apr_pool_t *ptemp,
476                         server_rec *base_server);
477
478void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
479
480const char *mgs_hook_http_scheme(const request_rec * r);
481
482apr_port_t mgs_hook_default_port(const request_rec * r);
483
484int mgs_hook_pre_connection(conn_rec * c, void *csd);
485
486int mgs_hook_fixups(request_rec *r);
487
488int mgs_hook_authz(request_rec *r);
489
490#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.