bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / apache2 / include / mod_ssl.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  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  *  _ __ ___   ___   __| |    ___ ___| |  mod_ssl
19  * | '_ ` _ \ / _ \ / _` |   / __/ __| |  Apache Interface to OpenSSL
20  * | | | | | | (_) | (_| |   \__ \__ \ |
21  * |_| |_| |_|\___/ \__,_|___|___/___/_|
22  *                      |_____|
23  *  mod_ssl.h
24  *  Global header
25  */
26                              /* ``The Apache Group: a collection
27                                   of talented individuals who are
28                                   trying to perfect the art of
29                                   never finishing something.''
30                                              -- Rob Hartill         */
31 #ifndef __MOD_SSL_H__
32 #define __MOD_SSL_H__
33
34 /* 
35  * Optionally enable the experimental stuff, but allow the user to
36  * override the decision which experimental parts are included by using
37  * CFLAGS="-DSSL_EXPERIMENTAL_xxxx_IGNORE".
38  */
39 #ifdef SSL_EXPERIMENTAL
40 #ifdef SSL_ENGINE
41 #ifndef SSL_EXPERIMENTAL_ENGINE_IGNORE
42 #define SSL_EXPERIMENTAL_ENGINE
43 #endif
44 #endif
45 #endif /* SSL_EXPERIMENTAL */
46
47 /*
48  * Power up our brain...
49  */
50
51 /* Apache headers */
52 #include "httpd.h"
53 #include "http_config.h"
54 #include "http_core.h"
55 #include "http_log.h"
56 #include "http_main.h"
57 #include "http_connection.h"
58 #include "http_request.h"
59 #include "http_protocol.h"
60 #include "util_script.h"
61 #include "util_filter.h"
62 #include "mpm.h"
63 #include "apr.h"
64 #include "apr_strings.h"
65 #define APR_WANT_STRFUNC
66 #include "apr_want.h"
67 #include "apr_tables.h"
68 #include "apr_lib.h"
69 #include "apr_fnmatch.h"
70 #include "apr_strings.h"
71 #include "apr_dbm.h"
72 #include "apr_rmm.h"
73 #include "apr_shm.h"
74 #include "apr_global_mutex.h"
75 #include "apr_optional.h"
76
77 #define MOD_SSL_VERSION AP_SERVER_BASEREVISION
78
79 #ifdef HAVE_SSLC
80   
81 #include <bio.h>
82 #include <ssl.h>
83 #include <err.h>
84 #include <x509.h>
85 #include <pem.h>
86 #include <evp.h>
87 #include <objects.h>
88 #include <sslc.h>
89
90 #else /* !HAVE_SSLC (implicit HAVE_OPENSSL) */
91
92 #include <ssl.h>
93 #include <err.h>
94 #include <x509.h>
95 #include <pem.h>
96 #include <crypto.h>
97 #include <evp.h>
98 #include <rand.h>
99 #ifdef SSL_EXPERIMENTAL_ENGINE
100 #include <engine.h>
101 #endif
102 #ifdef HAVE_SSL_X509V3_H
103 #include <x509v3.h>
104 #endif
105
106 #endif /* !HAVE_SSLC (implicit HAVE_OPENSSL) */
107
108
109 /* mod_ssl headers */
110 #include "ssl_toolkit_compat.h"
111 #include "ssl_expr.h"
112 #include "ssl_util_ssl.h"
113 #include "ssl_util_table.h"
114
115 /* The #ifdef macros are only defined AFTER including the above
116  * therefore we cannot include these system files at the top  :-(
117  */
118 #if APR_HAVE_SYS_TIME_H
119 #include <sys/time.h>
120 #endif
121 #if APR_HAVE_UNISTD_H
122 #include <unistd.h> /* needed for STDIN_FILENO et.al., at least on FreeBSD */
123 #endif
124
125 /*
126  * Provide reasonable default for some defines
127  */
128 #ifndef FALSE
129 #define FALSE (0)
130 #endif
131 #ifndef TRUE
132 #define TRUE (!FALSE)
133 #endif
134 #ifndef PFALSE
135 #define PFALSE ((void *)FALSE)
136 #endif
137 #ifndef PTRUE
138 #define PTRUE ((void *)TRUE)
139 #endif
140 #ifndef UNSET
141 #define UNSET (-1)
142 #endif
143 #ifndef NUL
144 #define NUL '\0'
145 #endif
146 #ifndef RAND_MAX
147 #include <limits.h>
148 #define RAND_MAX INT_MAX
149 #endif
150
151 /*
152  * Provide reasonable defines for some types
153  */
154 #ifndef BOOL
155 #define BOOL unsigned int
156 #endif
157 #ifndef UCHAR
158 #define UCHAR unsigned char
159 #endif
160
161 /*
162  * Provide useful shorthands
163  */
164 #define strEQ(s1,s2)     (strcmp(s1,s2)        == 0)
165 #define strNE(s1,s2)     (strcmp(s1,s2)        != 0)
166 #define strEQn(s1,s2,n)  (strncmp(s1,s2,n)     == 0)
167 #define strNEn(s1,s2,n)  (strncmp(s1,s2,n)     != 0)
168
169 #define strcEQ(s1,s2)    (strcasecmp(s1,s2)    == 0)
170 #define strcNE(s1,s2)    (strcasecmp(s1,s2)    != 0)
171 #define strcEQn(s1,s2,n) (strncasecmp(s1,s2,n) == 0)
172 #define strcNEn(s1,s2,n) (strncasecmp(s1,s2,n) != 0)
173
174 #define strIsEmpty(s)    (s == NULL || s[0] == NUL)
175
176 #define myConnConfig(c) \
177 (SSLConnRec *)ap_get_module_config(c->conn_config, &ssl_module)
178 #define myCtxConfig(sslconn, sc) (sslconn->is_proxy ? sc->proxy : sc->server)
179 #define myConnConfigSet(c, val) \
180 ap_set_module_config(c->conn_config, &ssl_module, val)
181 #define mySrvConfig(srv) (SSLSrvConfigRec *)ap_get_module_config(srv->module_config,  &ssl_module)
182 #define myDirConfig(req) (SSLDirConfigRec *)ap_get_module_config(req->per_dir_config, &ssl_module)
183 #define myModConfig(srv) (mySrvConfig((srv)))->mc
184
185 #define myCtxVarSet(mc,num,val)  mc->rCtx.pV##num = val
186 #define myCtxVarGet(mc,num,type) (type)(mc->rCtx.pV##num)
187
188 /*
189  * Defaults for the configuration
190  */
191 #ifndef SSL_SESSION_CACHE_TIMEOUT
192 #define SSL_SESSION_CACHE_TIMEOUT  300
193 #endif
194
195 /*
196  * Support for MM library
197  */
198 #define SSL_MM_FILE_MODE ( APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD )
199
200 /*
201  * Support for DBM library
202  */
203 #define SSL_DBM_FILE_MODE ( APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD )
204
205 #if !defined(SSL_DBM_FILE_SUFFIX_DIR) && !defined(SSL_DBM_FILE_SUFFIX_PAG)
206 #if defined(DBM_SUFFIX)
207 #define SSL_DBM_FILE_SUFFIX_DIR DBM_SUFFIX
208 #define SSL_DBM_FILE_SUFFIX_PAG DBM_SUFFIX
209 #elif defined(__FreeBSD__) || (defined(DB_LOCK) && defined(DB_SHMEM))
210 #define SSL_DBM_FILE_SUFFIX_DIR ".db"
211 #define SSL_DBM_FILE_SUFFIX_PAG ".db"
212 #else
213 #define SSL_DBM_FILE_SUFFIX_DIR ".dir"
214 #define SSL_DBM_FILE_SUFFIX_PAG ".pag"
215 #endif
216 #endif
217
218 /*
219  * Define the certificate algorithm types
220  */
221
222 typedef int ssl_algo_t;
223
224 #define SSL_ALGO_UNKNOWN (0)
225 #define SSL_ALGO_RSA     (1<<0)
226 #define SSL_ALGO_DSA     (1<<1)
227 #define SSL_ALGO_ALL     (SSL_ALGO_RSA|SSL_ALGO_DSA)
228
229 #define SSL_AIDX_RSA     (0)
230 #define SSL_AIDX_DSA     (1)
231 #define SSL_AIDX_MAX     (2)
232
233
234 /*
235  * Define IDs for the temporary RSA keys and DH params
236  */
237
238 #define SSL_TMP_KEY_RSA_512  (0)
239 #define SSL_TMP_KEY_RSA_1024 (1)
240 #define SSL_TMP_KEY_DH_512   (2)
241 #define SSL_TMP_KEY_DH_1024  (3)
242 #define SSL_TMP_KEY_MAX      (4)
243
244 /*
245  * Define the SSL options
246  */
247 #define SSL_OPT_NONE           (0)
248 #define SSL_OPT_RELSET         (1<<0)
249 #define SSL_OPT_STDENVVARS     (1<<1)
250 #define SSL_OPT_COMPATENVVARS  (1<<2)
251 #define SSL_OPT_EXPORTCERTDATA (1<<3)
252 #define SSL_OPT_FAKEBASICAUTH  (1<<4)
253 #define SSL_OPT_STRICTREQUIRE  (1<<5)
254 #define SSL_OPT_OPTRENEGOTIATE (1<<6)
255 #define SSL_OPT_ALL            (SSL_OPT_STDENVVARS|SSL_OPT_COMPATENVVAR|SSL_OPT_EXPORTCERTDATA|SSL_OPT_FAKEBASICAUTH|SSL_OPT_STRICTREQUIRE|SSL_OPT_OPTRENEGOTIATE)
256 typedef int ssl_opt_t;
257
258 /*
259  * Define the SSL Protocol options
260  */
261 #define SSL_PROTOCOL_NONE  (0)
262 #define SSL_PROTOCOL_SSLV2 (1<<0)
263 #define SSL_PROTOCOL_SSLV3 (1<<1)
264 #define SSL_PROTOCOL_TLSV1 (1<<2)
265 #define SSL_PROTOCOL_ALL   (SSL_PROTOCOL_SSLV2|SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1)
266 typedef int ssl_proto_t;
267
268 /*
269  * Define the SSL verify levels
270  */
271 typedef enum {
272     SSL_CVERIFY_UNSET           = UNSET,
273     SSL_CVERIFY_NONE            = 0,
274     SSL_CVERIFY_OPTIONAL        = 1,
275     SSL_CVERIFY_REQUIRE         = 2,
276     SSL_CVERIFY_OPTIONAL_NO_CA  = 3
277 } ssl_verify_t;
278
279 #define SSL_VERIFY_PEER_STRICT \
280      (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
281
282 #ifndef X509_V_ERR_CERT_UNTRUSTED
283 #define X509_V_ERR_CERT_UNTRUSTED 27
284 #endif
285
286 #define ssl_verify_error_is_optional(errnum) \
287    ((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) \
288     || (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
289     || (errnum == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) \
290     || (errnum == X509_V_ERR_CERT_UNTRUSTED) \
291     || (errnum == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
292
293 /*
294  * Define the SSL pass phrase dialog types
295  */
296 typedef enum {
297     SSL_PPTYPE_UNSET   = UNSET,
298     SSL_PPTYPE_BUILTIN = 0,
299     SSL_PPTYPE_FILTER  = 1,
300         SSL_PPTYPE_PIPE    = 2
301 } ssl_pphrase_t;
302
303 /*
304  * Define the Path Checking modes
305  */
306 #define SSL_PCM_EXISTS     1
307 #define SSL_PCM_ISREG      2
308 #define SSL_PCM_ISDIR      4
309 #define SSL_PCM_ISNONZERO  8
310 typedef unsigned int ssl_pathcheck_t;
311
312 /*
313  * Define the SSL session cache modes and structures
314  */
315 typedef enum {
316     SSL_SCMODE_UNSET = UNSET,
317     SSL_SCMODE_NONE  = 0,
318     SSL_SCMODE_DBM   = 1,
319     SSL_SCMODE_SHMHT = 2,
320     SSL_SCMODE_SHMCB = 3
321 } ssl_scmode_t;
322
323 /*
324  * Define the SSL mutex modes
325  */
326 typedef enum {
327     SSL_MUTEXMODE_UNSET  = UNSET,
328     SSL_MUTEXMODE_NONE   = 0,
329     SSL_MUTEXMODE_USED   = 1
330 } ssl_mutexmode_t;
331
332 /*
333  * Define the SSL requirement structure
334  */
335 typedef struct {
336     char     *cpExpr;
337     ssl_expr *mpExpr;
338 } ssl_require_t;
339
340 /*
341  * Define the SSL random number generator seeding source
342  */
343 typedef enum {
344     SSL_RSCTX_STARTUP = 1,
345     SSL_RSCTX_CONNECT = 2
346 } ssl_rsctx_t;
347 typedef enum {
348     SSL_RSSRC_BUILTIN = 1,
349     SSL_RSSRC_FILE    = 2,
350     SSL_RSSRC_EXEC    = 3,
351     SSL_RSSRC_EGD     = 4
352 } ssl_rssrc_t;
353 typedef struct {
354     ssl_rsctx_t  nCtx;
355     ssl_rssrc_t  nSrc;
356     char        *cpPath;
357     int          nBytes;
358 } ssl_randseed_t;
359
360 /*
361  * Define the structure of an ASN.1 anything
362  */
363 typedef struct {
364     long int       nData;
365     unsigned char *cpData;
366     apr_time_t     source_mtime;
367 } ssl_asn1_t;
368
369 /*
370  * Define the mod_ssl per-module configuration structure
371  * (i.e. the global configuration for each httpd process)
372  */
373
374 typedef enum {
375     SSL_SHUTDOWN_TYPE_UNSET,
376     SSL_SHUTDOWN_TYPE_STANDARD,
377     SSL_SHUTDOWN_TYPE_UNCLEAN,
378     SSL_SHUTDOWN_TYPE_ACCURATE
379 } ssl_shutdown_type_e;
380
381 typedef struct {
382     SSL *ssl;
383     const char *client_dn;
384     X509 *client_cert;
385     ssl_shutdown_type_e shutdown_type;
386     const char *verify_info;
387     const char *verify_error;
388     int verify_depth;
389     int is_proxy;
390     int disabled;
391     int non_ssl_request;
392
393     /* Track the handshake/renegotiation state for the connection so
394      * that all client-initiated renegotiations can be rejected, as a
395      * partial fix for CVE-2009-3555. */
396     enum {
397         RENEG_INIT = 0, /* Before initial handshake */
398         RENEG_REJECT, /* After initial handshake; any client-initiated
399                        * renegotiation should be rejected */
400         RENEG_ALLOW, /* A server-initated renegotiation is taking
401                       * place (as dictated by configuration) */
402         RENEG_ABORT /* Renegotiation initiated by client, abort the
403                      * connection */
404     } reneg_state;
405 } SSLConnRec;
406
407 typedef struct {
408     pid_t           pid;
409     apr_pool_t     *pPool;
410     BOOL            bFixed;
411     int             nSessionCacheMode;
412     char           *szSessionCacheDataFile;
413     int             nSessionCacheDataSize;
414     apr_shm_t      *pSessionCacheDataMM;
415     apr_rmm_t      *pSessionCacheDataRMM;
416     apr_table_t    *tSessionCacheDataTable;
417     ssl_mutexmode_t nMutexMode;
418     apr_lockmech_e  nMutexMech;
419     const char     *szMutexFile;
420     apr_global_mutex_t   *pMutex;
421     apr_array_header_t   *aRandSeed;
422     apr_hash_t     *tVHostKeys;
423     void           *pTmpKeys[SSL_TMP_KEY_MAX];
424     apr_hash_t     *tPublicCert;
425     apr_hash_t     *tPrivateKey;
426 #ifdef SSL_EXPERIMENTAL_ENGINE
427     char           *szCryptoDevice;
428 #endif
429     struct {
430         void *pV1, *pV2, *pV3, *pV4, *pV5, *pV6, *pV7, *pV8, *pV9, *pV10;
431     } rCtx;
432 } SSLModConfigRec;
433
434 /* public cert/private key */
435 typedef struct {
436     /* 
437      * server only has 1-2 certs/keys
438      * 1 RSA and/or 1 DSA
439      */
440     const char  *cert_files[SSL_AIDX_MAX];
441     const char  *key_files[SSL_AIDX_MAX];
442     X509        *certs[SSL_AIDX_MAX];
443     EVP_PKEY    *keys[SSL_AIDX_MAX];
444 } modssl_pk_server_t;
445
446 typedef struct {
447     /* proxy can have any number of cert/key pairs */
448     const char  *cert_file;
449     const char  *cert_path;
450     STACK_OF(X509_INFO) *certs;
451 } modssl_pk_proxy_t;
452
453 /* stuff related to authentication that can also be per-dir */
454 typedef struct {
455     /* known/trusted CAs */
456     const char  *ca_cert_path;
457     const char  *ca_cert_file;
458
459     const char  *cipher_suite;
460
461     /* for client or downstream server authentication */
462     int          verify_depth;
463     ssl_verify_t verify_mode;
464 } modssl_auth_ctx_t;
465
466 typedef struct SSLSrvConfigRec SSLSrvConfigRec;
467
468 typedef struct {
469     SSLSrvConfigRec *sc; /* pointer back to server config */
470     SSL_CTX *ssl_ctx;
471
472     /* we are one or the other */
473     modssl_pk_server_t *pks;
474     modssl_pk_proxy_t  *pkp;
475
476     ssl_proto_t  protocol;
477
478     /* config for handling encrypted keys */
479     ssl_pphrase_t pphrase_dialog_type;
480     const char   *pphrase_dialog_path;
481
482     const char  *cert_chain;
483
484     /* certificate revocation list */
485     const char  *crl_path;
486     const char  *crl_file;
487     X509_STORE  *crl;
488
489     modssl_auth_ctx_t auth;
490 } modssl_ctx_t;
491
492 struct SSLSrvConfigRec {
493     SSLModConfigRec *mc;
494     BOOL             enabled;
495     BOOL             proxy_enabled;
496     const char      *vhost_id;
497     int              vhost_id_len;
498     int              session_cache_timeout;
499     BOOL             insecure_reneg;
500     modssl_ctx_t    *server;
501     modssl_ctx_t    *proxy;
502 };
503
504 /*
505  * Define the mod_ssl per-directory configuration structure
506  * (i.e. the local configuration for all <Directory>
507  *  and .htaccess contexts)
508  */
509 typedef struct {
510     BOOL          bSSLRequired;
511     apr_array_header_t *aRequirement;
512     ssl_opt_t     nOptions;
513     ssl_opt_t     nOptionsAdd;
514     ssl_opt_t     nOptionsDel;
515     const char   *szCipherSuite;
516     ssl_verify_t  nVerifyClient;
517     int           nVerifyDepth;
518     const char   *szCACertificatePath;
519     const char   *szCACertificateFile;
520     const char   *szUserName;
521 } SSLDirConfigRec;
522
523 /*
524  *  function prototypes
525  */
526
527 /*  API glue structures  */
528 extern module AP_MODULE_DECLARE_DATA ssl_module;
529
530 /* "global" stuff */
531 extern const char ssl_valid_ssl_mutex_string[];
532
533 /*  configuration handling   */
534 SSLModConfigRec *ssl_config_global_create(server_rec *);
535 void         ssl_config_global_fix(SSLModConfigRec *);
536 BOOL         ssl_config_global_isfixed(SSLModConfigRec *);
537 void        *ssl_config_server_create(apr_pool_t *, server_rec *);
538 void        *ssl_config_server_merge(apr_pool_t *, void *, void *);
539 void        *ssl_config_perdir_create(apr_pool_t *, char *);
540 void        *ssl_config_perdir_merge(apr_pool_t *, void *, void *);
541 const char  *ssl_cmd_SSLMutex(cmd_parms *, void *, const char *);
542 const char  *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, void *, const char *);
543 const char  *ssl_cmd_SSLCryptoDevice(cmd_parms *, void *, const char *);
544 const char  *ssl_cmd_SSLRandomSeed(cmd_parms *, void *, const char *, const char *, const char *);
545 const char  *ssl_cmd_SSLEngine(cmd_parms *, void *, int);
546 const char  *ssl_cmd_SSLCipherSuite(cmd_parms *, void *, const char *);
547 const char  *ssl_cmd_SSLCertificateFile(cmd_parms *, void *, const char *);
548 const char  *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, void *, const char *);
549 const char  *ssl_cmd_SSLCertificateChainFile(cmd_parms *, void *, const char *);
550 const char  *ssl_cmd_SSLCACertificatePath(cmd_parms *, void *, const char *);
551 const char  *ssl_cmd_SSLCACertificateFile(cmd_parms *, void *, const char *);
552 const char  *ssl_cmd_SSLCARevocationPath(cmd_parms *, void *, const char *);
553 const char  *ssl_cmd_SSLCARevocationFile(cmd_parms *, void *, const char *);
554 const char  *ssl_cmd_SSLVerifyClient(cmd_parms *, void *, const char *);
555 const char  *ssl_cmd_SSLVerifyDepth(cmd_parms *, void *, const char *);
556 const char  *ssl_cmd_SSLSessionCache(cmd_parms *, void *, const char *);
557 const char  *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, void *, const char *);
558 const char  *ssl_cmd_SSLProtocol(cmd_parms *, void *, const char *);
559 const char  *ssl_cmd_SSLOptions(cmd_parms *, void *, const char *);
560 const char  *ssl_cmd_SSLRequireSSL(cmd_parms *, void *);
561 const char  *ssl_cmd_SSLRequire(cmd_parms *, void *, const char *);
562 const char  *ssl_cmd_SSLUserName(cmd_parms *, void *, const char *);
563 const char  *ssl_cmd_SSLInsecureRenegotiation(cmd_parms *cmd, void *dcfg, int flag);
564
565 const char *ssl_cmd_SSLProxyEngine(cmd_parms *cmd, void *dcfg, int flag);
566 const char  *ssl_cmd_SSLProxyProtocol(cmd_parms *, void *, const char *);
567 const char  *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, void *, const char *);
568 const char  *ssl_cmd_SSLProxyVerify(cmd_parms *, void *, const char *);
569 const char  *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, void *, const char *);
570 const char  *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, void *, const char *);
571 const char  *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, void *, const char *);
572 const char  *ssl_cmd_SSLProxyCARevocationPath(cmd_parms *, void *, const char *);
573 const char  *ssl_cmd_SSLProxyCARevocationFile(cmd_parms *, void *, const char *);
574 const char  *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
575 const char  *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
576
577 /*  module initialization  */
578 int          ssl_init_Module(apr_pool_t *, apr_pool_t *, apr_pool_t *, server_rec *);
579 void         ssl_init_Engine(server_rec *, apr_pool_t *);
580 void         ssl_init_ConfigureServer(server_rec *, apr_pool_t *, apr_pool_t *, SSLSrvConfigRec *);
581 void         ssl_init_CheckServers(server_rec *, apr_pool_t *);
582 STACK_OF(X509_NAME) 
583             *ssl_init_FindCAList(server_rec *, apr_pool_t *, const char *, const char *);
584 void         ssl_init_Child(apr_pool_t *, server_rec *);
585 apr_status_t ssl_init_ModuleKill(void *data);
586
587 /*  Apache API hooks  */
588 int          ssl_hook_Auth(request_rec *);
589 int          ssl_hook_UserCheck(request_rec *);
590 int          ssl_hook_Access(request_rec *);
591 int          ssl_hook_Fixup(request_rec *);
592 int          ssl_hook_ReadReq(request_rec *);
593
594 /*  OpenSSL callbacks */
595 RSA         *ssl_callback_TmpRSA(SSL *, int, int);
596 DH          *ssl_callback_TmpDH(SSL *, int, int);
597 int          ssl_callback_SSLVerify(int, X509_STORE_CTX *);
598 int          ssl_callback_SSLVerify_CRL(int, X509_STORE_CTX *, conn_rec *);
599 int          ssl_callback_proxy_cert(SSL *ssl, MODSSL_CLIENT_CERT_CB_ARG_TYPE **x509, EVP_PKEY **pkey);
600 int          ssl_callback_NewSessionCacheEntry(SSL *, SSL_SESSION *);
601 SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *, unsigned char *, int, int *);
602 void         ssl_callback_DelSessionCacheEntry(SSL_CTX *, SSL_SESSION *);
603 void         ssl_callback_Info(MODSSL_INFO_CB_ARG_TYPE, int, int);
604
605 /*  Session Cache Support  */
606 void         ssl_scache_init(server_rec *, apr_pool_t *);
607 #if 0 /* XXX */
608 void         ssl_scache_status_register(apr_pool_t *p);
609 #endif
610 void         ssl_scache_kill(server_rec *);
611 BOOL         ssl_scache_store(server_rec *, UCHAR *, int, time_t, SSL_SESSION *);
612 SSL_SESSION *ssl_scache_retrieve(server_rec *, UCHAR *, int);
613 void         ssl_scache_remove(server_rec *, UCHAR *, int);
614 void         ssl_scache_expire(server_rec *);
615 void         ssl_scache_status(server_rec *, apr_pool_t *, void (*)(char *, void *), void *);
616 char        *ssl_scache_id2sz(UCHAR *, int);
617 void         ssl_scache_dbm_init(server_rec *, apr_pool_t *);
618 void         ssl_scache_dbm_kill(server_rec *);
619 BOOL         ssl_scache_dbm_store(server_rec *, UCHAR *, int, time_t, SSL_SESSION *);
620 SSL_SESSION *ssl_scache_dbm_retrieve(server_rec *, UCHAR *, int);
621 void         ssl_scache_dbm_remove(server_rec *, UCHAR *, int);
622 void         ssl_scache_dbm_expire(server_rec *);
623 void         ssl_scache_dbm_status(server_rec *, apr_pool_t *, void (*)(char *, void *), void *);
624
625 void         ssl_scache_shmht_init(server_rec *, apr_pool_t *);
626 void         ssl_scache_shmht_kill(server_rec *);
627 BOOL         ssl_scache_shmht_store(server_rec *, UCHAR *, int, time_t, SSL_SESSION *);
628 SSL_SESSION *ssl_scache_shmht_retrieve(server_rec *, UCHAR *, int);
629 void         ssl_scache_shmht_remove(server_rec *, UCHAR *, int);
630 void         ssl_scache_shmht_expire(server_rec *);
631 void         ssl_scache_shmht_status(server_rec *, apr_pool_t *, void (*)(char *, void *), void *);
632
633 void         ssl_scache_shmcb_init(server_rec *, apr_pool_t *);
634 void         ssl_scache_shmcb_kill(server_rec *);
635 BOOL         ssl_scache_shmcb_store(server_rec *, UCHAR *, int, time_t, SSL_SESSION *);
636 SSL_SESSION *ssl_scache_shmcb_retrieve(server_rec *, UCHAR *, int);
637 void         ssl_scache_shmcb_remove(server_rec *, UCHAR *, int);
638 void         ssl_scache_shmcb_expire(server_rec *);
639 void         ssl_scache_shmcb_status(server_rec *, apr_pool_t *, void (*)(char *, void *), void *);
640
641 /*  Pass Phrase Support  */
642 void         ssl_pphrase_Handle(server_rec *, apr_pool_t *);
643
644 /*  Diffie-Hellman Parameter Support  */
645 DH           *ssl_dh_GetTmpParam(int);
646 DH           *ssl_dh_GetParamFromFile(char *);
647
648 unsigned char *ssl_asn1_table_set(apr_hash_t *table,
649                                   const char *key,
650                                   long int length);
651
652 ssl_asn1_t *ssl_asn1_table_get(apr_hash_t *table,
653                                const char *key);
654
655 void ssl_asn1_table_unset(apr_hash_t *table,
656                           const char *key);
657
658 const char *ssl_asn1_keystr(int keytype);
659
660 const char *ssl_asn1_table_keyfmt(apr_pool_t *p,
661                                   const char *id,
662                                   int keytype);
663 /*  Mutex Support  */
664 int          ssl_mutex_init(server_rec *, apr_pool_t *);
665 int          ssl_mutex_reinit(server_rec *, apr_pool_t *);
666 int          ssl_mutex_on(server_rec *);
667 int          ssl_mutex_off(server_rec *);
668
669 /*  Logfile Support  */
670 void         ssl_die(void);
671 void         ssl_log_ssl_error(const char *, int, int, server_rec *);
672
673 /*  Variables  */
674 void         ssl_var_register(void);
675 char        *ssl_var_lookup(apr_pool_t *, server_rec *, conn_rec *, request_rec *, char *);
676 void         ssl_var_log_config_register(apr_pool_t *p);
677
678 APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
679                         (apr_pool_t *, server_rec *,
680                          conn_rec *, request_rec *,
681                          char *));
682
683 /* An optional function which returns non-zero if the given connection
684  * is using SSL/TLS. */
685 APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
686
687 /* Proxy Support */
688 int ssl_proxy_enable(conn_rec *c);
689 int ssl_engine_disable(conn_rec *c);
690
691 APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
692
693 APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
694
695 /*  I/O  */
696 void         ssl_io_filter_init(conn_rec *, SSL *);
697 void         ssl_io_filter_register(apr_pool_t *);
698 long         ssl_io_data_cb(BIO *, int, MODSSL_BIO_CB_ARG_TYPE *, int, long, long);
699
700 /* ssl_io_buffer_fill fills the setaside buffering of the HTTP request
701   * to allow an SSL renegotiation to take place. */
702 int          ssl_io_buffer_fill(request_rec *r);
703
704 /*  PRNG  */
705 int          ssl_rand_seed(server_rec *, apr_pool_t *, ssl_rsctx_t, char *);
706
707 /*  Utility Functions  */
708 char        *ssl_util_vhostid(apr_pool_t *, server_rec *);
709 void         ssl_util_strupper(char *);
710 void         ssl_util_uuencode(char *, const char *, BOOL);
711 void         ssl_util_uuencode_binary(unsigned char *, const unsigned char *, int, BOOL);
712 apr_file_t  *ssl_util_ppopen(server_rec *, apr_pool_t *, const char *,
713                              const char * const *);
714 void         ssl_util_ppclose(server_rec *, apr_pool_t *, apr_file_t *);
715 char        *ssl_util_readfilter(server_rec *, apr_pool_t *, const char *,
716                                  const char * const *);
717 BOOL         ssl_util_path_check(ssl_pathcheck_t, const char *, apr_pool_t *);
718 ssl_algo_t   ssl_util_algotypeof(X509 *, EVP_PKEY *); 
719 char        *ssl_util_algotypestr(ssl_algo_t);
720 char        *ssl_util_ptxtsub(apr_pool_t *, const char *, const char *, char *);
721 void         ssl_util_thread_setup(apr_pool_t *);
722
723 #define APR_SHM_MAXSIZE (64 * 1024 * 1024)
724 #endif /* __MOD_SSL_H__ */