source: mod_gnutls/include/mod_gnutls.h.in @ 25e6b32

debian/masterdebian/stretch-backportsjessie-backportsmsvaupstream
Last change on this file since 25e6b32 was 25e6b32, checked in by Daniel Kahn Gillmor <dkg@…>, 7 years ago

remove obsolete mgs_handle_t.rsa_params -- RSA-EXPORT is not supported

This change breaks backward compatibility if anyone is trying to link
some other code to mod_gnutls. I don't think that's happening right
now, so I am willing to break backward compatibility to have a cleaner
codebase going forward.

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