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

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

Update copyright headers

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