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

debian/masterdebian/stretch-backportsjessie-backportsproxy-ticketupstream
Last change on this file since bc539d5 was 9ca1f21, checked in by Thomas Klute <thomas2.klute@…>, 5 years ago

Allow loading more than one PKCS #11 module using GnuTLSP11Module

This commit allows multiple modules to be loaded using the
GnuTLSP11Module directive. Each occurrence of GnuTLSP11Module causes the
given module to be added to a list, and all modules on that list are
loaded.

Commit f21d2a6dba6378b18d015dde88193fcad70d8728 disabled modules
configured through the system wide p11-kit configuration if
GnuTLSP11Module is set. With that change, using multiple PKCS #11
modules required using the system configuration, since only one module
could be loaded using GnuTLSP11Module.

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