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

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

Bind temporary pool in mgs_load_files() to ptemp scope

Pool 'spool' is destroyed at the end of the function, so the temporary
scope is definitely appropriate. This ensures cleanup in case a bug
prevents explicit pool destruction.

  • Property mode set to 100644
File size: 14.1 KB
RevLine 
[fcb122d]1/**
2 *  Copyright 2004-2005 Paul Querna
[e021722]3 *  Copyright 2014 Nikos Mavrogiannopoulos
[8913410]4 *  Copyright 2015-2016 Thomas Klute
[7e2b223]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
[3b4c0d0]20/* Apache Runtime Headers */
[7e2b223]21#include "httpd.h"
22#include "http_config.h"
23#include "http_protocol.h"
24#include "http_connection.h"
[76bd3bf]25#include "http_request.h"
[7e2b223]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"
[482f47f]31#include "ap_release.h"
[9ddaa29]32#include "apr_fnmatch.h"
[3b4c0d0]33/* GnuTLS Library Headers */
[31645b2]34#include <gnutls/gnutls.h>
[031acac]35#include <gnutls/abstract.h>
[e5bbda4]36#include <gnutls/openpgp.h>
[31645b2]37#include <gnutls/x509.h>
38
[05d56ce]39#ifndef __mod_gnutls_h_inc
40#define __mod_gnutls_h_inc
41
[6e0bfd6]42#define HAVE_APR_MEMCACHE    @have_apr_memcache@
[a66e147]43
[6d4de37]44extern module AP_MODULE_DECLARE_DATA gnutls_module;
[7e2b223]45
[3b4c0d0]46/* IO Filter names */
[7e2b223]47#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
48#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
[3b4c0d0]49/* GnuTLS Constants */
[7e2b223]50#define GNUTLS_ENABLED_FALSE 0
51#define GNUTLS_ENABLED_TRUE  1
[040387c]52#define GNUTLS_ENABLED_UNSET  2
[3b4c0d0]53/* Current module version */
[032ff02]54#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
55
[3b4c0d0]56/* Module Debug Mode */
[032ff02]57#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
[3b4c0d0]58
59/* mod_gnutls Cache Types */
60typedef enum {
61        /* No Cache */
[c301152]62    mgs_cache_none,
[3b4c0d0]63        /* Use Old Berkley DB */
[c301152]64    mgs_cache_dbm,
[3b4c0d0]65        /* Use Gnu's version of Berkley DB */
[d8c7cf4]66    mgs_cache_gdbm,
[fcb122d]67#if HAVE_APR_MEMCACHE
[3b4c0d0]68        /* Use Memcache */
[040387c]69    mgs_cache_memcache,
[2e12226]70#endif
[040387c]71    mgs_cache_unset
[c301152]72} mgs_cache_e;
[2e12226]73
[e809fb3]74/* Internal cache data, defined in gnutls_cache.h */
75typedef struct mgs_cache* mgs_cache_t;
76
[cf2b905]77typedef enum {
78    mgs_cvm_unset,
79    mgs_cvm_cartel,
80    mgs_cvm_msva
81} mgs_client_verification_method_e;
82
83
[3b4c0d0]84/* Directory Configuration Record */
85typedef struct {
[e924ddd]86    int client_verify_mode;
[c301152]87} mgs_dirconf_rec;
[31645b2]88
[7bebb42]89
[cc74801]90/* Internal per-vhost config for OCSP, defined in gnutls_ocsp.h */
91typedef struct mgs_ocsp_data* mgs_ocsp_data_t;
92
93
[3b4c0d0]94/* The maximum number of certificates to send in a chain */
[5e81262]95#define MAX_CHAIN_SIZE 8
[3b4c0d0]96/* The maximum number of SANs to read from a x509 certificate */
97#define MAX_CERT_SAN 5
[7bebb42]98
[3b4c0d0]99/* Server Configuration Record */
100typedef struct {
[031acac]101    /* --- Configuration values --- */
102        /* Is the module enabled? */
103    int enabled;
104        /* Is mod_proxy enabled? */
105    int proxy_enabled;
106        /* A Plain HTTP request */
107    int non_ssl_request;
108
[9ca1f21]109    /* List of PKCS #11 provider modules to load, only valid in the
[87f1ed2]110     * base config, ignored in virtual hosts */
[9ca1f21]111    apr_array_header_t *p11_modules;
[87f1ed2]112
[031acac]113    /* PIN used for PKCS #11 operations */
114    char *pin;
115
116    /* the SRK PIN used in TPM operations */
117    char *srk_pin;
118
119    char *x509_cert_file;
120    char *x509_key_file;
121    char *x509_ca_file;
122
123    char *pgp_cert_file;
124    char *pgp_key_file;
125    char *pgp_ring_file;
126
127    char *dh_file;
[7314438]128
[031acac]129    char *priorities_str;
[4133f2d]130    char *proxy_priorities_str;
[031acac]131
132    const char* srp_tpasswd_file;
133    const char* srp_tpasswd_conf_file;
134
135        /* Cache timeout value */
136    int cache_timeout;
137        /* Chose Cache Type */
138    mgs_cache_e cache_type;
139    const char* cache_config;
[e809fb3]140    /* Internal cache data */
141    mgs_cache_t cache;
[031acac]142
143        /* GnuTLS uses Session Tickets */
144    int tickets;
145
146    /* --- Things initialized at _child_init --- */
147
[0de1839]148    /* x509 Certificate Structure */
[671b64f]149    gnutls_certificate_credentials_t certs;
[0de1839]150    /* x509 credentials for proxy connections */
151    gnutls_certificate_credentials_t proxy_x509_creds;
[bd24203]152    /* trust list for proxy_x509_creds */
153    gnutls_x509_trust_list_t proxy_x509_tl;
[0de1839]154    const char* proxy_x509_key_file;
155    const char* proxy_x509_cert_file;
156    const char* proxy_x509_ca_file;
[809c422]157    const char* proxy_x509_crl_file;
[f030883]158    /* GnuTLS priorities for proxy connections */
159    gnutls_priority_t proxy_priorities;
[0de1839]160    /* SRP Certificate Structure*/
[7bebb42]161    gnutls_srp_server_credentials_t srp_creds;
[beb14d9]162    /* Anonymous Certificate Structure */
[7bebb42]163    gnutls_anon_server_credentials_t anon_creds;
[beb14d9]164    /* Anonymous Client Certificate Structure, used for proxy
165     * connections */
166    gnutls_anon_client_credentials_t anon_client_creds;
[3b4c0d0]167        /* Current x509 Certificate CN [Common Name] */
[e924ddd]168    char* cert_cn;
[3b4c0d0]169        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
[031acac]170    char* cert_san[MAX_CERT_SAN];
171        /* An x509 Certificate Chain */
172    gnutls_pcert_st *certs_x509_chain;
173    gnutls_x509_crt_t *certs_x509_crt_chain;
174        /* Number of Certificates in Chain */
175    unsigned int certs_x509_chain_num;
176
[3b4c0d0]177        /* Current x509 Certificate Private Key */
[031acac]178    gnutls_privkey_t privkey_x509;
179
[3b4c0d0]180        /* OpenPGP Certificate */
[031acac]181    gnutls_pcert_st *cert_pgp;
182    gnutls_openpgp_crt_t *cert_crt_pgp;
183
[3b4c0d0]184        /* OpenPGP Certificate Private Key */
[031acac]185    gnutls_privkey_t privkey_pgp;
[d04f7da]186#if GNUTLS_VERSION_NUMBER < 0x030312
187    /* Internal structure for the OpenPGP private key, used in the
188     * workaround for a bug in gnutls_privkey_import_openpgp_raw that
189     * frees memory that is still needed. DO NOT USE for any other
190     * purpose. */
[2cde8111]191    gnutls_openpgp_privkey_t privkey_pgp_internal;
[d04f7da]192#endif
[031acac]193
[7d1ab49]194    /* Export full certificates to CGI environment: */
[2aaf4f5]195    int export_certificates_size;
[3b4c0d0]196        /* GnuTLS Priorities */
[7bebb42]197    gnutls_priority_t priorities;
[3b4c0d0]198        /* GnuTLS DH Parameters */
[a3c97d1]199    gnutls_dh_params_t dh_params;
[3b4c0d0]200        /* A list of CA Certificates */
[8663ace]201    gnutls_x509_crt_t *ca_list;
[3b4c0d0]202        /* OpenPGP Key Ring */
[e5bbda4]203    gnutls_openpgp_keyring_t pgp_list;
[3b4c0d0]204        /* CA Certificate list size */
[7bebb42]205    unsigned int ca_list_size;
[3b4c0d0]206        /* Client Certificate Verification Mode */
[e924ddd]207    int client_verify_mode;
[cf2b905]208        /* Client Certificate Verification Method */
209    mgs_client_verification_method_e client_verify_method;
[3b4c0d0]210        /* Last Cache timestamp */
[f10ab4f]211    apr_time_t last_cache_check;
[94cb972]212
213    /* EXPERIMENTAL: OCSP response file for stapling, will go away
214     * once sending OCSP requests is implemented */
215    char *ocsp_response_file;
[cc74801]216    /* Server specific OCSP data */
217    mgs_ocsp_data_t ocsp;
[d6834e0]218    /* Mutex to prevent parallel OCSP requests */
219    apr_global_mutex_t *ocsp_mutex;
[70a1e5a]220    /* Cached OCSP responses expire this long before their validity
221     * period expires. This way mod_gnutls does not staple barely
222     * valid responses. */
223    apr_time_t ocsp_grace_time;
[c301152]224} mgs_srvconf_rec;
[7e2b223]225
[3b4c0d0]226/* Character Buffer */
[dae0aec]227typedef struct {
228    int length;
229    char *value;
[c301152]230} mgs_char_buffer_t;
[dae0aec]231
[3b4c0d0]232/* GnuTLS Handle */
233typedef struct {
234        /* Server configuration record */
[c301152]235    mgs_srvconf_rec *sc;
[3b4c0d0]236        /* Connection record */
[dae0aec]237    conn_rec* c;
[e8acf05]238        /* Is TLS enabled for this connection? */
239    int enabled;
[c1ef069]240    /* Is this a proxy connection? */
241    int is_proxy;
[3b4c0d0]242        /* GnuTLS Session handle */
[7e2b223]243    gnutls_session_t session;
[3b4c0d0]244        /* module input status */
[dae0aec]245    apr_status_t input_rc;
[3b4c0d0]246        /* Input filter */
[7e2b223]247    ap_filter_t *input_filter;
[3b4c0d0]248        /* Input Bucket Brigade */
[7e2b223]249    apr_bucket_brigade *input_bb;
[3b4c0d0]250        /* Input Read Type */
[7e2b223]251    apr_read_type_e input_block;
[3b4c0d0]252        /* Input Mode */
[dae0aec]253    ap_input_mode_t input_mode;
[3b4c0d0]254        /* Input Character Buffer */
[c301152]255    mgs_char_buffer_t input_cbuf;
[3b4c0d0]256        /* Input Character Array */
[dae0aec]257    char input_buffer[AP_IOBUFSIZE];
[3b4c0d0]258        /* module Output status */
[dae0aec]259    apr_status_t output_rc;
[3b4c0d0]260        /* Output filter */
[dae0aec]261    ap_filter_t *output_filter;
[3b4c0d0]262        /* Output Bucket Brigade */
[dae0aec]263    apr_bucket_brigade *output_bb;
[3b4c0d0]264        /* Output character array */
[dae0aec]265    char output_buffer[AP_IOBUFSIZE];
[3b4c0d0]266        /* Output buffer length */
[dae0aec]267    apr_size_t output_blen;
[3b4c0d0]268        /* Output length */
[dae0aec]269    apr_size_t output_length;
[3b4c0d0]270        /* General Status */
[7e2b223]271    int status;
[c301152]272} mgs_handle_t;
[7e2b223]273
[3b4c0d0]274
275
[7e2b223]276/** Functions in gnutls_io.c **/
277
[fb26be5]278/* apr_signal_block() for blocking SIGPIPE */
279apr_status_t apr_signal_block(int signum);
280
[33826c5]281 /* Proxy Support */
[37f8282]282/* An optional function which returns non-zero if the given connection
283is using SSL/TLS. */
284APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
285/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
286 * are used by mod_proxy to enable use of SSL for outgoing
287 * connections. */
288APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
289APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
290int ssl_is_https(conn_rec *c);
[33826c5]291int ssl_proxy_enable(conn_rec *c);
292int ssl_engine_disable(conn_rec *c);
[37f8282]293const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
[176047e]294                                 const int arg);
[37f8282]295apr_status_t mgs_cleanup_pre_config(void *data);
[33826c5]296
[7e2b223]297/**
[c301152]298 * mgs_filter_input will filter the input data
[7e2b223]299 * by decrypting it using GnuTLS and passes it cleartext.
300 *
301 * @param f     the filter info record
302 * @param bb    the bucket brigade, where to store the result to
303 * @param mode  what shall we read?
304 * @param block a block index we shall read from?
305 * @return result status
306 */
[c301152]307apr_status_t mgs_filter_input(ap_filter_t * f,
[2e12226]308                                     apr_bucket_brigade * bb,
309                                     ap_input_mode_t mode,
310                                     apr_read_type_e block,
311                                     apr_off_t readbytes);
[7e2b223]312
313/**
[c301152]314 * mgs_filter_output will filter the encrypt
[7e2b223]315 * the incoming bucket using GnuTLS and passes it onto the next filter.
316 *
317 * @param f     the filter info record
318 * @param bb    the bucket brigade, where to store the result to
319 * @return result status
320 */
[c301152]321apr_status_t mgs_filter_output(ap_filter_t * f,
[2e12226]322                                      apr_bucket_brigade * bb);
[7e2b223]323
324
325/**
[671b64f]326 * mgs_transport_read is called from GnuTLS to provide encrypted
[7e2b223]327 * data from the client.
328 *
329 * @param ptr     pointer to the filter context
330 * @param buffer  place to put data
331 * @param len     maximum size
332 * @return size   length of the data stored in buffer
333 */
[c301152]334ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
[2e12226]335                                  void *buffer, size_t len);
[7e2b223]336
337/**
[671b64f]338 * mgs_transport_write is called from GnuTLS to
[7e2b223]339 * write data to the client.
340 *
341 * @param ptr     pointer to the filter context
342 * @param buffer  buffer to write to the client
343 * @param len     size of the buffer
344 * @return size   length of the data written
345 */
[c301152]346ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
[2e12226]347                                   const void *buffer, size_t len);
[7e2b223]348
349
[c301152]350int mgs_rehandshake(mgs_handle_t * ctxt);
[e924ddd]351
352
353
[a66e147]354/**
[031acac]355 * Perform any reinitialization required in PKCS #11
356 */
357int mgs_pkcs11_reinit(server_rec * s);
358
[7bebb42]359
[c301152]360
[46b85d8]361/* Configuration Functions */
362
[031acac]363/* Loads all files set in the configuration */
[eee1432]364int mgs_load_files(apr_pool_t *pconf, apr_pool_t *ptemp, server_rec *s)
365    __attribute__((nonnull));
[031acac]366
[7bebb42]367const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
368                                        const char *arg);
369const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
370                                        const char *arg);
371const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
372                                        const char *arg);
[46b85d8]373const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
374                                        const char *arg);
375
376const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
377                             const char *arg);
378
[e5bbda4]379const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
380                                        const char *arg);
381
382const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
383                             const char *arg);
384
[46b85d8]385const char *mgs_set_cache(cmd_parms * parms, void *dummy,
386                          const char *type, const char* arg);
387
[70a1e5a]388const char *mgs_set_timeout(cmd_parms *parms, void *dummy, const char *arg);
[46b85d8]389
390const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
391                                  const char *arg);
392
[cf2b905]393const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
394                                         const char *arg);
395
[46b85d8]396const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
397                                   const char *arg);
[87f1ed2]398
399const char *mgs_set_p11_module(cmd_parms * parms, void *dummy,
400                               const char *arg);
401
[031acac]402const char *mgs_set_pin(cmd_parms * parms, void *dummy,
403                                   const char *arg);
404
405const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
406                                   const char *arg);
[46b85d8]407
[e5bbda4]408const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
409                                   const char *arg);
410
[46b85d8]411const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
[176047e]412                            const int arg);
[2aaf4f5]413const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
[7bebb42]414                            const char *arg);
415const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
416                            const char *arg);
[ae233c2]417const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
[176047e]418                            const int arg);
[671b64f]419
420const char *mgs_set_require_section(cmd_parms *cmd,
[84cb5b2]421                                    void *mconfig, const char *arg);
[46b85d8]422void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
[040387c]423void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
[46b85d8]424
[84cb5b2]425void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
426
[46b85d8]427void *mgs_config_dir_create(apr_pool_t *p, char *dir);
428
[671b64f]429const char *mgs_set_require_bytecode(cmd_parms *cmd,
[84cb5b2]430                                    void *mconfig, const char *arg);
431
[836417f]432mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
[c301152]433
[0de1839]434const char *mgs_store_cred_path(cmd_parms * parms,
435                                void *dummy __attribute__((unused)),
436                                const char *arg);
437
[c301152]438/* mod_gnutls Hooks. */
439
440int mgs_hook_pre_config(apr_pool_t * pconf,
441                        apr_pool_t * plog, apr_pool_t * ptemp);
442
[64856fd]443int mgs_hook_post_config(apr_pool_t *pconf,
444                         apr_pool_t *plog,
445                         apr_pool_t *ptemp,
446                         server_rec *base_server);
[c301152]447
448void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
449
450const char *mgs_hook_http_scheme(const request_rec * r);
451
452apr_port_t mgs_hook_default_port(const request_rec * r);
453
454int mgs_hook_pre_connection(conn_rec * c, void *csd);
455
456int mgs_hook_fixups(request_rec *r);
457
458int mgs_hook_authz(request_rec *r);
459
[7e2b223]460#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.