source: mod_gnutls/include/mod_gnutls.h.in @ 3b4c0d0

debian/masterdebian/stretch-backportsjessie-backportsmsvaupstream
Last change on this file since 3b4c0d0 was 3b4c0d0, checked in by Dash Shendy <neuromancer@…>, 7 years ago
  • Added Comments to Header Structures
  • Refactored the following:

mod_gnutls.h.in:

  • struct mgs_srvconf_rec{}

gnutls_config.c:

  • mgs_set_cert_file()
  • mgs_set_key_file()
  • mgs_set_priorities()
  • mgs_config_server_create()

gnutls_hooks.c

  • mgs_hook_pre_config()
  • mgs_select_virtual_server_cb()
  • cert_retrieve_fn()
  • read_crt_cn()
  • mgs_hook_post_config()
  • mgs_find_sni_server()
  • mgs_add_common_cert_vars()
  • mgs_add_common_pgpcert_vars()

Signed-off-by: Dash Shendy <neuromancer@…>

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