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

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

Merge branch 'split-testsuite' into new-gnutls-api

OpenPGP support is still broken, but this will make testing a lot
easier.

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