source: mod_gnutls/include/mod_gnutls.h.in @ 809c422

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

TLS proxy: Add support for CRLs to back end server verification

When configured as a TLS proxy, mod_gnutls can now use CRLs to check if
the certificate provided by a back end server is still valid. The CRL
file must be provided externally, the new configuration option
"GnuTLSProxyCRLFile" is used to load it.

  • Property mode set to 100644
File size: 13.1 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
[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
[671b64f]59/*
60 * Recent Versions of 2.1 renamed several hooks.
61 * This allows us to compile on 2.0.xx
[3b4c0d0]62 */
[7e67487]63#if AP_SERVER_MINORVERSION_NUMBER >= 2 || (AP_SERVER_MINORVERSION_NUMBER == 1 && AP_SERVER_PATCHLEVEL_NUMBER >= 3)
[3b4c0d0]64        #define USING_2_1_RECENT 1
[7c05ed1]65#else
[3b4c0d0]66        #define USING_2_1_RECENT 0
[671b64f]67#endif
[482f47f]68
[3b4c0d0]69/* mod_gnutls Cache Types */
70typedef enum {
71        /* No Cache */
[c301152]72    mgs_cache_none,
[3b4c0d0]73        /* Use Old Berkley DB */
[c301152]74    mgs_cache_dbm,
[3b4c0d0]75        /* Use Gnu's version of Berkley DB */
[d8c7cf4]76    mgs_cache_gdbm,
[fcb122d]77#if HAVE_APR_MEMCACHE
[3b4c0d0]78        /* Use Memcache */
[040387c]79    mgs_cache_memcache,
[2e12226]80#endif
[040387c]81    mgs_cache_unset
[c301152]82} mgs_cache_e;
[2e12226]83
[cf2b905]84typedef enum {
85    mgs_cvm_unset,
86    mgs_cvm_cartel,
87    mgs_cvm_msva
88} mgs_client_verification_method_e;
89
90
[3b4c0d0]91/* Directory Configuration Record */
92typedef struct {
[e924ddd]93    int client_verify_mode;
[84cb5b2]94    const char* lua_bytecode;
95    apr_size_t lua_bytecode_len;
[c301152]96} mgs_dirconf_rec;
[31645b2]97
[7bebb42]98
[3b4c0d0]99/* The maximum number of certificates to send in a chain */
[5e81262]100#define MAX_CHAIN_SIZE 8
[3b4c0d0]101/* The maximum number of SANs to read from a x509 certificate */
102#define MAX_CERT_SAN 5
[7bebb42]103
[3b4c0d0]104/* Server Configuration Record */
105typedef struct {
[0de1839]106    /* x509 Certificate Structure */
[671b64f]107    gnutls_certificate_credentials_t certs;
[0de1839]108    /* x509 credentials for proxy connections */
109    gnutls_certificate_credentials_t proxy_x509_creds;
[bd24203]110    /* trust list for proxy_x509_creds */
111    gnutls_x509_trust_list_t proxy_x509_tl;
[0de1839]112    const char* proxy_x509_key_file;
113    const char* proxy_x509_cert_file;
114    const char* proxy_x509_ca_file;
[809c422]115    const char* proxy_x509_crl_file;
[0de1839]116    /* SRP Certificate Structure*/
[7bebb42]117    gnutls_srp_server_credentials_t srp_creds;
[beb14d9]118    /* Anonymous Certificate Structure */
[7bebb42]119    gnutls_anon_server_credentials_t anon_creds;
[beb14d9]120    /* Anonymous Client Certificate Structure, used for proxy
121     * connections */
122    gnutls_anon_client_credentials_t anon_client_creds;
[3b4c0d0]123        /* Current x509 Certificate CN [Common Name] */
[e924ddd]124    char* cert_cn;
[3b4c0d0]125        /* Current x509 Certificate SAN [Subject Alternate Name]s*/
126        char* cert_san[MAX_CERT_SAN];
127        /* A x509 Certificate Chain */
128    gnutls_x509_crt_t *certs_x509_chain;
129        /* Current x509 Certificate Private Key */
[31645b2]130    gnutls_x509_privkey_t privkey_x509;
[3b4c0d0]131        /* OpenPGP Certificate */
132    gnutls_openpgp_crt_t cert_pgp;
133        /* OpenPGP Certificate Private Key */
[e5bbda4]134    gnutls_openpgp_privkey_t privkey_pgp;
[3b4c0d0]135        /* Number of Certificates in Chain */
136    unsigned int certs_x509_chain_num;
137        /* Is the module enabled? */
[7e2b223]138    int enabled;
[7d1ab49]139    /* Export full certificates to CGI environment: */
[2aaf4f5]140    int export_certificates_size;
[3b4c0d0]141        /* GnuTLS Priorities */
[7bebb42]142    gnutls_priority_t priorities;
[3b4c0d0]143        /* GnuTLS DH Parameters */
[a3c97d1]144    gnutls_dh_params_t dh_params;
[3b4c0d0]145        /* Cache timeout value */
[7bebb42]146    int cache_timeout;
[3b4c0d0]147        /* Chose Cache Type */
[c301152]148    mgs_cache_e cache_type;
[a66e147]149    const char* cache_config;
[7bebb42]150    const char* srp_tpasswd_file;
151    const char* srp_tpasswd_conf_file;
[3b4c0d0]152        /* A list of CA Certificates */
[8663ace]153    gnutls_x509_crt_t *ca_list;
[3b4c0d0]154        /* OpenPGP Key Ring */
[e5bbda4]155    gnutls_openpgp_keyring_t pgp_list;
[3b4c0d0]156        /* CA Certificate list size */
[7bebb42]157    unsigned int ca_list_size;
[3b4c0d0]158        /* Client Certificate Verification Mode */
[e924ddd]159    int client_verify_mode;
[cf2b905]160        /* Client Certificate Verification Method */
161    mgs_client_verification_method_e client_verify_method;
[3b4c0d0]162        /* Last Cache timestamp */
[f10ab4f]163    apr_time_t last_cache_check;
[3b4c0d0]164        /* GnuTLS uses Session Tickets */
[671b64f]165    int tickets;
[3b4c0d0]166        /* Is mod_proxy enabled? */
[33826c5]167    int proxy_enabled;
[3b4c0d0]168        /* A Plain HTTP request */
[9ee0464]169    int non_ssl_request;
[c301152]170} mgs_srvconf_rec;
[7e2b223]171
[3b4c0d0]172/* Character Buffer */
[dae0aec]173typedef struct {
174    int length;
175    char *value;
[c301152]176} mgs_char_buffer_t;
[dae0aec]177
[3b4c0d0]178/* GnuTLS Handle */
179typedef struct {
180        /* Server configuration record */
[c301152]181    mgs_srvconf_rec *sc;
[3b4c0d0]182        /* Connection record */
[dae0aec]183    conn_rec* c;
[e8acf05]184        /* Is TLS enabled for this connection? */
185    int enabled;
[c1ef069]186    /* Is this a proxy connection? */
187    int is_proxy;
[3b4c0d0]188        /* GnuTLS Session handle */
[7e2b223]189    gnutls_session_t session;
[3b4c0d0]190        /* module input status */
[dae0aec]191    apr_status_t input_rc;
[3b4c0d0]192        /* Input filter */
[7e2b223]193    ap_filter_t *input_filter;
[3b4c0d0]194        /* Input Bucket Brigade */
[7e2b223]195    apr_bucket_brigade *input_bb;
[3b4c0d0]196        /* Input Read Type */
[7e2b223]197    apr_read_type_e input_block;
[3b4c0d0]198        /* Input Mode */
[dae0aec]199    ap_input_mode_t input_mode;
[3b4c0d0]200        /* Input Character Buffer */
[c301152]201    mgs_char_buffer_t input_cbuf;
[3b4c0d0]202        /* Input Character Array */
[dae0aec]203    char input_buffer[AP_IOBUFSIZE];
[3b4c0d0]204        /* module Output status */
[dae0aec]205    apr_status_t output_rc;
[3b4c0d0]206        /* Output filter */
[dae0aec]207    ap_filter_t *output_filter;
[3b4c0d0]208        /* Output Bucket Brigade */
[dae0aec]209    apr_bucket_brigade *output_bb;
[3b4c0d0]210        /* Output character array */
[dae0aec]211    char output_buffer[AP_IOBUFSIZE];
[3b4c0d0]212        /* Output buffer length */
[dae0aec]213    apr_size_t output_blen;
[3b4c0d0]214        /* Output length */
[dae0aec]215    apr_size_t output_length;
[3b4c0d0]216        /* General Status */
[7e2b223]217    int status;
[c301152]218} mgs_handle_t;
[7e2b223]219
[3b4c0d0]220
221
[7e2b223]222/** Functions in gnutls_io.c **/
223
[fb26be5]224/* apr_signal_block() for blocking SIGPIPE */
225apr_status_t apr_signal_block(int signum);
226
[33826c5]227 /* Proxy Support */
[37f8282]228/* An optional function which returns non-zero if the given connection
229is using SSL/TLS. */
230APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
231/* The ssl_proxy_enable() and ssl_engine_disable() optional functions
232 * are used by mod_proxy to enable use of SSL for outgoing
233 * connections. */
234APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
235APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
236int ssl_is_https(conn_rec *c);
[33826c5]237int ssl_proxy_enable(conn_rec *c);
238int ssl_engine_disable(conn_rec *c);
[37f8282]239const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy,
240    const char *arg);
241apr_status_t mgs_cleanup_pre_config(void *data);
[33826c5]242
[7e2b223]243/**
[c301152]244 * mgs_filter_input will filter the input data
[7e2b223]245 * by decrypting it using GnuTLS and passes it cleartext.
246 *
247 * @param f     the filter info record
248 * @param bb    the bucket brigade, where to store the result to
249 * @param mode  what shall we read?
250 * @param block a block index we shall read from?
251 * @return result status
252 */
[c301152]253apr_status_t mgs_filter_input(ap_filter_t * f,
[2e12226]254                                     apr_bucket_brigade * bb,
255                                     ap_input_mode_t mode,
256                                     apr_read_type_e block,
257                                     apr_off_t readbytes);
[7e2b223]258
259/**
[c301152]260 * mgs_filter_output will filter the encrypt
[7e2b223]261 * the incoming bucket using GnuTLS and passes it onto the next filter.
262 *
263 * @param f     the filter info record
264 * @param bb    the bucket brigade, where to store the result to
265 * @return result status
266 */
[c301152]267apr_status_t mgs_filter_output(ap_filter_t * f,
[2e12226]268                                      apr_bucket_brigade * bb);
[7e2b223]269
270
271/**
[671b64f]272 * mgs_transport_read is called from GnuTLS to provide encrypted
[7e2b223]273 * data from the client.
274 *
275 * @param ptr     pointer to the filter context
276 * @param buffer  place to put data
277 * @param len     maximum size
278 * @return size   length of the data stored in buffer
279 */
[c301152]280ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
[2e12226]281                                  void *buffer, size_t len);
[7e2b223]282
283/**
[671b64f]284 * mgs_transport_write is called from GnuTLS to
[7e2b223]285 * write data to the client.
286 *
287 * @param ptr     pointer to the filter context
288 * @param buffer  buffer to write to the client
289 * @param len     size of the buffer
290 * @return size   length of the data written
291 */
[c301152]292ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
[2e12226]293                                   const void *buffer, size_t len);
[7e2b223]294
295
[c301152]296int mgs_rehandshake(mgs_handle_t * ctxt);
[e924ddd]297
298
299
[a66e147]300/**
[fcb122d]301 * Init the Cache after Configuration is done
302 */
[671b64f]303int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
[c301152]304                                 mgs_srvconf_rec *sc);
[fcb122d]305/**
[a66e147]306 * Init the Cache inside each Process
307 */
[671b64f]308int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
[c301152]309                                mgs_srvconf_rec *sc);
[a66e147]310/**
311 * Setup the Session Caching
312 */
[c301152]313int mgs_cache_session_init(mgs_handle_t *ctxt);
[05d56ce]314
[42307a9]315#define GNUTLS_SESSION_ID_STRING_LEN \
316    ((GNUTLS_MAX_SESSION_ID + 1) * 2)
[671b64f]317
[42307a9]318/**
319 * Convert a SSL Session ID into a Null Terminated Hex Encoded String
320 * @param id raw SSL Session ID
321 * @param idlen Length of the raw Session ID
322 * @param str Location to store the Hex Encoded String
323 * @param strsize The Maximum Length that can be stored in str
324 */
[c301152]325char *mgs_session_id2sz(unsigned char *id, int idlen,
[42307a9]326                                char *str, int strsize);
327
[7bebb42]328/**
329 * Convert a time_t into a Null Terminated String
330 * @param t time_t time
331 * @param str Location to store the Hex Encoded String
332 * @param strsize The Maximum Length that can be stored in str
333 */
334char *mgs_time2sz(time_t t, char *str, int strsize);
335
[c301152]336
[46b85d8]337/* Configuration Functions */
338
[7bebb42]339const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy,
340                                        const char *arg);
341const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy,
342                                        const char *arg);
343const char *mgs_set_dh_file(cmd_parms * parms, void *dummy,
344                                        const char *arg);
[46b85d8]345const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
346                                        const char *arg);
347
348const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
349                             const char *arg);
350
[e5bbda4]351const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy,
352                                        const char *arg);
353
354const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy,
355                             const char *arg);
356
[46b85d8]357const char *mgs_set_cache(cmd_parms * parms, void *dummy,
358                          const char *type, const char* arg);
359
360const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy,
361                                  const char *arg);
362
363const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
364                                  const char *arg);
365
[cf2b905]366const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy,
367                                         const char *arg);
368
[46b85d8]369const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
370                                   const char *arg);
371
[e5bbda4]372const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy,
373                                   const char *arg);
374
[46b85d8]375const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
376                            const char *arg);
[2aaf4f5]377const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy,
[7bebb42]378                            const char *arg);
379const char *mgs_set_priorities(cmd_parms * parms, void *dummy,
380                            const char *arg);
[ae233c2]381const char *mgs_set_tickets(cmd_parms * parms, void *dummy,
382                            const char *arg);
[671b64f]383
384const char *mgs_set_require_section(cmd_parms *cmd,
[84cb5b2]385                                    void *mconfig, const char *arg);
[46b85d8]386void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
[040387c]387void *mgs_config_server_merge(apr_pool_t *p, void *BASE, void *ADD);
[46b85d8]388
[84cb5b2]389void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
390
[46b85d8]391void *mgs_config_dir_create(apr_pool_t *p, char *dir);
392
[671b64f]393const char *mgs_set_require_bytecode(cmd_parms *cmd,
[84cb5b2]394                                    void *mconfig, const char *arg);
395
[836417f]396mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
[c301152]397
[0de1839]398const char *mgs_store_cred_path(cmd_parms * parms,
399                                void *dummy __attribute__((unused)),
400                                const char *arg);
401
[c301152]402/* mod_gnutls Hooks. */
403
404int mgs_hook_pre_config(apr_pool_t * pconf,
405                        apr_pool_t * plog, apr_pool_t * ptemp);
406
407int mgs_hook_post_config(apr_pool_t * p, apr_pool_t * plog,
408                         apr_pool_t * ptemp,
409                         server_rec * base_server);
410
411void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
412
413const char *mgs_hook_http_scheme(const request_rec * r);
414
415apr_port_t mgs_hook_default_port(const request_rec * r);
416
417int mgs_hook_pre_connection(conn_rec * c, void *csd);
418
419int mgs_hook_fixups(request_rec *r);
420
421int mgs_hook_authz(request_rec *r);
422
[7e2b223]423#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.