source: mod_gnutls/include/mod_gnutls.h.in @ 39bd695

asynciodebian/masterdebian/stretch-backportsjessie-backportsproxy-ticketupstream
Last change on this file since 39bd695 was 4133f2d, checked in by Thomas Klute <thomas2.klute@…>, 6 years ago

Unify argument handling in mgs_set_priorities

Just store the argument in mgs_set_priorities for both front end and
proxy priorities. Like the front end priorities, the gnutls_priority_t
structure for proxy connections now gets initialized when the
credentials are loaded (load_proxy_x509_credentials in gnutls_hooks.c).

  • Property mode set to 100644
File size: 14.5 KB
RevLine 
[fcb122d]1/**
2 *  Copyright 2004-2005 Paul Querna
[7e2b223]3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *  Unless required by applicable law or agreed to in writing, software
11 *  distributed under the License is distributed on an "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *  See the License for the specific language governing permissions and
14 *  limitations under the License.
15 *
16 */
17
[3b4c0d0]18/* Apache Runtime Headers */
[7e2b223]19#include "httpd.h"
20#include "http_config.h"
21#include "http_protocol.h"
22#include "http_connection.h"
[76bd3bf]23#include "http_request.h"
[7e2b223]24#include "http_core.h"
25#include "http_log.h"
26#include "apr_buckets.h"
27#include "apr_strings.h"
28#include "apr_tables.h"
[482f47f]29#include "ap_release.h"
[9ddaa29]30#include "apr_fnmatch.h"
[3b4c0d0]31/* GnuTLS Library Headers */
[31645b2]32#include <gnutls/gnutls.h>
[3596d6a]33#if GNUTLS_VERSION_MAJOR == 2
[e5bbda4]34#include <gnutls/extra.h>
[3596d6a]35#endif
[031acac]36#include <gnutls/abstract.h>
[e5bbda4]37#include <gnutls/openpgp.h>
[31645b2]38#include <gnutls/x509.h>
39
[05d56ce]40#ifndef __mod_gnutls_h_inc
41#define __mod_gnutls_h_inc
42
[6e0bfd6]43#define HAVE_APR_MEMCACHE    @have_apr_memcache@
[a66e147]44
[6d4de37]45extern module AP_MODULE_DECLARE_DATA gnutls_module;
[7e2b223]46
[3b4c0d0]47/* IO Filter names */
[7e2b223]48#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
49#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
[3b4c0d0]50/* GnuTLS Constants */
[7e2b223]51#define GNUTLS_ENABLED_FALSE 0
52#define GNUTLS_ENABLED_TRUE  1
[040387c]53#define GNUTLS_ENABLED_UNSET  2
[3b4c0d0]54/* Current module version */
[032ff02]55#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
56
[3b4c0d0]57/* Module Debug Mode */
[032ff02]58#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
[3b4c0d0]59
[671b64f]60/*
61 * Recent Versions of 2.1 renamed several hooks.
62 * This allows us to compile on 2.0.xx
[3b4c0d0]63 */
[7e67487]64#if AP_SERVER_MINORVERSION_NUMBER >= 2 || (AP_SERVER_MINORVERSION_NUMBER == 1 && AP_SERVER_PATCHLEVEL_NUMBER >= 3)
[3b4c0d0]65        #define USING_2_1_RECENT 1
[7c05ed1]66#else
[3b4c0d0]67        #define USING_2_1_RECENT 0
[671b64f]68#endif
[482f47f]69
[3b4c0d0]70/* mod_gnutls Cache Types */
71typedef enum {
72        /* No Cache */
[c301152]73    mgs_cache_none,
[3b4c0d0]74        /* Use Old Berkley DB */
[c301152]75    mgs_cache_dbm,
[3b4c0d0]76        /* Use Gnu's version of Berkley DB */
[d8c7cf4]77    mgs_cache_gdbm,
[fcb122d]78#if HAVE_APR_MEMCACHE
[3b4c0d0]79        /* Use Memcache */
[040387c]80    mgs_cache_memcache,
[2e12226]81#endif
[040387c]82    mgs_cache_unset
[c301152]83} mgs_cache_e;
[2e12226]84
[cf2b905]85typedef enum {
86    mgs_cvm_unset,
87    mgs_cvm_cartel,
88    mgs_cvm_msva
89} mgs_client_verification_method_e;
90
91
[3b4c0d0]92/* Directory Configuration Record */
93typedef struct {
[e924ddd]94    int client_verify_mode;
[84cb5b2]95    const char* lua_bytecode;
96    apr_size_t lua_bytecode_len;
[c301152]97} mgs_dirconf_rec;
[31645b2]98
[7bebb42]99
[3b4c0d0]100/* The maximum number of certificates to send in a chain */
[5e81262]101#define MAX_CHAIN_SIZE 8
[3b4c0d0]102/* The maximum number of SANs to read from a x509 certificate */
103#define MAX_CERT_SAN 5
[7bebb42]104
[3b4c0d0]105/* Server Configuration Record */
106typedef struct {
[031acac]107    /* --- Configuration values --- */
108        /* Is the module enabled? */
109    int enabled;
110        /* Is mod_proxy enabled? */
111    int proxy_enabled;
112        /* A Plain HTTP request */
113    int non_ssl_request;
114
115    /* PIN used for PKCS #11 operations */
116    char *pin;
117
118    /* the SRK PIN used in TPM operations */
119    char *srk_pin;
120
121    char *x509_cert_file;
122    char *x509_key_file;
123    char *x509_ca_file;
124
125    char *pgp_cert_file;
126    char *pgp_key_file;
127    char *pgp_ring_file;
128
129    char *dh_file;
[7314438]130
[031acac]131    char *priorities_str;
[4133f2d]132    char *proxy_priorities_str;
[031acac]133
134    const char* srp_tpasswd_file;
135    const char* srp_tpasswd_conf_file;
136
137        /* Cache timeout value */
138    int cache_timeout;
139        /* Chose Cache Type */
140    mgs_cache_e cache_type;
141    const char* cache_config;
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;
[c301152]212} mgs_srvconf_rec;
[7e2b223]213
[3b4c0d0]214/* Character Buffer */
[dae0aec]215typedef struct {
216    int length;
217    char *value;
[c301152]218} mgs_char_buffer_t;
[dae0aec]219
[3b4c0d0]220/* GnuTLS Handle */
221typedef struct {
222        /* Server configuration record */
[c301152]223    mgs_srvconf_rec *sc;
[3b4c0d0]224        /* Connection record */
[dae0aec]225    conn_rec* c;
[e8acf05]226        /* Is TLS enabled for this connection? */
227    int enabled;
[c1ef069]228    /* Is this a proxy connection? */
229    int is_proxy;
[3b4c0d0]230        /* GnuTLS Session handle */
[7e2b223]231    gnutls_session_t session;
[3b4c0d0]232        /* module input status */
[dae0aec]233    apr_status_t input_rc;
[3b4c0d0]234        /* Input filter */
[7e2b223]235    ap_filter_t *input_filter;
[3b4c0d0]236        /* Input Bucket Brigade */
[7e2b223]237    apr_bucket_brigade *input_bb;
[3b4c0d0]238        /* Input Read Type */
[7e2b223]239    apr_read_type_e input_block;
[3b4c0d0]240        /* Input Mode */
[dae0aec]241    ap_input_mode_t input_mode;
[3b4c0d0]242        /* Input Character Buffer */
[c301152]243    mgs_char_buffer_t input_cbuf;
[3b4c0d0]244        /* Input Character Array */
[dae0aec]245    char input_buffer[AP_IOBUFSIZE];
[3b4c0d0]246        /* module Output status */
[dae0aec]247    apr_status_t output_rc;
[3b4c0d0]248        /* Output filter */
[dae0aec]249    ap_filter_t *output_filter;
[3b4c0d0]250        /* Output Bucket Brigade */
[dae0aec]251    apr_bucket_brigade *output_bb;
[3b4c0d0]252        /* Output character array */
[dae0aec]253    char output_buffer[AP_IOBUFSIZE];
[3b4c0d0]254        /* Output buffer length */
[dae0aec]255    apr_size_t output_blen;
[3b4c0d0]256        /* Output length */
[dae0aec]257    apr_size_t output_length;
[3b4c0d0]258        /* General Status */
[7e2b223]259    int status;
[c301152]260} mgs_handle_t;
[7e2b223]261
[3b4c0d0]262
263
[7e2b223]264/** Functions in gnutls_io.c **/
265
[fb26be5]266/* apr_signal_block() for blocking SIGPIPE */
267apr_status_t apr_signal_block(int signum);
268
[33826c5]269 /* Proxy Support */
[37f8282]270/* An optional function which returns non-zero if the given connection
271is using SSL/TLS. */
272APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
273/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
274 * are used by mod_proxy to enable use of SSL for outgoing
275 * connections. */
276APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
277APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
278int ssl_is_https(conn_rec *c);
[33826c5]279int ssl_proxy_enable(conn_rec *c);
280int ssl_engine_disable(conn_rec *c);
[37f8282]281const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
282    const char *arg);
283apr_status_t mgs_cleanup_pre_config(void *data);
[33826c5]284
[7e2b223]285/**
[c301152]286 * mgs_filter_input will filter the input data
[7e2b223]287 * by decrypting it using GnuTLS and passes it cleartext.
288 *
289 * @param f     the filter info record
290 * @param bb    the bucket brigade, where to store the result to
291 * @param mode  what shall we read?
292 * @param block a block index we shall read from?
293 * @return result status
294 */
[c301152]295apr_status_t mgs_filter_input(ap_filter_t * f,
[2e12226]296                                     apr_bucket_brigade * bb,
297                                     ap_input_mode_t mode,
298                                     apr_read_type_e block,
299                                     apr_off_t readbytes);
[7e2b223]300
301/**
[c301152]302 * mgs_filter_output will filter the encrypt
[7e2b223]303 * the incoming bucket using GnuTLS and passes it onto the next filter.
304 *
305 * @param f     the filter info record
306 * @param bb    the bucket brigade, where to store the result to
307 * @return result status
308 */
[c301152]309apr_status_t mgs_filter_output(ap_filter_t * f,
[2e12226]310                                      apr_bucket_brigade * bb);
[7e2b223]311
312
313/**
[671b64f]314 * mgs_transport_read is called from GnuTLS to provide encrypted
[7e2b223]315 * data from the client.
316 *
317 * @param ptr     pointer to the filter context
318 * @param buffer  place to put data
319 * @param len     maximum size
320 * @return size   length of the data stored in buffer
321 */
[c301152]322ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
[2e12226]323                                  void *buffer, size_t len);
[7e2b223]324
325/**
[671b64f]326 * mgs_transport_write is called from GnuTLS to
[7e2b223]327 * write data to the client.
328 *
329 * @param ptr     pointer to the filter context
330 * @param buffer  buffer to write to the client
331 * @param len     size of the buffer
332 * @return size   length of the data written
333 */
[c301152]334ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
[2e12226]335                                   const void *buffer, size_t len);
[7e2b223]336
337
[c301152]338int mgs_rehandshake(mgs_handle_t * ctxt);
[e924ddd]339
340
341
[a66e147]342/**
[fcb122d]343 * Init the Cache after Configuration is done
344 */
[671b64f]345int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
[c301152]346                                 mgs_srvconf_rec *sc);
[fcb122d]347/**
[a66e147]348 * Init the Cache inside each Process
349 */
[671b64f]350int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
[c301152]351                                mgs_srvconf_rec *sc);
[a66e147]352/**
353 * Setup the Session Caching
354 */
[c301152]355int mgs_cache_session_init(mgs_handle_t *ctxt);
[05d56ce]356
[42307a9]357#define GNUTLS_SESSION_ID_STRING_LEN \
358    ((GNUTLS_MAX_SESSION_ID + 1) * 2)
[671b64f]359
[42307a9]360/**
[031acac]361 * Perform any reinitialization required in PKCS #11
362 */
363int mgs_pkcs11_reinit(server_rec * s);
364
365/**
[42307a9]366 * Convert a SSL Session ID into a Null Terminated Hex Encoded String
367 * @param id raw SSL Session ID
368 * @param idlen Length of the raw Session ID
369 * @param str Location to store the Hex Encoded String
370 * @param strsize The Maximum Length that can be stored in str
371 */
[c301152]372char *mgs_session_id2sz(unsigned char *id, int idlen,
[42307a9]373                                char *str, int strsize);
374
[7bebb42]375/**
376 * Convert a time_t into a Null Terminated String
377 * @param t time_t time
378 * @param str Location to store the Hex Encoded String
379 * @param strsize The Maximum Length that can be stored in str
380 */
381char *mgs_time2sz(time_t t, char *str, int strsize);
382
[c301152]383
[46b85d8]384/* Configuration Functions */
385
[031acac]386/* Loads all files set in the configuration */
387int mgs_load_files(apr_pool_t * p, server_rec * s);
388
[7bebb42]389const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
390                                        const char *arg);
391const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
392                                        const char *arg);
393const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
394                                        const char *arg);
[46b85d8]395const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
396                                        const char *arg);
397
398const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
399                             const char *arg);
400
[e5bbda4]401const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
402                                        const char *arg);
403
404const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
405                             const char *arg);
406
[46b85d8]407const char *mgs_set_cache(cmd_parms * parms, void *dummy,
408                          const char *type, const char* arg);
409
410const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy,
411                                  const char *arg);
412
413const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
414                                  const char *arg);
415
[cf2b905]416const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
417                                         const char *arg);
418
[46b85d8]419const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
420                                   const char *arg);
[031acac]421const char *mgs_set_pin(cmd_parms * parms, void *dummy,
422                                   const char *arg);
423
424const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy,
425                                   const char *arg);
[46b85d8]426
[e5bbda4]427const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
428                                   const char *arg);
429
[46b85d8]430const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
431                            const char *arg);
[2aaf4f5]432const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
[7bebb42]433                            const char *arg);
434const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
435                            const char *arg);
[ae233c2]436const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
437                            const char *arg);
[671b64f]438
439const char *mgs_set_require_section(cmd_parms *cmd,
[84cb5b2]440                                    void *mconfig, const char *arg);
[46b85d8]441void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
[040387c]442void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
[46b85d8]443
[84cb5b2]444void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
445
[46b85d8]446void *mgs_config_dir_create(apr_pool_t *p, char *dir);
447
[671b64f]448const char *mgs_set_require_bytecode(cmd_parms *cmd,
[84cb5b2]449                                    void *mconfig, const char *arg);
450
[836417f]451mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
[c301152]452
[0de1839]453const char *mgs_store_cred_path(cmd_parms * parms,
454                                void *dummy __attribute__((unused)),
455                                const char *arg);
456
[c301152]457/* mod_gnutls Hooks. */
458
459int mgs_hook_pre_config(apr_pool_t * pconf,
460                        apr_pool_t * plog, apr_pool_t * ptemp);
461
462int mgs_hook_post_config(apr_pool_t * p, apr_pool_t * plog,
463                         apr_pool_t * ptemp,
464                         server_rec * base_server);
465
466void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
467
468const char *mgs_hook_http_scheme(const request_rec * r);
469
470apr_port_t mgs_hook_default_port(const request_rec * r);
471
472int mgs_hook_pre_connection(conn_rec * c, void *csd);
473
474int mgs_hook_fixups(request_rec *r);
475
476int mgs_hook_authz(request_rec *r);
477
[7e2b223]478#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.