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

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

Record if a connection is a proxy connection

When handling a proxy request with TLS in the backend, the proxy server
acts as a TLS client. This requires a different setup of the GnuTLS
session, so we need to add a record to the connection configuration that
states whether it is a proxy backend connection or not.

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