source: mod_gnutls/include/mod_gnutls.h.in @ 84cb5b2

debian/masterdebian/stretch-backportsjessie-backportsmsvaupstream
Last change on this file since 84cb5b2 was 84cb5b2, checked in by Paul Querna <chip@…>, 14 years ago
  • add lua to do client verification
  • only use gcrypt locking when required to
  • Property mode set to 100644
File size: 7.6 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#include "httpd.h"
19#include "http_config.h"
20#include "http_protocol.h"
21#include "http_connection.h"
22#include "http_request.h"
23#include "http_core.h"
24#include "http_log.h"
25#include "apr_buckets.h"
26#include "apr_strings.h"
27#include "apr_tables.h"
28#include "ap_release.h"
29
30#include <gcrypt.h>
31#include <gnutls/gnutls.h>
32#include <gnutls/x509.h>
33
34#ifndef __mod_gnutls_h_inc
35#define __mod_gnutls_h_inc
36
37#define HAVE_APR_MEMCACHE    @have_apr_memcache@
38
39module AP_MODULE_DECLARE_DATA gnutls_module;
40
41#define GNUTLS_OUTPUT_FILTER_NAME "gnutls_output_filter"
42#define GNUTLS_INPUT_FILTER_NAME "gnutls_input_filter"
43
44#define GNUTLS_ENABLED_FALSE 0
45#define GNUTLS_ENABLED_TRUE  1
46
47#define MOD_GNUTLS_VERSION "@MOD_GNUTLS_VERSION@"
48
49#define MOD_GNUTLS_DEBUG @OOO_MAINTAIN@
50
51/* Recent Versions of 2.1 renamed several hooks. This allows us to
52   compile on 2.0.xx  */
53#if AP_SERVER_MINORVERSION_NUMBER >= 1
54#if AP_SERVER_PATCHLEVEL_NUMBER >= 3
55#define USING_2_1_RECENT 1
56#endif
57#endif
58
59#ifndef USING_2_1_RECENT
60#define USING_2_1_RECENT 0
61#endif
62
63typedef enum
64{
65    mgs_cache_none,
66    mgs_cache_dbm,
67#if HAVE_APR_MEMCACHE
68    mgs_cache_memcache
69#endif
70} mgs_cache_e;
71
72typedef struct
73{
74    int client_verify_mode;
75    const char* lua_bytecode;
76    apr_size_t lua_bytecode_len;
77} mgs_dirconf_rec;
78
79typedef struct
80{
81    gnutls_certificate_credentials_t certs;
82    char* cert_cn;
83    gnutls_x509_crt_t cert_x509;
84    gnutls_x509_privkey_t privkey_x509;
85    int enabled;
86    int ciphers[16];
87    int key_exchange[16];
88    int macs[16];
89    int protocol[16];
90    int compression[16];
91    int cert_types[16];
92    apr_time_t cache_timeout;
93    mgs_cache_e cache_type;
94    const char* cache_config;
95    const char* rsa_params_file;
96    const char* dh_params_file;
97    int client_verify_mode;
98} mgs_srvconf_rec;
99
100typedef struct {
101    int length;
102    char *value;
103} mgs_char_buffer_t;
104
105typedef struct
106{
107    mgs_srvconf_rec *sc;
108    conn_rec* c;
109    gnutls_session_t session;
110
111    apr_status_t input_rc;
112    ap_filter_t *input_filter;
113    apr_bucket_brigade *input_bb;
114    apr_read_type_e input_block;
115    ap_input_mode_t input_mode;
116    mgs_char_buffer_t input_cbuf;
117    char input_buffer[AP_IOBUFSIZE];
118
119    apr_status_t output_rc;
120    ap_filter_t *output_filter;
121    apr_bucket_brigade *output_bb;
122    char output_buffer[AP_IOBUFSIZE];
123    apr_size_t output_blen;
124    apr_size_t output_length;
125
126    int status;
127    int non_https;
128} mgs_handle_t;
129
130/** Functions in gnutls_io.c **/
131
132/**
133 * mgs_filter_input will filter the input data
134 * by decrypting it using GnuTLS and passes it cleartext.
135 *
136 * @param f     the filter info record
137 * @param bb    the bucket brigade, where to store the result to
138 * @param mode  what shall we read?
139 * @param block a block index we shall read from?
140 * @return result status
141 */
142apr_status_t mgs_filter_input(ap_filter_t * f,
143                                     apr_bucket_brigade * bb,
144                                     ap_input_mode_t mode,
145                                     apr_read_type_e block,
146                                     apr_off_t readbytes);
147
148/**
149 * mgs_filter_output will filter the encrypt
150 * the incoming bucket using GnuTLS and passes it onto the next filter.
151 *
152 * @param f     the filter info record
153 * @param bb    the bucket brigade, where to store the result to
154 * @return result status
155 */
156apr_status_t mgs_filter_output(ap_filter_t * f,
157                                      apr_bucket_brigade * bb);
158
159
160/**
161 * mgs_transport_read is called from GnuTLS to provide encrypted
162 * data from the client.
163 *
164 * @param ptr     pointer to the filter context
165 * @param buffer  place to put data
166 * @param len     maximum size
167 * @return size   length of the data stored in buffer
168 */
169ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr,
170                                  void *buffer, size_t len);
171
172/**
173 * mgs_transport_write is called from GnuTLS to
174 * write data to the client.
175 *
176 * @param ptr     pointer to the filter context
177 * @param buffer  buffer to write to the client
178 * @param len     size of the buffer
179 * @return size   length of the data written
180 */
181ssize_t mgs_transport_write(gnutls_transport_ptr_t ptr,
182                                   const void *buffer, size_t len);
183
184
185int mgs_rehandshake(mgs_handle_t * ctxt);
186
187
188
189/**
190 * Init the Cache after Configuration is done
191 */
192int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
193                                 mgs_srvconf_rec *sc);
194/**
195 * Init the Cache inside each Process
196 */
197int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
198                                mgs_srvconf_rec *sc);
199/**
200 * Setup the Session Caching
201 */
202int mgs_cache_session_init(mgs_handle_t *ctxt);
203
204#define GNUTLS_SESSION_ID_STRING_LEN \
205    ((GNUTLS_MAX_SESSION_ID + 1) * 2)
206   
207/**
208 * Convert a SSL Session ID into a Null Terminated Hex Encoded String
209 * @param id raw SSL Session ID
210 * @param idlen Length of the raw Session ID
211 * @param str Location to store the Hex Encoded String
212 * @param strsize The Maximum Length that can be stored in str
213 */
214char *mgs_session_id2sz(unsigned char *id, int idlen,
215                                char *str, int strsize);
216
217
218/* Configuration Functions */
219
220const char *mgs_set_cert_file(cmd_parms * parms, void *dummy,
221                                        const char *arg);
222
223const char *mgs_set_key_file(cmd_parms * parms, void *dummy,
224                             const char *arg);
225
226const char *mgs_set_cache(cmd_parms * parms, void *dummy,
227                          const char *type, const char* arg);
228
229const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy,
230                                  const char *arg);
231
232const char *mgs_set_client_verify(cmd_parms * parms, void *dummy,
233                                  const char *arg);
234
235const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy,
236                                   const char *arg);
237
238const char *mgs_set_enabled(cmd_parms * parms, void *dummy,
239                            const char *arg);
240                           
241const char *mgs_set_require_section(cmd_parms *cmd,
242                                    void *mconfig, const char *arg);
243void *mgs_config_server_create(apr_pool_t * p, server_rec * s);
244
245void *mgs_config_dir_merge(apr_pool_t *p, void *basev, void *addv);
246
247void *mgs_config_dir_create(apr_pool_t *p, char *dir);
248
249const char *mgs_set_require_bytecode(cmd_parms *cmd,
250                                    void *mconfig, const char *arg);
251
252mgs_srvconf_rec* mgs_find_sni_server(gnutls_session_t session);
253
254/* mod_gnutls Hooks. */
255
256int mgs_hook_pre_config(apr_pool_t * pconf,
257                        apr_pool_t * plog, apr_pool_t * ptemp);
258
259int mgs_hook_post_config(apr_pool_t * p, apr_pool_t * plog,
260                         apr_pool_t * ptemp,
261                         server_rec * base_server);
262
263void mgs_hook_child_init(apr_pool_t *p, server_rec *s);
264
265const char *mgs_hook_http_scheme(const request_rec * r);
266
267apr_port_t mgs_hook_default_port(const request_rec * r);
268
269int mgs_hook_pre_connection(conn_rec * c, void *csd);
270
271int mgs_hook_fixups(request_rec *r);
272
273int mgs_hook_authz(request_rec *r);
274
275int mgs_authz_lua(request_rec* r);
276
277#endif /*  __mod_gnutls_h_inc */
Note: See TracBrowser for help on using the repository browser.