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

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

Enable/disable TLS per connection in ssl_engine_disable

Previously, ssl_engine_disable set the server wide variable sc->enabled
to GNUTLS_ENABLED_FALSE, leading to mod_gnutls refusing to serve any
connection, including incoming client connections. The general HTTP
handler cannot process raw TLS traffic, so all further requests using
TLS failed.

This commit adds a new element "enabled" to struct mgs_handle_t, which
is used to disable TLS per connection, making it possible to disable TLS
for proxy back end connections while continuing to serve TLS clients.

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