]> granicus.if.org Git - apache/blob - modules/ssl/ssl_private.h
drop SSLv2 support (set SSL_OP_NO_SSLv2 for any new SSL_CTX)
[apache] / modules / ssl / ssl_private.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 #ifndef SSL_PRIVATE_H
18 #define SSL_PRIVATE_H
19
20 /**
21  * @file  ssl_private.h
22  * @brief Internal interfaces private to mod_ssl.
23  *
24  * @defgroup MOD_SSL_PRIVATE Private
25  * @ingroup MOD_SSL
26  * @{
27  */
28
29 /** Apache headers */
30 #include "httpd.h"
31 #include "http_config.h"
32 #include "http_core.h"
33 #include "http_log.h"
34 #include "http_main.h"
35 #include "http_connection.h"
36 #include "http_request.h"
37 #include "http_protocol.h"
38 #include "http_vhost.h"
39 #include "util_script.h"
40 #include "util_filter.h"
41 #include "util_ebcdic.h"
42 #include "util_mutex.h"
43 #include "apr.h"
44 #include "apr_strings.h"
45 #define APR_WANT_STRFUNC
46 #define APR_WANT_MEMFUNC
47 #include "apr_want.h"
48 #include "apr_tables.h"
49 #include "apr_lib.h"
50 #include "apr_fnmatch.h"
51 #include "apr_strings.h"
52 #include "apr_global_mutex.h"
53 #include "apr_optional.h"
54 #include "ap_socache.h"
55 #include "mod_auth.h"
56
57 /* The #ifdef macros are only defined AFTER including the above
58  * therefore we cannot include these system files at the top  :-(
59  */
60 #ifdef APR_HAVE_STDLIB_H
61 #include <stdlib.h>
62 #endif
63 #if APR_HAVE_SYS_TIME_H
64 #include <sys/time.h>
65 #endif
66 #if APR_HAVE_UNISTD_H
67 #include <unistd.h> /* needed for STDIN_FILENO et.al., at least on FreeBSD */
68 #endif
69
70 #ifndef FALSE
71 #define FALSE 0
72 #endif
73
74 #ifndef TRUE
75 #define TRUE !FALSE
76 #endif
77
78 #ifndef BOOL
79 #define BOOL unsigned int
80 #endif
81
82 #include "ap_expr.h"
83
84 /* OpenSSL headers */
85 #include <openssl/ssl.h>
86 #include <openssl/err.h>
87 #include <openssl/x509.h>
88 #include <openssl/pem.h>
89 #include <openssl/crypto.h>
90 #include <openssl/evp.h>
91 #include <openssl/rand.h>
92 #include <openssl/x509v3.h>
93 #include <openssl/x509_vfy.h>
94 #include <openssl/ocsp.h>
95
96 /* Avoid tripping over an engine build installed globally and detected
97  * when the user points at an explicit non-engine flavor of OpenSSL
98  */
99 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
100 #include <openssl/engine.h>
101 #endif
102
103 #if (OPENSSL_VERSION_NUMBER < 0x0090700f)
104 #error mod_ssl requires OpenSSL 0.9.7 or later
105 #endif
106
107 /* ...shifting sands of OpenSSL... */
108 #if (OPENSSL_VERSION_NUMBER >= 0x0090707f)
109 #define MODSSL_D2I_SSL_SESSION_CONST const
110 #else
111 #define MODSSL_D2I_SSL_SESSION_CONST
112 #endif
113
114 #if (OPENSSL_VERSION_NUMBER >= 0x00908000)
115 #define HAVE_GENERATE_EX
116 #define MODSSL_D2I_ASN1_type_bytes_CONST const
117 #define MODSSL_D2I_PrivateKey_CONST const
118 #define MODSSL_D2I_X509_CONST const
119 #else
120 #define MODSSL_D2I_ASN1_type_bytes_CONST
121 #define MODSSL_D2I_PrivateKey_CONST
122 #define MODSSL_D2I_X509_CONST
123 #endif
124
125 #if OPENSSL_VERSION_NUMBER >= 0x00908080 && !defined(OPENSSL_NO_OCSP) \
126     && !defined(OPENSSL_NO_TLSEXT)
127 #define HAVE_OCSP_STAPLING
128 #if (OPENSSL_VERSION_NUMBER < 0x10000000)
129 #define sk_OPENSSL_STRING_pop sk_pop
130 #endif
131 #endif
132
133 #if (OPENSSL_VERSION_NUMBER >= 0x009080a0) && defined(OPENSSL_FIPS)
134 #define HAVE_FIPS
135 #endif
136
137 #if (OPENSSL_VERSION_NUMBER >= 0x10000000)
138 #define MODSSL_SSL_CIPHER_CONST const
139 #define MODSSL_SSL_METHOD_CONST const
140 #else
141 #define MODSSL_SSL_CIPHER_CONST
142 #define MODSSL_SSL_METHOD_CONST
143 /* ECC support came along in OpenSSL 1.0.0 */
144 #define OPENSSL_NO_EC
145 #endif
146
147 #ifndef PEM_F_DEF_CALLBACK
148 #ifdef PEM_F_PEM_DEF_CALLBACK
149 /** In OpenSSL 0.9.8 PEM_F_DEF_CALLBACK was renamed */
150 #define PEM_F_DEF_CALLBACK PEM_F_PEM_DEF_CALLBACK
151 #endif
152 #endif
153
154 #ifndef OPENSSL_NO_TLSEXT
155 #ifndef SSL_CTRL_SET_TLSEXT_HOSTNAME
156 #define OPENSSL_NO_TLSEXT
157 #endif
158 #endif
159
160 #ifndef OPENSSL_NO_TLSEXT
161 #ifdef SSL_CTX_set_tlsext_ticket_key_cb
162 #define HAVE_TLSEXT_TICKETS
163 #endif
164 #endif
165
166 /* mod_ssl headers */
167 #include "ssl_util_ssl.h"
168
169 APLOG_USE_MODULE(ssl);
170
171 /*
172  * Provide reasonable default for some defines
173  */
174 #ifndef PFALSE
175 #define PFALSE ((void *)FALSE)
176 #endif
177 #ifndef PTRUE
178 #define PTRUE ((void *)TRUE)
179 #endif
180 #ifndef UNSET
181 #define UNSET (-1)
182 #endif
183 #ifndef NUL
184 #define NUL '\0'
185 #endif
186 #ifndef RAND_MAX
187 #include <limits.h>
188 #define RAND_MAX INT_MAX
189 #endif
190
191 /**
192  * Provide reasonable defines for some types
193  */
194 #ifndef UCHAR
195 #define UCHAR unsigned char
196 #endif
197
198 /**
199  * Provide useful shorthands
200  */
201 #define strEQ(s1,s2)     (strcmp(s1,s2)        == 0)
202 #define strNE(s1,s2)     (strcmp(s1,s2)        != 0)
203 #define strEQn(s1,s2,n)  (strncmp(s1,s2,n)     == 0)
204 #define strNEn(s1,s2,n)  (strncmp(s1,s2,n)     != 0)
205
206 #define strcEQ(s1,s2)    (strcasecmp(s1,s2)    == 0)
207 #define strcNE(s1,s2)    (strcasecmp(s1,s2)    != 0)
208 #define strcEQn(s1,s2,n) (strncasecmp(s1,s2,n) == 0)
209 #define strcNEn(s1,s2,n) (strncasecmp(s1,s2,n) != 0)
210
211 #define strIsEmpty(s)    (s == NULL || s[0] == NUL)
212
213 #define myConnConfig(c) \
214 (SSLConnRec *)ap_get_module_config(c->conn_config, &ssl_module)
215 #define myCtxConfig(sslconn, sc) (sslconn->is_proxy ? sc->proxy : sc->server)
216 #define myConnConfigSet(c, val) \
217 ap_set_module_config(c->conn_config, &ssl_module, val)
218 #define mySrvConfig(srv) (SSLSrvConfigRec *)ap_get_module_config(srv->module_config,  &ssl_module)
219 #define myDirConfig(req) (SSLDirConfigRec *)ap_get_module_config(req->per_dir_config, &ssl_module)
220 #define myModConfig(srv) (mySrvConfig((srv)))->mc
221 #define mySrvFromConn(c) (myConnConfig(c))->server
222 #define mySrvConfigFromConn(c) mySrvConfig(mySrvFromConn(c))
223 #define myModConfigFromConn(c) myModConfig(mySrvFromConn(c))
224
225 #define myCtxVarSet(mc,num,val)  mc->rCtx.pV##num = val
226 #define myCtxVarGet(mc,num,type) (type)(mc->rCtx.pV##num)
227
228 /**
229  * Defaults for the configuration
230  */
231 #ifndef SSL_SESSION_CACHE_TIMEOUT
232 #define SSL_SESSION_CACHE_TIMEOUT  300
233 #endif
234
235 /* Default setting for per-dir reneg buffer. */
236 #ifndef DEFAULT_RENEG_BUFFER_SIZE
237 #define DEFAULT_RENEG_BUFFER_SIZE (128 * 1024)
238 #endif
239
240 /* Default for OCSP response validity */
241 #ifndef DEFAULT_OCSP_MAX_SKEW
242 #define DEFAULT_OCSP_MAX_SKEW (60 * 5)
243 #endif
244
245 /* Default timeout for OCSP queries */
246 #ifndef DEFAULT_OCSP_TIMEOUT
247 #define DEFAULT_OCSP_TIMEOUT 10
248 #endif
249
250 /**
251  * Define the certificate algorithm types
252  */
253
254 typedef int ssl_algo_t;
255
256 #define SSL_ALGO_UNKNOWN (0)
257 #define SSL_ALGO_RSA     (1<<0)
258 #define SSL_ALGO_DSA     (1<<1)
259 #ifndef OPENSSL_NO_EC
260 #define SSL_ALGO_ECC     (1<<2)
261 #define SSL_ALGO_ALL     (SSL_ALGO_RSA|SSL_ALGO_DSA|SSL_ALGO_ECC)
262 #else
263 #define SSL_ALGO_ALL     (SSL_ALGO_RSA|SSL_ALGO_DSA)
264 #endif
265
266 #define SSL_AIDX_RSA     (0)
267 #define SSL_AIDX_DSA     (1)
268 #ifndef OPENSSL_NO_EC
269 #define SSL_AIDX_ECC     (2)
270 #define SSL_AIDX_MAX     (3)
271 #else
272 #define SSL_AIDX_MAX     (2)
273 #endif
274
275
276 /**
277  * Define IDs for the temporary RSA keys and DH params
278  */
279
280 #define SSL_TMP_KEY_RSA_512  (0)
281 #define SSL_TMP_KEY_RSA_1024 (1)
282 #define SSL_TMP_KEY_DH_512   (2)
283 #define SSL_TMP_KEY_DH_1024  (3)
284 #define SSL_TMP_KEY_MAX      (4)
285
286 /**
287  * Define the SSL options
288  */
289 #define SSL_OPT_NONE           (0)
290 #define SSL_OPT_RELSET         (1<<0)
291 #define SSL_OPT_STDENVVARS     (1<<1)
292 #define SSL_OPT_EXPORTCERTDATA (1<<3)
293 #define SSL_OPT_FAKEBASICAUTH  (1<<4)
294 #define SSL_OPT_STRICTREQUIRE  (1<<5)
295 #define SSL_OPT_OPTRENEGOTIATE (1<<6)
296 #define SSL_OPT_LEGACYDNFORMAT (1<<7)
297 typedef int ssl_opt_t;
298
299 /**
300  * Define the SSL Protocol options
301  */
302 #define SSL_PROTOCOL_NONE  (0)
303 #define SSL_PROTOCOL_SSLV2 (1<<0)
304 #define SSL_PROTOCOL_SSLV3 (1<<1)
305 #define SSL_PROTOCOL_TLSV1 (1<<2)
306 #define SSL_PROTOCOL_ALL   (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1)
307 typedef int ssl_proto_t;
308
309 /**
310  * Define the SSL verify levels
311  */
312 typedef enum {
313     SSL_CVERIFY_UNSET           = UNSET,
314     SSL_CVERIFY_NONE            = 0,
315     SSL_CVERIFY_OPTIONAL        = 1,
316     SSL_CVERIFY_REQUIRE         = 2,
317     SSL_CVERIFY_OPTIONAL_NO_CA  = 3
318 } ssl_verify_t;
319
320 #define SSL_VERIFY_PEER_STRICT \
321      (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
322
323 #define ssl_verify_error_is_optional(errnum) \
324    ((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) \
325     || (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
326     || (errnum == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) \
327     || (errnum == X509_V_ERR_CERT_UNTRUSTED) \
328     || (errnum == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
329
330 /**
331   * CRL checking modes
332   */
333 typedef enum {
334     SSL_CRLCHECK_UNSET = UNSET,
335     SSL_CRLCHECK_NONE  = 0,
336     SSL_CRLCHECK_LEAF  = 1,
337     SSL_CRLCHECK_CHAIN = 2
338 } ssl_crlcheck_t;
339
340 /**
341  * Define the SSL pass phrase dialog types
342  */
343 typedef enum {
344     SSL_PPTYPE_UNSET   = UNSET,
345     SSL_PPTYPE_BUILTIN = 0,
346     SSL_PPTYPE_FILTER  = 1,
347     SSL_PPTYPE_PIPE    = 2
348 } ssl_pphrase_t;
349
350 /**
351  * Define the Path Checking modes
352  */
353 #define SSL_PCM_EXISTS     1
354 #define SSL_PCM_ISREG      2
355 #define SSL_PCM_ISDIR      4
356 #define SSL_PCM_ISNONZERO  8
357 typedef unsigned int ssl_pathcheck_t;
358
359 /**
360  * Define the SSL enabled state
361  */
362 typedef enum {
363     SSL_ENABLED_UNSET    = UNSET,
364     SSL_ENABLED_FALSE    = 0,
365     SSL_ENABLED_TRUE     = 1,
366     SSL_ENABLED_OPTIONAL = 3
367 } ssl_enabled_t;
368
369 /**
370  * Define the SSL requirement structure
371  */
372 typedef struct {
373     char           *cpExpr;
374     ap_expr_info_t *mpExpr;
375 } ssl_require_t;
376
377 /**
378  * Define the SSL random number generator seeding source
379  */
380 typedef enum {
381     SSL_RSCTX_STARTUP = 1,
382     SSL_RSCTX_CONNECT = 2
383 } ssl_rsctx_t;
384 typedef enum {
385     SSL_RSSRC_BUILTIN = 1,
386     SSL_RSSRC_FILE    = 2,
387     SSL_RSSRC_EXEC    = 3,
388     SSL_RSSRC_EGD     = 4
389 } ssl_rssrc_t;
390 typedef struct {
391     ssl_rsctx_t  nCtx;
392     ssl_rssrc_t  nSrc;
393     char        *cpPath;
394     int          nBytes;
395 } ssl_randseed_t;
396
397 /**
398  * Define the structure of an ASN.1 anything
399  */
400 typedef struct {
401     long int       nData;
402     unsigned char *cpData;
403     apr_time_t     source_mtime;
404 } ssl_asn1_t;
405
406 /**
407  * Define the mod_ssl per-module configuration structure
408  * (i.e. the global configuration for each httpd process)
409  */
410
411 typedef enum {
412     SSL_SHUTDOWN_TYPE_UNSET,
413     SSL_SHUTDOWN_TYPE_STANDARD,
414     SSL_SHUTDOWN_TYPE_UNCLEAN,
415     SSL_SHUTDOWN_TYPE_ACCURATE
416 } ssl_shutdown_type_e;
417
418 typedef struct {
419     SSL *ssl;
420     const char *client_dn;
421     X509 *client_cert;
422     ssl_shutdown_type_e shutdown_type;
423     const char *verify_info;
424     const char *verify_error;
425     int verify_depth;
426     int is_proxy;
427     int disabled;
428     int non_ssl_request;
429
430     /* Track the handshake/renegotiation state for the connection so
431      * that all client-initiated renegotiations can be rejected, as a
432      * partial fix for CVE-2009-3555. */
433     enum {
434         RENEG_INIT = 0, /* Before initial handshake */
435         RENEG_REJECT, /* After initial handshake; any client-initiated
436                        * renegotiation should be rejected */
437         RENEG_ALLOW, /* A server-initated renegotiation is taking
438                       * place (as dictated by configuration) */
439         RENEG_ABORT /* Renegotiation initiated by client, abort the
440                      * connection */
441     } reneg_state;
442
443     server_rec *server;
444 } SSLConnRec;
445
446 /* BIG FAT WARNING: SSLModConfigRec has unusual memory lifetime: it is
447  * allocated out of the "process" pool and only a single such
448  * structure is created and used for the lifetime of the process.
449  * (The process pool is s->process->pool and is stored in the .pPool
450  * field.)  Most members of this structure are likewise allocated out
451  * of the process pool, but notably sesscache and sesscache_context
452  * are not.
453  *
454  * The structure is treated as mostly immutable after a single config
455  * parse has completed; the post_config hook (ssl_init_Module) flips
456  * the bFixed flag to true and subsequent invocations of the config
457  * callbacks hence do nothing.
458  *
459  * This odd lifetime strategy is used so that encrypted private keys
460  * can be decrypted once at startup and continue to be used across
461  * subsequent server reloads where the interactive password prompt is
462  * not possible.
463
464  * It is really an ABI nightmare waiting to happen since DSOs are
465  * reloaded across restarts, and nothing prevents the struct type
466  * changing across such reloads, yet the cached structure will be
467  * assumed to match regardless.
468  *
469  * This should really be fixed using a smaller structure which only
470  * stores that which is absolutely necessary (the private keys, maybe
471  * the random seed), and have that structure be strictly ABI-versioned
472  * for safety.
473  */
474 typedef struct {
475     pid_t           pid;
476     apr_pool_t     *pPool;
477     BOOL            bFixed;
478
479     /* OpenSSL SSL_SESS_CACHE_* flags: */
480     long            sesscache_mode;
481
482     /* The configured provider, and associated private data
483      * structure. */
484     const ap_socache_provider_t *sesscache;
485     ap_socache_instance_t *sesscache_context;
486
487     apr_global_mutex_t   *pMutex;
488     apr_array_header_t   *aRandSeed;
489     apr_hash_t     *tVHostKeys;
490     void           *pTmpKeys[SSL_TMP_KEY_MAX];
491
492     /* Two hash tables of pointers to ssl_asn1_t structures.  The
493      * structures are used to store certificates and private keys
494      * respectively, in raw DER format (serialized OpenSSL X509 and
495      * PrivateKey structures).  The tables are indexed by (vhost-id,
496      * algorithm type) using the function ssl_asn1_table_keyfmt(); for
497      * example the string "vhost.example.com:443:RSA". */
498     apr_hash_t     *tPublicCert;
499     apr_hash_t     *tPrivateKey;
500
501 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
502     const char     *szCryptoDevice;
503 #endif
504
505 #ifdef HAVE_OCSP_STAPLING
506     const ap_socache_provider_t *stapling_cache;
507     ap_socache_instance_t *stapling_cache_context;
508     apr_global_mutex_t   *stapling_mutex;
509 #endif
510
511     struct {
512         void *pV1, *pV2, *pV3, *pV4, *pV5, *pV6, *pV7, *pV8, *pV9, *pV10;
513     } rCtx;
514 } SSLModConfigRec;
515
516 /** Structure representing configured filenames for certs and keys for
517  * a given vhost, and the corresponding in-memory structures once the
518  * files are parsed.  */
519 typedef struct {
520     /* Lists of configured certs and keys for this server; from index
521      * 0 up to SSL_AIDX_MAX-1 or the first NULL pointer.  Note that
522      * these arrays are NOT indexed by algorithm type, they are simply
523      * unordered lists. */
524     const char  *cert_files[SSL_AIDX_MAX];
525     const char  *key_files[SSL_AIDX_MAX];
526     /* Loaded certs and keys; these arrays ARE indexed by the
527      * algorithm type, i.e.  keys[SSL_AIDX_RSA] maps to the RSA
528      * private key. */
529     X509        *certs[SSL_AIDX_MAX];
530     EVP_PKEY    *keys[SSL_AIDX_MAX];
531
532     /** Certificates which specify the set of CA names which should be
533      * sent in the CertificateRequest message: */
534     const char  *ca_name_path;
535     const char  *ca_name_file;
536 } modssl_pk_server_t;
537
538 typedef struct {
539     /** proxy can have any number of cert/key pairs */
540     const char  *cert_file;
541     const char  *cert_path;
542     const char  *ca_cert_file;
543     STACK_OF(X509_INFO) *certs; /* Contains End Entity certs */
544     STACK_OF(X509) **ca_certs; /* Contains ONLY chain certs for
545                                 * each item in certs.
546                                 * (ptr to array of ptrs) */
547 } modssl_pk_proxy_t;
548
549 /** stuff related to authentication that can also be per-dir */
550 typedef struct {
551     /** known/trusted CAs */
552     const char  *ca_cert_path;
553     const char  *ca_cert_file;
554
555     const char  *cipher_suite;
556
557     /** for client or downstream server authentication */
558     int          verify_depth;
559     ssl_verify_t verify_mode;
560 } modssl_auth_ctx_t;
561
562
563 #ifdef HAVE_TLSEXT_TICKETS
564
565 /* 48 bytes: 16 for keyname, 16 for HMAC secret, 16 for AES private key */
566 #define TLSEXT_TICKET_KEYLEN (48)
567
568 typedef struct {
569     /* Human readable name, used in the configuration */
570     const char *conf_name;
571     char key_name[16];
572     unsigned char hmac_secret[16];
573     unsigned char aes_key[16];
574 } modssl_ticket_t;
575 #endif
576
577 typedef struct SSLSrvConfigRec SSLSrvConfigRec;
578
579 typedef struct {
580     SSLSrvConfigRec *sc; /** pointer back to server config */
581     SSL_CTX *ssl_ctx;
582
583     /** we are one or the other */
584     modssl_pk_server_t *pks;
585     modssl_pk_proxy_t  *pkp;
586
587     ssl_proto_t  protocol;
588
589     /** config for handling encrypted keys */
590     ssl_pphrase_t pphrase_dialog_type;
591     const char   *pphrase_dialog_path;
592
593     const char  *cert_chain;
594     const char  *pkcs7;
595
596     /** certificate revocation list */
597     const char    *crl_path;
598     const char    *crl_file;
599     ssl_crlcheck_t crl_check_mode;
600
601 #ifdef HAVE_OCSP_STAPLING
602     /** OCSP stapling options */
603     BOOL        stapling_enabled;
604     long        stapling_resptime_skew;
605     long        stapling_resp_maxage;
606     int         stapling_cache_timeout;
607     BOOL        stapling_return_errors;
608     BOOL        stapling_fake_trylater;
609     int         stapling_errcache_timeout;
610     apr_interval_time_t stapling_responder_timeout;
611     const char *stapling_force_url;
612 #endif
613
614     modssl_auth_ctx_t auth;
615
616     BOOL ocsp_enabled; /* true if OCSP verification enabled */
617     BOOL ocsp_force_default; /* true if the default responder URL is
618                               * used regardless of per-cert URL */
619     const char *ocsp_responder; /* default responder URL */
620     long ocsp_resptime_skew;
621     long ocsp_resp_maxage;
622     apr_interval_time_t ocsp_responder_timeout;
623
624 } modssl_ctx_t;
625
626 struct SSLSrvConfigRec {
627     SSLModConfigRec *mc;
628     ssl_enabled_t    enabled;
629     BOOL             proxy_enabled;
630     const char      *vhost_id;
631     int              vhost_id_len;
632     int              session_cache_timeout;
633     BOOL             cipher_server_pref;
634     BOOL             insecure_reneg;
635     modssl_ctx_t    *server;
636     modssl_ctx_t    *proxy;
637     ssl_enabled_t    proxy_ssl_check_peer_expire;
638     ssl_enabled_t    proxy_ssl_check_peer_cn;
639 #ifndef OPENSSL_NO_TLSEXT
640     ssl_enabled_t    strict_sni_vhost_check;
641 #endif
642 #ifdef HAVE_FIPS
643     BOOL             fips;
644 #endif
645 #ifdef HAVE_TLSEXT_TICKETS
646     const char *default_ticket_name;
647     modssl_ticket_t* default_ticket;
648     apr_array_header_t* tickets;
649 #endif
650 };
651
652 /**
653  * Define the mod_ssl per-directory configuration structure
654  * (i.e. the local configuration for all &lt;Directory>
655  *  and .htaccess contexts)
656  */
657 typedef struct {
658     BOOL          bSSLRequired;
659     apr_array_header_t *aRequirement;
660     ssl_opt_t     nOptions;
661     ssl_opt_t     nOptionsAdd;
662     ssl_opt_t     nOptionsDel;
663     const char   *szCipherSuite;
664     ssl_verify_t  nVerifyClient;
665     int           nVerifyDepth;
666     const char   *szCACertificatePath;
667     const char   *szCACertificateFile;
668     const char   *szUserName;
669     apr_size_t    nRenegBufferSize;
670 } SSLDirConfigRec;
671
672 /**
673  *  function prototypes
674  */
675
676 /**  API glue structures  */
677 extern module AP_MODULE_DECLARE_DATA ssl_module;
678
679 /**  configuration handling   */
680 SSLModConfigRec *ssl_config_global_create(server_rec *);
681 void         ssl_config_global_fix(SSLModConfigRec *);
682 BOOL         ssl_config_global_isfixed(SSLModConfigRec *);
683 void        *ssl_config_server_create(apr_pool_t *, server_rec *);
684 void        *ssl_config_server_merge(apr_pool_t *, void *, void *);
685 void        *ssl_config_perdir_create(apr_pool_t *, char *);
686 void        *ssl_config_perdir_merge(apr_pool_t *, void *, void *);
687 const char  *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, void *, const char *);
688 const char  *ssl_cmd_SSLCryptoDevice(cmd_parms *, void *, const char *);
689 const char  *ssl_cmd_SSLRandomSeed(cmd_parms *, void *, const char *, const char *, const char *);
690 const char  *ssl_cmd_SSLEngine(cmd_parms *, void *, const char *);
691 const char  *ssl_cmd_SSLCipherSuite(cmd_parms *, void *, const char *);
692 const char  *ssl_cmd_SSLCertificateFile(cmd_parms *, void *, const char *);
693 const char  *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, void *, const char *);
694 const char  *ssl_cmd_SSLCertificateChainFile(cmd_parms *, void *, const char *);
695 const char  *ssl_cmd_SSLPKCS7CertificateFile(cmd_parms *, void *, const char *);
696 const char  *ssl_cmd_SSLCACertificatePath(cmd_parms *, void *, const char *);
697 const char  *ssl_cmd_SSLCACertificateFile(cmd_parms *, void *, const char *);
698 const char  *ssl_cmd_SSLCADNRequestPath(cmd_parms *, void *, const char *);
699 const char  *ssl_cmd_SSLCADNRequestFile(cmd_parms *, void *, const char *);
700 const char  *ssl_cmd_SSLCARevocationPath(cmd_parms *, void *, const char *);
701 const char  *ssl_cmd_SSLCARevocationFile(cmd_parms *, void *, const char *);
702 const char  *ssl_cmd_SSLCARevocationCheck(cmd_parms *, void *, const char *);
703 const char  *ssl_cmd_SSLHonorCipherOrder(cmd_parms *cmd, void *dcfg, int flag);
704 const char  *ssl_cmd_SSLVerifyClient(cmd_parms *, void *, const char *);
705 const char  *ssl_cmd_SSLVerifyDepth(cmd_parms *, void *, const char *);
706 const char  *ssl_cmd_SSLSessionCache(cmd_parms *, void *, const char *);
707 const char  *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, void *, const char *);
708 const char  *ssl_cmd_SSLProtocol(cmd_parms *, void *, const char *);
709 const char  *ssl_cmd_SSLOptions(cmd_parms *, void *, const char *);
710 const char  *ssl_cmd_SSLRequireSSL(cmd_parms *, void *);
711 const char  *ssl_cmd_SSLRequire(cmd_parms *, void *, const char *);
712 const char  *ssl_cmd_SSLUserName(cmd_parms *, void *, const char *);
713 const char  *ssl_cmd_SSLRenegBufferSize(cmd_parms *cmd, void *dcfg, const char *arg);
714 const char  *ssl_cmd_SSLStrictSNIVHostCheck(cmd_parms *cmd, void *dcfg, int flag);
715 const char *ssl_cmd_SSLInsecureRenegotiation(cmd_parms *cmd, void *dcfg, int flag);
716
717 const char  *ssl_cmd_SSLProxyEngine(cmd_parms *cmd, void *dcfg, int flag);
718 const char  *ssl_cmd_SSLProxyProtocol(cmd_parms *, void *, const char *);
719 const char  *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, void *, const char *);
720 const char  *ssl_cmd_SSLProxyVerify(cmd_parms *, void *, const char *);
721 const char  *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, void *, const char *);
722 const char  *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, void *, const char *);
723 const char  *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, void *, const char *);
724 const char  *ssl_cmd_SSLProxyCARevocationPath(cmd_parms *, void *, const char *);
725 const char  *ssl_cmd_SSLProxyCARevocationFile(cmd_parms *, void *, const char *);
726 const char  *ssl_cmd_SSLProxyCARevocationCheck(cmd_parms *, void *, const char *);
727 const char  *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
728 const char  *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
729 const char  *ssl_cmd_SSLProxyMachineCertificateChainFile(cmd_parms *, void *, const char *);
730 const char  *ssl_cmd_SSLProxyCheckPeerExpire(cmd_parms *cmd, void *dcfg, int flag);
731 const char  *ssl_cmd_SSLProxyCheckPeerCN(cmd_parms *cmd, void *dcfg, int flag);
732
733 const char *ssl_cmd_SSLOCSPOverrideResponder(cmd_parms *cmd, void *dcfg, int flag);
734 const char *ssl_cmd_SSLOCSPDefaultResponder(cmd_parms *cmd, void *dcfg, const char *arg);
735 const char *ssl_cmd_SSLOCSPResponseTimeSkew(cmd_parms *cmd, void *dcfg, const char *arg);
736 const char *ssl_cmd_SSLOCSPResponseMaxAge(cmd_parms *cmd, void *dcfg, const char *arg);
737 const char *ssl_cmd_SSLOCSPResponderTimeout(cmd_parms *cmd, void *dcfg, const char *arg);
738 const char *ssl_cmd_SSLOCSPEnable(cmd_parms *cmd, void *dcfg, int flag);
739
740 const char *ssl_cmd_SSLFIPS(cmd_parms *cmd, void *dcfg, int flag);
741 const char *ssl_cmd_SSLTicketKeyDefault(cmd_parms *cmd, void *dcfg, const char *name);
742 const char *ssl_cmd_SSLTicketKeyFile(cmd_parms *cmd, void *dcfg, const char *name, const char *path);
743
744 /**  module initialization  */
745 int          ssl_init_Module(apr_pool_t *, apr_pool_t *, apr_pool_t *, server_rec *);
746 void         ssl_init_Engine(server_rec *, apr_pool_t *);
747 void         ssl_init_ConfigureServer(server_rec *, apr_pool_t *, apr_pool_t *, SSLSrvConfigRec *);
748 void         ssl_init_CheckServers(server_rec *, apr_pool_t *);
749 STACK_OF(X509_NAME)
750             *ssl_init_FindCAList(server_rec *, apr_pool_t *, const char *, const char *);
751 void         ssl_init_Child(apr_pool_t *, server_rec *);
752 apr_status_t ssl_init_ModuleKill(void *data);
753
754 /**  Apache API hooks  */
755 int          ssl_hook_Auth(request_rec *);
756 int          ssl_hook_UserCheck(request_rec *);
757 int          ssl_hook_Access(request_rec *);
758 int          ssl_hook_Fixup(request_rec *);
759 int          ssl_hook_ReadReq(request_rec *);
760 int          ssl_hook_Upgrade(request_rec *);
761 void         ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s);
762
763 /** Apache authz provisders */
764 extern const authz_provider ssl_authz_provider_require_ssl;
765 extern const authz_provider ssl_authz_provider_verify_client;
766
767 /**  OpenSSL callbacks */
768 RSA         *ssl_callback_TmpRSA(SSL *, int, int);
769 DH          *ssl_callback_TmpDH(SSL *, int, int);
770 #ifndef OPENSSL_NO_EC
771 EC_KEY      *ssl_callback_TmpECDH(SSL *, int, int);
772 #endif
773 int          ssl_callback_SSLVerify(int, X509_STORE_CTX *);
774 int          ssl_callback_SSLVerify_CRL(int, X509_STORE_CTX *, conn_rec *);
775 int          ssl_callback_proxy_cert(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
776 int          ssl_callback_NewSessionCacheEntry(SSL *, SSL_SESSION *);
777 SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *, unsigned char *, int, int *);
778 void         ssl_callback_DelSessionCacheEntry(SSL_CTX *, SSL_SESSION *);
779 void         ssl_callback_Info(const SSL *, int, int);
780 #ifndef OPENSSL_NO_TLSEXT
781 int          ssl_callback_ServerNameIndication(SSL *, int *, modssl_ctx_t *);
782 #endif
783
784 #ifdef HAVE_TLSEXT_TICKETS
785 int         ssl_callback_tlsext_tickets(SSL *ssl,
786                                         unsigned char *keyname,
787                                         unsigned char *iv,
788                                         EVP_CIPHER_CTX *cipher_ctx,
789                                         HMAC_CTX *hctx,
790                                         int mode);
791 #endif
792
793 /**  Session Cache Support  */
794 void         ssl_scache_init(server_rec *, apr_pool_t *);
795 void         ssl_scache_status_register(apr_pool_t *p);
796 void         ssl_scache_kill(server_rec *);
797 BOOL         ssl_scache_store(server_rec *, UCHAR *, int,
798                               apr_time_t, SSL_SESSION *, apr_pool_t *);
799 SSL_SESSION *ssl_scache_retrieve(server_rec *, UCHAR *, int, apr_pool_t *);
800 void         ssl_scache_remove(server_rec *, UCHAR *, int,
801                                apr_pool_t *);
802
803 /** Proxy Support */
804 int ssl_proxy_enable(conn_rec *c);
805 int ssl_engine_disable(conn_rec *c);
806
807 /** OCSP Stapling Support */
808 #ifdef HAVE_OCSP_STAPLING
809 const char *ssl_cmd_SSLStaplingCache(cmd_parms *, void *, const char *);
810 const char *ssl_cmd_SSLUseStapling(cmd_parms *, void *, int);
811 const char *ssl_cmd_SSLStaplingResponseTimeSkew(cmd_parms *, void *, const char *);
812 const char *ssl_cmd_SSLStaplingResponseMaxAge(cmd_parms *, void *, const char *);
813 const char *ssl_cmd_SSLStaplingStandardCacheTimeout(cmd_parms *, void *, const char *);
814 const char *ssl_cmd_SSLStaplingErrorCacheTimeout(cmd_parms *, void *, const char *);
815 const char *ssl_cmd_SSLStaplingReturnResponderErrors(cmd_parms *, void *, int);
816 const char *ssl_cmd_SSLStaplingFakeTryLater(cmd_parms *, void *, int);
817 const char *ssl_cmd_SSLStaplingResponderTimeout(cmd_parms *, void *, const char *);
818 const char  *ssl_cmd_SSLStaplingForceURL(cmd_parms *, void *, const char *);
819 void         modssl_init_stapling(server_rec *, apr_pool_t *, apr_pool_t *, modssl_ctx_t *);
820 void         ssl_stapling_ex_init(void);
821 int          ssl_stapling_init_cert(server_rec *s, modssl_ctx_t *mctx, X509 *x);
822 #endif
823
824 /**  I/O  */
825 void         ssl_io_filter_init(conn_rec *, request_rec *r, SSL *);
826 void         ssl_io_filter_register(apr_pool_t *);
827 long         ssl_io_data_cb(BIO *, int, const char *, int, long, long);
828
829 /* ssl_io_buffer_fill fills the setaside buffering of the HTTP request
830  * to allow an SSL renegotiation to take place. */
831 int          ssl_io_buffer_fill(request_rec *r, apr_size_t maxlen);
832
833 /**  PRNG  */
834 int          ssl_rand_seed(server_rec *, apr_pool_t *, ssl_rsctx_t, char *);
835
836 /**  Utility Functions  */
837 char        *ssl_util_vhostid(apr_pool_t *, server_rec *);
838 apr_file_t  *ssl_util_ppopen(server_rec *, apr_pool_t *, const char *,
839                              const char * const *);
840 void         ssl_util_ppclose(server_rec *, apr_pool_t *, apr_file_t *);
841 char        *ssl_util_readfilter(server_rec *, apr_pool_t *, const char *,
842                                  const char * const *);
843 BOOL         ssl_util_path_check(ssl_pathcheck_t, const char *, apr_pool_t *);
844 ssl_algo_t   ssl_util_algotypeof(X509 *, EVP_PKEY *);
845 char        *ssl_util_algotypestr(ssl_algo_t);
846 void         ssl_util_thread_setup(apr_pool_t *);
847 int          ssl_init_ssl_connection(conn_rec *c, request_rec *r);
848
849 /**  Pass Phrase Support  */
850 void         ssl_pphrase_Handle(server_rec *, apr_pool_t *);
851
852 /**  Diffie-Hellman Parameter Support  */
853 DH           *ssl_dh_GetTmpParam(int);
854 DH           *ssl_dh_GetParamFromFile(char *);
855
856 unsigned char *ssl_asn1_table_set(apr_hash_t *table,
857                                   const char *key,
858                                   long int length);
859
860 ssl_asn1_t *ssl_asn1_table_get(apr_hash_t *table,
861                                const char *key);
862
863 void ssl_asn1_table_unset(apr_hash_t *table,
864                           const char *key);
865
866 const char *ssl_asn1_keystr(int keytype);
867
868 const char *ssl_asn1_table_keyfmt(apr_pool_t *p,
869                                   const char *id,
870                                   int keytype);
871
872 STACK_OF(X509) *ssl_read_pkcs7(server_rec *s, const char *pkcs7);
873
874 /**  Mutex Support  */
875 int          ssl_mutex_init(server_rec *, apr_pool_t *);
876 int          ssl_mutex_reinit(server_rec *, apr_pool_t *);
877 int          ssl_mutex_on(server_rec *);
878 int          ssl_mutex_off(server_rec *);
879
880 int          ssl_stapling_mutex_reinit(server_rec *, apr_pool_t *);
881
882 /* mutex type names for Mutex directive */
883 #define SSL_CACHE_MUTEX_TYPE    "ssl-cache"
884 #define SSL_STAPLING_MUTEX_TYPE "ssl-stapling"
885
886 /**  Logfile Support  */
887 void         ssl_die(void);
888 void         ssl_log_ssl_error(const char *, int, int, server_rec *);
889
890 /* ssl_log_xerror, ssl_log_cxerror and ssl_log_rxerror are wrappers for the
891  * respective ap_log_*error functions and take a certificate as an
892  * additional argument (whose details are appended to the log message).
893  * The other arguments are interpreted exactly as with their ap_log_*error
894  * counterparts. */
895 void ssl_log_xerror(const char *file, int line, int level,
896                     apr_status_t rv, apr_pool_t *p, server_rec *s,
897                     X509 *cert, const char *format, ...)
898     __attribute__((format(printf,8,9)));
899
900 void ssl_log_cxerror(const char *file, int line, int level,
901                      apr_status_t rv, conn_rec *c, X509 *cert,
902                      const char *format, ...)
903     __attribute__((format(printf,7,8)));
904
905 void ssl_log_rxerror(const char *file, int line, int level,
906                      apr_status_t rv, request_rec *r, X509 *cert,
907                      const char *format, ...)
908     __attribute__((format(printf,7,8)));
909
910 #define SSLLOG_MARK              __FILE__,__LINE__
911
912 /**  Variables  */
913
914 /* Register variables for the lifetime of the process pool 'p'. */
915 void         ssl_var_register(apr_pool_t *p);
916 char        *ssl_var_lookup(apr_pool_t *, server_rec *, conn_rec *, request_rec *, char *);
917 apr_array_header_t *ssl_ext_list(apr_pool_t *p, conn_rec *c, int peer, const char *extension);
918
919 void         ssl_var_log_config_register(apr_pool_t *p);
920
921 /* Extract SSL_*_DN_* variables into table 't' from SSL object 'ssl',
922  * allocating from 'p': */
923 void modssl_var_extract_dns(apr_table_t *t, SSL *ssl, apr_pool_t *p);
924
925 #ifndef OPENSSL_NO_OCSP
926 /* Perform OCSP validation of the current cert in the given context.
927  * Returns non-zero on success or zero on failure.  On failure, the
928  * context error code is set. */
929 int modssl_verify_ocsp(X509_STORE_CTX *ctx, SSLSrvConfigRec *sc,
930                        server_rec *s, conn_rec *c, apr_pool_t *pool);
931
932 /* OCSP helper interface; dispatches the given OCSP request to the
933  * responder at the given URI.  Returns the decoded OCSP response
934  * object, or NULL on error (in which case, errors will have been
935  * logged).  Pool 'p' is used for temporary allocations. */
936 OCSP_RESPONSE *modssl_dispatch_ocsp_request(const apr_uri_t *uri,
937                                             apr_interval_time_t timeout,
938                                             OCSP_REQUEST *request,
939                                             conn_rec *c, apr_pool_t *p);
940 #endif
941
942 #endif /* SSL_PRIVATE_H */
943 /** @} */
944