]> granicus.if.org Git - apache/blob - modules/ssl/ssl_private.h
mod_ssl: Add support for loading private keys from ENGINEs. Support
[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 #if 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/opensslv.h>
86 #if (OPENSSL_VERSION_NUMBER >= 0x10001000)
87 /* must be defined before including ssl.h */
88 #define OPENSSL_NO_SSL_INTERN
89 #endif
90 #include <openssl/ssl.h>
91 #include <openssl/err.h>
92 #include <openssl/x509.h>
93 #include <openssl/pem.h>
94 #include <openssl/crypto.h>
95 #include <openssl/evp.h>
96 #include <openssl/rand.h>
97 #include <openssl/x509v3.h>
98 #include <openssl/x509_vfy.h>
99 #include <openssl/ocsp.h>
100
101 /* Avoid tripping over an engine build installed globally and detected
102  * when the user points at an explicit non-engine flavor of OpenSSL
103  */
104 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
105 #include <openssl/engine.h>
106 #endif
107
108 #if (OPENSSL_VERSION_NUMBER < 0x0090801f)
109 #error mod_ssl requires OpenSSL 0.9.8a or later
110 #endif
111
112 /**
113  * ...shifting sands of OpenSSL...
114  * Note: when adding support for new OpenSSL features, avoid explicit
115  * version number checks whenever possible, and use "feature-based"
116  * detection instead (check for definitions of constants or functions)
117  */
118 #if (OPENSSL_VERSION_NUMBER >= 0x10000000)
119 #define MODSSL_SSL_CIPHER_CONST const
120 #define MODSSL_SSL_METHOD_CONST const
121 #else
122 #define MODSSL_SSL_CIPHER_CONST
123 #define MODSSL_SSL_METHOD_CONST
124 #endif
125
126 #if defined(LIBRESSL_VERSION_NUMBER)
127 /* Missing from LibreSSL */
128 #if LIBRESSL_VERSION_NUMBER < 0x2060000f
129 #define SSL_CTRL_SET_MIN_PROTO_VERSION          123
130 #define SSL_CTRL_SET_MAX_PROTO_VERSION          124
131 #define SSL_CTX_set_min_proto_version(ctx, version) \
132         SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
133 #define SSL_CTX_set_max_proto_version(ctx, version) \
134         SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
135 #elif LIBRESSL_VERSION_NUMBER < 0x2070000f
136 /* LibreSSL before 2.7 declares OPENSSL_VERSION_NUMBER == 2.0 but does not
137  * include most changes from OpenSSL >= 1.1 (new functions, macros, 
138  * deprecations, ...), so we have to work around this...
139  */
140 #define MODSSL_USE_OPENSSL_PRE_1_1_API (1)
141 #endif /* LIBRESSL_VERSION_NUMBER < 0x2060000f */
142 #else /* defined(LIBRESSL_VERSION_NUMBER) */
143 #define MODSSL_USE_OPENSSL_PRE_1_1_API (OPENSSL_VERSION_NUMBER < 0x10100000L)
144 #endif
145
146 #if defined(OPENSSL_FIPS)
147 #define HAVE_FIPS
148 #endif
149
150 #if defined(SSL_OP_NO_TLSv1_2)
151 #define HAVE_TLSV1_X
152 #endif
153
154 #if defined(SSL_CONF_FLAG_FILE)
155 #define HAVE_SSL_CONF_CMD
156 #endif
157
158 /* session id constness */
159 #if MODSSL_USE_OPENSSL_PRE_1_1_API
160 #define IDCONST
161 #else
162 #define IDCONST const
163 #endif
164
165 /**
166   * The following features all depend on TLS extension support.
167   * Within this block, check again for features (not version numbers).
168   */
169 #if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name)
170
171 #define HAVE_TLSEXT
172
173 /* ECC: make sure we have at least 1.0.0 */
174 #if !defined(OPENSSL_NO_EC) && defined(TLSEXT_ECPOINTFORMAT_uncompressed)
175 #define HAVE_ECC
176 #endif
177
178 /* OCSP stapling */
179 #if !defined(OPENSSL_NO_OCSP) && defined(SSL_CTX_set_tlsext_status_cb)
180 #define HAVE_OCSP_STAPLING
181 /* All exist but are no longer macros since OpenSSL 1.1.0 */
182 #if OPENSSL_VERSION_NUMBER < 0x10100000L
183 /* backward compatibility with OpenSSL < 1.0 */
184 #ifndef sk_OPENSSL_STRING_num
185 #define sk_OPENSSL_STRING_num sk_num
186 #endif
187 #ifndef sk_OPENSSL_STRING_value
188 #define sk_OPENSSL_STRING_value sk_value
189 #endif
190 #ifndef sk_OPENSSL_STRING_pop
191 #define sk_OPENSSL_STRING_pop sk_pop
192 #endif
193 #endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L */
194 #endif /* if !defined(OPENSSL_NO_OCSP) && defined(SSL_CTX_set_tlsext_status_cb) */
195
196 /* TLS session tickets */
197 #if defined(SSL_CTX_set_tlsext_ticket_key_cb)
198 #define HAVE_TLS_SESSION_TICKETS
199 #define TLSEXT_TICKET_KEY_LEN 48
200 #ifndef tlsext_tick_md
201 #ifdef OPENSSL_NO_SHA256
202 #define tlsext_tick_md EVP_sha1
203 #else
204 #define tlsext_tick_md EVP_sha256
205 #endif
206 #endif
207 #endif
208
209 /* Secure Remote Password */
210 #if !defined(OPENSSL_NO_SRP) && defined(SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB)
211 #define HAVE_SRP
212 #include <openssl/srp.h>
213 #endif
214
215 /* ALPN Protocol Negotiation */
216 #if defined(TLSEXT_TYPE_application_layer_protocol_negotiation)
217 #define HAVE_TLS_ALPN
218 #endif
219
220 #endif /* !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name) */
221
222 #if MODSSL_USE_OPENSSL_PRE_1_1_API
223 #define BN_get_rfc2409_prime_768   get_rfc2409_prime_768
224 #define BN_get_rfc2409_prime_1024  get_rfc2409_prime_1024
225 #define BN_get_rfc3526_prime_1536  get_rfc3526_prime_1536
226 #define BN_get_rfc3526_prime_2048  get_rfc3526_prime_2048
227 #define BN_get_rfc3526_prime_3072  get_rfc3526_prime_3072
228 #define BN_get_rfc3526_prime_4096  get_rfc3526_prime_4096
229 #define BN_get_rfc3526_prime_6144  get_rfc3526_prime_6144
230 #define BN_get_rfc3526_prime_8192  get_rfc3526_prime_8192
231 #define BIO_set_init(x,v)          (x->init=v)
232 #define BIO_get_data(x)            (x->ptr)
233 #define BIO_set_data(x,v)          (x->ptr=v)
234 #define BIO_get_shutdown(x)        (x->shutdown)
235 #define BIO_set_shutdown(x,v)      (x->shutdown=v)
236 #define DH_bits(x)                 (BN_num_bits(x->p))
237 #else
238 void init_bio_methods(void);
239 void free_bio_methods(void);
240 #endif
241
242 #if OPENSSL_VERSION_NUMBER < 0x10002000L || \
243         (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000f)
244 #define X509_STORE_CTX_get0_store(x) (x->ctx)
245 #endif
246
247 #if OPENSSL_VERSION_NUMBER < 0x10000000L
248 #ifndef X509_STORE_CTX_get0_current_issuer
249 #define X509_STORE_CTX_get0_current_issuer(x) (x->current_issuer)
250 #endif
251 #endif
252
253 /* mod_ssl headers */
254 #include "ssl_util_ssl.h"
255
256 APLOG_USE_MODULE(ssl);
257
258 /*
259  * Provide reasonable default for some defines
260  */
261 #ifndef UNSET
262 #define UNSET (-1)
263 #endif
264 #ifndef NUL
265 #define NUL '\0'
266 #endif
267 #ifndef RAND_MAX
268 #include <limits.h>
269 #define RAND_MAX INT_MAX
270 #endif
271
272 /**
273  * Provide reasonable defines for some types
274  */
275 #ifndef UCHAR
276 #define UCHAR unsigned char
277 #endif
278
279 /**
280  * Provide useful shorthands
281  */
282 #define strEQ(s1,s2)     (strcmp(s1,s2)        == 0)
283 #define strNE(s1,s2)     (strcmp(s1,s2)        != 0)
284 #define strEQn(s1,s2,n)  (strncmp(s1,s2,n)     == 0)
285 #define strNEn(s1,s2,n)  (strncmp(s1,s2,n)     != 0)
286
287 #define strcEQ(s1,s2)    (strcasecmp(s1,s2)    == 0)
288 #define strcNE(s1,s2)    (strcasecmp(s1,s2)    != 0)
289 #define strcEQn(s1,s2,n) (strncasecmp(s1,s2,n) == 0)
290 #define strcNEn(s1,s2,n) (strncasecmp(s1,s2,n) != 0)
291
292 #define strIsEmpty(s)    (s == NULL || s[0] == NUL)
293
294 #define myConnConfig(c) \
295     ((SSLConnRec *)ap_get_module_config(c->conn_config, &ssl_module))
296 #define myConnConfigSet(c, val) \
297     ap_set_module_config(c->conn_config, &ssl_module, val)
298 #define mySrvConfig(srv) \
299     ((SSLSrvConfigRec *)ap_get_module_config(srv->module_config,  &ssl_module))
300 #define myDirConfig(req) \
301     ((SSLDirConfigRec *)ap_get_module_config(req->per_dir_config, &ssl_module))
302 #define myCtxConfig(sslconn, sc) \
303     (sslconn->is_proxy ? sslconn->dc->proxy : sc->server)
304 #define myModConfig(srv) mySrvConfig((srv))->mc
305 #define mySrvFromConn(c) myConnConfig(c)->server
306 #define myDirConfigFromConn(c) myConnConfig(c)->dc
307 #define mySrvConfigFromConn(c) mySrvConfig(mySrvFromConn(c))
308 #define myModConfigFromConn(c) myModConfig(mySrvFromConn(c))
309
310 /**
311  * Defaults for the configuration
312  */
313 #ifndef SSL_SESSION_CACHE_TIMEOUT
314 #define SSL_SESSION_CACHE_TIMEOUT  300
315 #endif
316
317 /* Default setting for per-dir reneg buffer. */
318 #ifndef DEFAULT_RENEG_BUFFER_SIZE
319 #define DEFAULT_RENEG_BUFFER_SIZE (128 * 1024)
320 #endif
321
322 /* Default for OCSP response validity */
323 #ifndef DEFAULT_OCSP_MAX_SKEW
324 #define DEFAULT_OCSP_MAX_SKEW (60 * 5)
325 #endif
326
327 /* Default timeout for OCSP queries */
328 #ifndef DEFAULT_OCSP_TIMEOUT
329 #define DEFAULT_OCSP_TIMEOUT 10
330 #endif
331
332 /**
333  * Define the SSL options
334  */
335 #define SSL_OPT_NONE           (0)
336 #define SSL_OPT_RELSET         (1<<0)
337 #define SSL_OPT_STDENVVARS     (1<<1)
338 #define SSL_OPT_EXPORTCERTDATA (1<<3)
339 #define SSL_OPT_FAKEBASICAUTH  (1<<4)
340 #define SSL_OPT_STRICTREQUIRE  (1<<5)
341 #define SSL_OPT_OPTRENEGOTIATE (1<<6)
342 #define SSL_OPT_LEGACYDNFORMAT (1<<7)
343 typedef int ssl_opt_t;
344
345 /**
346  * Define the SSL Protocol options
347  */
348 #define SSL_PROTOCOL_NONE  (0)
349 #ifndef OPENSSL_NO_SSL3
350 #define SSL_PROTOCOL_SSLV3 (1<<1)
351 #endif
352 #define SSL_PROTOCOL_TLSV1 (1<<2)
353 #ifndef OPENSSL_NO_SSL3
354 #define SSL_PROTOCOL_BASIC (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1)
355 #else
356 #define SSL_PROTOCOL_BASIC (SSL_PROTOCOL_TLSV1)
357 #endif
358 #ifdef HAVE_TLSV1_X
359 #define SSL_PROTOCOL_TLSV1_1 (1<<3)
360 #define SSL_PROTOCOL_TLSV1_2 (1<<4)
361 #define SSL_PROTOCOL_TLSV1_3 (1<<5)
362
363 #ifdef SSL_OP_NO_TLSv1_3
364 #define SSL_HAVE_PROTOCOL_TLSV1_3   (1)
365 #define SSL_PROTOCOL_ALL   (SSL_PROTOCOL_BASIC| \
366                             SSL_PROTOCOL_TLSV1_1|SSL_PROTOCOL_TLSV1_2|SSL_PROTOCOL_TLSV1_3)
367 #else
368 #define SSL_HAVE_PROTOCOL_TLSV1_3   (0)
369 #define SSL_PROTOCOL_ALL   (SSL_PROTOCOL_BASIC| \
370                             SSL_PROTOCOL_TLSV1_1|SSL_PROTOCOL_TLSV1_2)
371 #endif
372 #else
373 #define SSL_PROTOCOL_ALL   (SSL_PROTOCOL_BASIC)
374 #endif
375 #ifndef OPENSSL_NO_SSL3
376 #define SSL_PROTOCOL_DEFAULT (SSL_PROTOCOL_ALL & ~SSL_PROTOCOL_SSLV3)
377 #else
378 #define SSL_PROTOCOL_DEFAULT (SSL_PROTOCOL_ALL)
379 #endif
380 typedef int ssl_proto_t;
381
382 /**
383  * Define the SSL verify levels
384  */
385 typedef enum {
386     SSL_CVERIFY_UNSET           = UNSET,
387     SSL_CVERIFY_NONE            = 0,
388     SSL_CVERIFY_OPTIONAL        = 1,
389     SSL_CVERIFY_REQUIRE         = 2,
390     SSL_CVERIFY_OPTIONAL_NO_CA  = 3
391 } ssl_verify_t;
392
393 #define SSL_VERIFY_PEER_STRICT \
394      (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
395
396 #define ssl_verify_error_is_optional(errnum) \
397    ((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) \
398     || (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
399     || (errnum == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) \
400     || (errnum == X509_V_ERR_CERT_UNTRUSTED) \
401     || (errnum == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
402
403 /**
404   * CRL checking mask (mode | flags)
405   */
406 typedef enum {
407     SSL_CRLCHECK_NONE  = (0),
408     SSL_CRLCHECK_LEAF  = (1 << 0),
409     SSL_CRLCHECK_CHAIN = (1 << 1),
410
411 #define SSL_CRLCHECK_FLAGS (~0x3)
412     SSL_CRLCHECK_NO_CRL_FOR_CERT_OK = (1 << 2)
413 } ssl_crlcheck_t;
414
415 /**
416   * OCSP checking mask (mode | flags)
417   */
418 typedef enum {
419     SSL_OCSPCHECK_NONE  = (0),
420     SSL_OCSPCHECK_LEAF  = (1 << 0),
421     SSL_OCSPCHECK_CHAIN = (1 << 1),
422     SSL_OCSPCHECK_NO_OCSP_FOR_CERT_OK = (1 << 2)
423 } ssl_ocspcheck_t;
424
425 /**
426  * Define the SSL pass phrase dialog types
427  */
428 typedef enum {
429     SSL_PPTYPE_UNSET   = UNSET,
430     SSL_PPTYPE_BUILTIN = 0,
431     SSL_PPTYPE_FILTER  = 1,
432     SSL_PPTYPE_PIPE    = 2
433 } ssl_pphrase_t;
434
435 /**
436  * Define the Path Checking modes
437  */
438 #define SSL_PCM_EXISTS     1
439 #define SSL_PCM_ISREG      2
440 #define SSL_PCM_ISDIR      4
441 #define SSL_PCM_ISNONZERO  8
442 typedef unsigned int ssl_pathcheck_t;
443
444 /**
445  * Define the SSL enabled state
446  */
447 typedef enum {
448     SSL_ENABLED_UNSET    = UNSET,
449     SSL_ENABLED_FALSE    = 0,
450     SSL_ENABLED_TRUE     = 1,
451     SSL_ENABLED_OPTIONAL = 3
452 } ssl_enabled_t;
453
454 /**
455  * Define the SSL requirement structure
456  */
457 typedef struct {
458     const char     *cpExpr;
459     ap_expr_info_t *mpExpr;
460 } ssl_require_t;
461
462 /**
463  * Define the SSL random number generator seeding source
464  */
465 typedef enum {
466     SSL_RSCTX_STARTUP = 1,
467     SSL_RSCTX_CONNECT = 2
468 } ssl_rsctx_t;
469 typedef enum {
470     SSL_RSSRC_BUILTIN = 1,
471     SSL_RSSRC_FILE    = 2,
472     SSL_RSSRC_EXEC    = 3,
473     SSL_RSSRC_EGD     = 4
474 } ssl_rssrc_t;
475 typedef struct {
476     ssl_rsctx_t  nCtx;
477     ssl_rssrc_t  nSrc;
478     char        *cpPath;
479     int          nBytes;
480 } ssl_randseed_t;
481
482 /**
483  * Define the structure of an ASN.1 anything
484  */
485 typedef struct {
486     long int       nData;
487     unsigned char *cpData;
488     apr_time_t     source_mtime;
489 } ssl_asn1_t;
490
491 /**
492  * Define the mod_ssl per-module configuration structure
493  * (i.e. the global configuration for each httpd process)
494  */
495
496 typedef struct SSLSrvConfigRec SSLSrvConfigRec;
497 typedef struct SSLDirConfigRec SSLDirConfigRec;
498
499 typedef enum {
500     SSL_SHUTDOWN_TYPE_UNSET,
501     SSL_SHUTDOWN_TYPE_STANDARD,
502     SSL_SHUTDOWN_TYPE_UNCLEAN,
503     SSL_SHUTDOWN_TYPE_ACCURATE
504 } ssl_shutdown_type_e;
505
506 typedef struct {
507     SSL *ssl;
508     const char *client_dn;
509     X509 *client_cert;
510     ssl_shutdown_type_e shutdown_type;
511     const char *verify_info;
512     const char *verify_error;
513     int verify_depth;
514     int is_proxy;
515     int disabled;
516     enum {
517         NON_SSL_OK = 0,        /* is SSL request, or error handling completed */
518         NON_SSL_SEND_REQLINE,  /* Need to send the fake request line */
519         NON_SSL_SEND_HDR_SEP,  /* Need to send the header separator */
520         NON_SSL_SET_ERROR_MSG  /* Need to set the error message */
521     } non_ssl_request;
522
523     /* Track the handshake/renegotiation state for the connection so
524      * that all client-initiated renegotiations can be rejected, as a
525      * partial fix for CVE-2009-3555. */
526     enum {
527         RENEG_INIT = 0, /* Before initial handshake */
528         RENEG_REJECT,   /* After initial handshake; any client-initiated
529                          * renegotiation should be rejected */
530         RENEG_ALLOW,    /* A server-initiated renegotiation is taking
531                          * place (as dictated by configuration) */
532         RENEG_ABORT     /* Renegotiation initiated by client, abort the
533                          * connection */
534     } reneg_state;
535
536     server_rec *server;
537     SSLDirConfigRec *dc;
538     
539     const char *cipher_suite; /* cipher suite used in last reneg */
540     int service_unavailable;  /* thouugh we negotiate SSL, no requests will be served */
541 } SSLConnRec;
542
543 /* BIG FAT WARNING: SSLModConfigRec has unusual memory lifetime: it is
544  * allocated out of the "process" pool and only a single such
545  * structure is created and used for the lifetime of the process.
546  * (The process pool is s->process->pool and is stored in the .pPool
547  * field.)  Most members of this structure are likewise allocated out
548  * of the process pool, but notably sesscache and sesscache_context
549  * are not.
550  *
551  * The structure is treated as mostly immutable after a single config
552  * parse has completed; the post_config hook (ssl_init_Module) flips
553  * the bFixed flag to true and subsequent invocations of the config
554  * callbacks hence do nothing.
555  *
556  * This odd lifetime strategy is used so that encrypted private keys
557  * can be decrypted once at startup and continue to be used across
558  * subsequent server reloads where the interactive password prompt is
559  * not possible.
560
561  * It is really an ABI nightmare waiting to happen since DSOs are
562  * reloaded across restarts, and nothing prevents the struct type
563  * changing across such reloads, yet the cached structure will be
564  * assumed to match regardless.
565  *
566  * This should really be fixed using a smaller structure which only
567  * stores that which is absolutely necessary (the private keys, maybe
568  * the random seed), and have that structure be strictly ABI-versioned
569  * for safety.
570  */
571 typedef struct {
572     pid_t           pid;
573     apr_pool_t     *pPool;
574     BOOL            bFixed;
575
576     /* OpenSSL SSL_SESS_CACHE_* flags: */
577     long            sesscache_mode;
578
579     /* The configured provider, and associated private data
580      * structure. */
581     const ap_socache_provider_t *sesscache;
582     ap_socache_instance_t *sesscache_context;
583
584     apr_global_mutex_t   *pMutex;
585     apr_array_header_t   *aRandSeed;
586     apr_hash_t     *tVHostKeys;
587
588     /* A hash table of pointers to ssl_asn1_t structures.  The structures
589      * are used to store private keys in raw DER format (serialized OpenSSL
590      * PrivateKey structures).  The table is indexed by (vhost-id,
591      * index), for example the string "vhost.example.com:443:0". */
592     apr_hash_t     *tPrivateKey;
593
594 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
595     const char     *szCryptoDevice;
596 #endif
597
598 #ifdef HAVE_OCSP_STAPLING
599     const ap_socache_provider_t *stapling_cache;
600     ap_socache_instance_t *stapling_cache_context;
601     apr_global_mutex_t   *stapling_cache_mutex;
602     apr_global_mutex_t   *stapling_refresh_mutex;
603 #endif
604
605 } SSLModConfigRec;
606
607 /** Structure representing configured filenames for certs and keys for
608  * a given vhost */
609 typedef struct {
610     /* Lists of configured certs and keys for this server */
611     apr_array_header_t *cert_files;
612     apr_array_header_t *key_files;
613
614     /** Certificates which specify the set of CA names which should be
615      * sent in the CertificateRequest message: */
616     const char  *ca_name_path;
617     const char  *ca_name_file;
618     
619     /* TLS service for this server is suspended */
620     int service_unavailable;
621 } modssl_pk_server_t;
622
623 typedef struct {
624     /** proxy can have any number of cert/key pairs */
625     const char  *cert_file;
626     const char  *cert_path;
627     const char  *ca_cert_file;
628     STACK_OF(X509_INFO) *certs; /* Contains End Entity certs */
629     STACK_OF(X509) **ca_certs; /* Contains ONLY chain certs for
630                                 * each item in certs.
631                                 * (ptr to array of ptrs) */
632 } modssl_pk_proxy_t;
633
634 /** stuff related to authentication that can also be per-dir */
635 typedef struct {
636     /** known/trusted CAs */
637     const char  *ca_cert_path;
638     const char  *ca_cert_file;
639
640     const char  *cipher_suite;
641
642     /** for client or downstream server authentication */
643     int          verify_depth;
644     ssl_verify_t verify_mode;
645
646     /** TLSv1.3 has its separate cipher list, separate from the
647      settings for older TLS protocol versions. Since which one takes
648      effect is a matter of negotiation, we need separate settings */
649     const char  *tls13_ciphers;
650 } modssl_auth_ctx_t;
651
652 #ifdef HAVE_TLS_SESSION_TICKETS
653 typedef struct {
654     const char *file_path;
655     unsigned char key_name[16];
656     unsigned char hmac_secret[16];
657     unsigned char aes_key[16];
658 } modssl_ticket_key_t;
659 #endif
660
661 #ifdef HAVE_SSL_CONF_CMD
662 typedef struct {
663     const char *name;
664     const char *value;
665 } ssl_ctx_param_t;
666 #endif
667
668 typedef struct {
669     SSLSrvConfigRec *sc; /** pointer back to server config */
670     SSL_CTX *ssl_ctx;
671
672     /** we are one or the other */
673     modssl_pk_server_t *pks;
674     modssl_pk_proxy_t  *pkp;
675
676 #ifdef HAVE_TLS_SESSION_TICKETS
677     modssl_ticket_key_t *ticket_key;
678 #endif
679
680     ssl_proto_t  protocol;
681     int protocol_set;
682
683     /** config for handling encrypted keys */
684     ssl_pphrase_t pphrase_dialog_type;
685     const char   *pphrase_dialog_path;
686
687     const char  *cert_chain;
688
689     /** certificate revocation list */
690     const char    *crl_path;
691     const char    *crl_file;
692     int            crl_check_mask;
693
694 #ifdef HAVE_OCSP_STAPLING
695     /** OCSP stapling options */
696     BOOL        stapling_enabled;
697     long        stapling_resptime_skew;
698     long        stapling_resp_maxage;
699     int         stapling_cache_timeout;
700     BOOL        stapling_return_errors;
701     BOOL        stapling_fake_trylater;
702     int         stapling_errcache_timeout;
703     apr_interval_time_t stapling_responder_timeout;
704     const char *stapling_force_url;
705 #endif
706
707 #ifdef HAVE_SRP
708     char *srp_vfile;
709     char *srp_unknown_user_seed;
710     SRP_VBASE  *srp_vbase;
711 #endif
712
713     modssl_auth_ctx_t auth;
714
715     int ocsp_mask;
716     BOOL ocsp_force_default; /* true if the default responder URL is
717                               * used regardless of per-cert URL */
718     const char *ocsp_responder; /* default responder URL */
719     long ocsp_resptime_skew;
720     long ocsp_resp_maxage;
721     apr_interval_time_t ocsp_responder_timeout;
722     BOOL ocsp_use_request_nonce;
723     apr_uri_t *proxy_uri;
724
725     BOOL ocsp_noverify; /* true if skipping OCSP certification verification like openssl -noverify */
726     /* Declare variables for using OCSP Responder Certs for OCSP verification */
727     int ocsp_verify_flags; /* Flags to use when verifying OCSP response */
728     const char *ocsp_certs_file; /* OCSP other certificates filename */
729     STACK_OF(X509) *ocsp_certs; /* OCSP other certificates */
730
731 #ifdef HAVE_SSL_CONF_CMD
732     SSL_CONF_CTX *ssl_ctx_config; /* Configuration context */
733     apr_array_header_t *ssl_ctx_param; /* parameters to pass to SSL_CTX */
734 #endif
735
736     BOOL ssl_check_peer_cn;
737     BOOL ssl_check_peer_name;
738     BOOL ssl_check_peer_expire;
739 } modssl_ctx_t;
740
741 struct SSLSrvConfigRec {
742     SSLModConfigRec *mc;
743     ssl_enabled_t    enabled;
744     const char      *vhost_id;
745     int              vhost_id_len;
746     int              session_cache_timeout;
747     BOOL             cipher_server_pref;
748     BOOL             insecure_reneg;
749     modssl_ctx_t    *server;
750 #ifdef HAVE_TLSEXT
751     ssl_enabled_t    strict_sni_vhost_check;
752 #endif
753 #ifdef HAVE_FIPS
754     BOOL             fips;
755 #endif
756 #ifndef OPENSSL_NO_COMP
757     BOOL             compression;
758 #endif
759     BOOL             session_tickets;
760     
761 };
762
763 /**
764  * Define the mod_ssl per-directory configuration structure
765  * (i.e. the local configuration for all &lt;Directory>
766  *  and .htaccess contexts)
767  */
768 struct SSLDirConfigRec {
769     BOOL          bSSLRequired;
770     apr_array_header_t *aRequirement;
771     ssl_opt_t     nOptions;
772     ssl_opt_t     nOptionsAdd;
773     ssl_opt_t     nOptionsDel;
774     const char   *szCipherSuite;
775     ssl_verify_t  nVerifyClient;
776     int           nVerifyDepth;
777     const char   *szUserName;
778     apr_size_t    nRenegBufferSize;
779
780     modssl_ctx_t *proxy;
781     BOOL          proxy_enabled;
782     BOOL          proxy_post_config;
783 };
784
785 typedef struct SSLPolicyRec SSLPolicyRec;
786 struct SSLPolicyRec {
787     const char *name;
788     SSLSrvConfigRec *sc;
789 };
790
791 SSLPolicyRec *ssl_policy_lookup(apr_pool_t *pool, const char *name);
792
793 /**
794  *  function prototypes
795  */
796
797 /**  API glue structures  */
798 extern module AP_MODULE_DECLARE_DATA ssl_module;
799
800 /**  configuration handling   */
801 SSLModConfigRec *ssl_config_global_create(server_rec *);
802 void         ssl_config_global_fix(SSLModConfigRec *);
803 BOOL         ssl_config_global_isfixed(SSLModConfigRec *);
804 void        *ssl_config_server_create(apr_pool_t *, server_rec *);
805 void        *ssl_config_server_merge(apr_pool_t *, void *, void *);
806 void        *ssl_config_perdir_create(apr_pool_t *, char *);
807 void        *ssl_config_perdir_merge(apr_pool_t *, void *, void *);
808 void         ssl_config_proxy_merge(apr_pool_t *,
809                                     SSLDirConfigRec *, SSLDirConfigRec *);
810 const char  *ssl_cmd_SSLPolicyApply(cmd_parms *, void *, const char *);
811 const char  *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, void *, const char *);
812 const char  *ssl_cmd_SSLCryptoDevice(cmd_parms *, void *, const char *);
813 const char  *ssl_cmd_SSLRandomSeed(cmd_parms *, void *, const char *, const char *, const char *);
814 const char  *ssl_cmd_SSLEngine(cmd_parms *, void *, const char *);
815 const char  *ssl_cmd_SSLCipherSuite(cmd_parms *, void *, const char *, const char *);
816 const char  *ssl_cmd_SSLCertificateFile(cmd_parms *, void *, const char *);
817 const char  *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, void *, const char *);
818 const char  *ssl_cmd_SSLCertificateChainFile(cmd_parms *, void *, const char *);
819 const char  *ssl_cmd_SSLCACertificatePath(cmd_parms *, void *, const char *);
820 const char  *ssl_cmd_SSLCACertificateFile(cmd_parms *, void *, const char *);
821 const char  *ssl_cmd_SSLCADNRequestPath(cmd_parms *, void *, const char *);
822 const char  *ssl_cmd_SSLCADNRequestFile(cmd_parms *, void *, const char *);
823 const char  *ssl_cmd_SSLCARevocationPath(cmd_parms *, void *, const char *);
824 const char  *ssl_cmd_SSLCARevocationFile(cmd_parms *, void *, const char *);
825 const char  *ssl_cmd_SSLCARevocationCheck(cmd_parms *, void *, const char *);
826 const char  *ssl_cmd_SSLHonorCipherOrder(cmd_parms *cmd, void *dcfg, int flag);
827 const char  *ssl_cmd_SSLCompression(cmd_parms *, void *, int flag);
828 const char  *ssl_cmd_SSLSessionTickets(cmd_parms *, void *, int flag);
829 const char  *ssl_cmd_SSLVerifyClient(cmd_parms *, void *, const char *);
830 const char  *ssl_cmd_SSLVerifyDepth(cmd_parms *, void *, const char *);
831 const char  *ssl_cmd_SSLSessionCache(cmd_parms *, void *, const char *);
832 const char  *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, void *, const char *);
833 const char  *ssl_cmd_SSLProtocol(cmd_parms *, void *, const char *);
834 const char  *ssl_cmd_SSLOptions(cmd_parms *, void *, const char *);
835 const char  *ssl_cmd_SSLRequireSSL(cmd_parms *, void *);
836 const char  *ssl_cmd_SSLRequire(cmd_parms *, void *, const char *);
837 const char  *ssl_cmd_SSLUserName(cmd_parms *, void *, const char *);
838 const char  *ssl_cmd_SSLRenegBufferSize(cmd_parms *cmd, void *dcfg, const char *arg);
839 const char  *ssl_cmd_SSLStrictSNIVHostCheck(cmd_parms *cmd, void *dcfg, int flag);
840 const char *ssl_cmd_SSLInsecureRenegotiation(cmd_parms *cmd, void *dcfg, int flag);
841
842 const char  *ssl_cmd_SSLProxyEngine(cmd_parms *cmd, void *dcfg, int flag);
843 const char  *ssl_cmd_SSLProxyProtocol(cmd_parms *, void *, const char *);
844 const char  *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, void *, const char *, const char *);
845 const char  *ssl_cmd_SSLProxyVerify(cmd_parms *, void *, const char *);
846 const char  *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, void *, const char *);
847 const char  *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, void *, const char *);
848 const char  *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, void *, const char *);
849 const char  *ssl_cmd_SSLProxyCARevocationPath(cmd_parms *, void *, const char *);
850 const char  *ssl_cmd_SSLProxyCARevocationFile(cmd_parms *, void *, const char *);
851 const char  *ssl_cmd_SSLProxyCARevocationCheck(cmd_parms *, void *, const char *);
852 const char  *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
853 const char  *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
854 const char  *ssl_cmd_SSLProxyMachineCertificateChainFile(cmd_parms *, void *, const char *);
855 #ifdef HAVE_TLS_SESSION_TICKETS
856 const char *ssl_cmd_SSLSessionTicketKeyFile(cmd_parms *cmd, void *dcfg, const char *arg);
857 #endif
858 const char  *ssl_cmd_SSLProxyCheckPeerExpire(cmd_parms *cmd, void *dcfg, int flag);
859 const char  *ssl_cmd_SSLProxyCheckPeerCN(cmd_parms *cmd, void *dcfg, int flag);
860 const char  *ssl_cmd_SSLProxyCheckPeerName(cmd_parms *cmd, void *dcfg, int flag);
861
862 const char *ssl_cmd_SSLOCSPOverrideResponder(cmd_parms *cmd, void *dcfg, int flag);
863 const char *ssl_cmd_SSLOCSPDefaultResponder(cmd_parms *cmd, void *dcfg, const char *arg);
864 const char *ssl_cmd_SSLOCSPResponseTimeSkew(cmd_parms *cmd, void *dcfg, const char *arg);
865 const char *ssl_cmd_SSLOCSPResponseMaxAge(cmd_parms *cmd, void *dcfg, const char *arg);
866 const char *ssl_cmd_SSLOCSPResponderTimeout(cmd_parms *cmd, void *dcfg, const char *arg);
867 const char *ssl_cmd_SSLOCSPUseRequestNonce(cmd_parms *cmd, void *dcfg, int flag);
868 const char *ssl_cmd_SSLOCSPEnable(cmd_parms *cmd, void *dcfg, const char *arg);
869 const char *ssl_cmd_SSLOCSPProxyURL(cmd_parms *cmd, void *dcfg, const char *arg);
870
871 /* Declare OCSP Responder Certificate Verification Directive */
872 const char *ssl_cmd_SSLOCSPNoVerify(cmd_parms *cmd, void *dcfg, int flag);
873 /* Declare OCSP Responder Certificate File Directive */
874 const char *ssl_cmd_SSLOCSPResponderCertificateFile(cmd_parms *cmd, void *dcfg, const char *arg);
875
876 #ifdef HAVE_SSL_CONF_CMD
877 const char *ssl_cmd_SSLOpenSSLConfCmd(cmd_parms *cmd, void *dcfg, const char *arg1, const char *arg2);
878 #endif
879
880 #ifdef HAVE_SRP
881 const char *ssl_cmd_SSLSRPVerifierFile(cmd_parms *cmd, void *dcfg, const char *arg);
882 const char *ssl_cmd_SSLSRPUnknownUserSeed(cmd_parms *cmd, void *dcfg, const char *arg);
883 #endif
884
885 const char *ssl_cmd_SSLFIPS(cmd_parms *cmd, void *dcfg, int flag);
886
887 /**  module initialization  */
888 apr_status_t ssl_init_Module(apr_pool_t *, apr_pool_t *, apr_pool_t *, server_rec *);
889 apr_status_t ssl_init_Engine(server_rec *, apr_pool_t *);
890 apr_status_t ssl_init_ConfigureServer(server_rec *, apr_pool_t *, apr_pool_t *, SSLSrvConfigRec *,
891                                       apr_array_header_t *);
892 apr_status_t ssl_init_CheckServers(server_rec *, apr_pool_t *);
893 int          ssl_proxy_section_post_config(apr_pool_t *p, apr_pool_t *plog,
894                                            apr_pool_t *ptemp, server_rec *s,
895                                            ap_conf_vector_t *section_config);
896 STACK_OF(X509_NAME)
897             *ssl_init_FindCAList(server_rec *, apr_pool_t *, const char *, const char *);
898 void         ssl_init_Child(apr_pool_t *, server_rec *);
899 apr_status_t ssl_init_ModuleKill(void *data);
900
901 /**  Apache API hooks  */
902 int          ssl_hook_Auth(request_rec *);
903 int          ssl_hook_UserCheck(request_rec *);
904 int          ssl_hook_Access(request_rec *);
905 int          ssl_hook_Fixup(request_rec *);
906 int          ssl_hook_ReadReq(request_rec *);
907 int          ssl_hook_Upgrade(request_rec *);
908 void         ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s);
909
910 /** Apache authz provisders */
911 extern const authz_provider ssl_authz_provider_require_ssl;
912 extern const authz_provider ssl_authz_provider_verify_client;
913
914 /**  OpenSSL callbacks */
915 DH          *ssl_callback_TmpDH(SSL *, int, int);
916 int          ssl_callback_SSLVerify(int, X509_STORE_CTX *);
917 int          ssl_callback_SSLVerify_CRL(int, X509_STORE_CTX *, conn_rec *);
918 int          ssl_callback_proxy_cert(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
919 int          ssl_callback_NewSessionCacheEntry(SSL *, SSL_SESSION *);
920 SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *, IDCONST unsigned char *, int, int *);
921 void         ssl_callback_DelSessionCacheEntry(SSL_CTX *, SSL_SESSION *);
922 void         ssl_callback_Info(const SSL *, int, int);
923 #ifdef HAVE_TLSEXT
924 int          ssl_callback_ServerNameIndication(SSL *, int *, modssl_ctx_t *);
925 #endif
926 #ifdef HAVE_TLS_SESSION_TICKETS
927 int         ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
928                                        EVP_CIPHER_CTX *, HMAC_CTX *, int);
929 #endif
930
931 #ifdef HAVE_TLS_ALPN
932 int ssl_callback_alpn_select(SSL *ssl, const unsigned char **out,
933                              unsigned char *outlen, const unsigned char *in,
934                              unsigned int inlen, void *arg);
935 #endif
936
937 /**  Session Cache Support  */
938 apr_status_t ssl_scache_init(server_rec *, apr_pool_t *);
939 void         ssl_scache_status_register(apr_pool_t *p);
940 void         ssl_scache_kill(server_rec *);
941 BOOL         ssl_scache_store(server_rec *, IDCONST UCHAR *, int,
942                               apr_time_t, SSL_SESSION *, apr_pool_t *);
943 SSL_SESSION *ssl_scache_retrieve(server_rec *, IDCONST UCHAR *, int, apr_pool_t *);
944 void         ssl_scache_remove(server_rec *, IDCONST UCHAR *, int,
945                                apr_pool_t *);
946
947 /** OCSP Stapling Support */
948 #ifdef HAVE_OCSP_STAPLING
949 const char *ssl_cmd_SSLStaplingCache(cmd_parms *, void *, const char *);
950 const char *ssl_cmd_SSLUseStapling(cmd_parms *, void *, int);
951 const char *ssl_cmd_SSLStaplingResponseTimeSkew(cmd_parms *, void *, const char *);
952 const char *ssl_cmd_SSLStaplingResponseMaxAge(cmd_parms *, void *, const char *);
953 const char *ssl_cmd_SSLStaplingStandardCacheTimeout(cmd_parms *, void *, const char *);
954 const char *ssl_cmd_SSLStaplingErrorCacheTimeout(cmd_parms *, void *, const char *);
955 const char *ssl_cmd_SSLStaplingReturnResponderErrors(cmd_parms *, void *, int);
956 const char *ssl_cmd_SSLStaplingFakeTryLater(cmd_parms *, void *, int);
957 const char *ssl_cmd_SSLStaplingResponderTimeout(cmd_parms *, void *, const char *);
958 const char *ssl_cmd_SSLStaplingForceURL(cmd_parms *, void *, const char *);
959 apr_status_t modssl_init_stapling(server_rec *, apr_pool_t *, apr_pool_t *, modssl_ctx_t *);
960 void         ssl_stapling_certinfo_hash_init(apr_pool_t *);
961 int          ssl_stapling_init_cert(server_rec *, apr_pool_t *, apr_pool_t *,
962                                     modssl_ctx_t *, X509 *);
963 #endif
964 #ifdef HAVE_SRP
965 int          ssl_callback_SRPServerParams(SSL *, int *, void *);
966 #endif
967
968 /**  I/O  */
969 void         ssl_io_filter_init(conn_rec *, request_rec *r, SSL *);
970 void         ssl_io_filter_register(apr_pool_t *);
971 long         ssl_io_data_cb(BIO *, int, const char *, int, long, long);
972
973 /* ssl_io_buffer_fill fills the setaside buffering of the HTTP request
974  * to allow an SSL renegotiation to take place. */
975 int          ssl_io_buffer_fill(request_rec *r, apr_size_t maxlen);
976
977 /**  PRNG  */
978 int          ssl_rand_seed(server_rec *, apr_pool_t *, ssl_rsctx_t, char *);
979
980 /**  Utility Functions  */
981 char        *ssl_util_vhostid(apr_pool_t *, server_rec *);
982 apr_file_t  *ssl_util_ppopen(server_rec *, apr_pool_t *, const char *,
983                              const char * const *);
984 void         ssl_util_ppclose(server_rec *, apr_pool_t *, apr_file_t *);
985 char        *ssl_util_readfilter(server_rec *, apr_pool_t *, const char *,
986                                  const char * const *);
987 BOOL         ssl_util_path_check(ssl_pathcheck_t, const char *, apr_pool_t *);
988 #if APR_HAS_THREADS && MODSSL_USE_OPENSSL_PRE_1_1_API
989 void         ssl_util_thread_setup(apr_pool_t *);
990 void         ssl_util_thread_id_setup(apr_pool_t *);
991 #endif
992 int          ssl_init_ssl_connection(conn_rec *c, request_rec *r);
993
994 BOOL         ssl_util_vhost_matches(const char *servername, server_rec *s);
995
996 /**  Pass Phrase Support  */
997 apr_status_t ssl_load_encrypted_pkey(server_rec *, apr_pool_t *, int,
998                                      const char *, apr_array_header_t **);
999 /* Load private key from the configured ENGINE, returned as **pkey.
1000  * Errors logged on failure. */
1001 apr_status_t modssl_load_engine_pkey(server_rec *s, apr_pool_t *p,
1002                                      const char *keyid, EVP_PKEY **ppkey);
1003
1004 /**  Diffie-Hellman Parameter Support  */
1005 DH           *ssl_dh_GetParamFromFile(const char *);
1006 #ifdef HAVE_ECC
1007 EC_GROUP     *ssl_ec_GetParamFromFile(const char *);
1008 #endif
1009
1010 unsigned char *ssl_asn1_table_set(apr_hash_t *table,
1011                                   const char *key,
1012                                   long int length);
1013
1014 ssl_asn1_t *ssl_asn1_table_get(apr_hash_t *table,
1015                                const char *key);
1016
1017 void ssl_asn1_table_unset(apr_hash_t *table,
1018                           const char *key);
1019
1020 /**  Mutex Support  */
1021 int          ssl_mutex_init(server_rec *, apr_pool_t *);
1022 int          ssl_mutex_reinit(server_rec *, apr_pool_t *);
1023 int          ssl_mutex_on(server_rec *);
1024 int          ssl_mutex_off(server_rec *);
1025
1026 int          ssl_stapling_mutex_reinit(server_rec *, apr_pool_t *);
1027
1028 /* mutex type names for Mutex directive */
1029 #define SSL_CACHE_MUTEX_TYPE    "ssl-cache"
1030 #define SSL_STAPLING_CACHE_MUTEX_TYPE "ssl-stapling"
1031 #define SSL_STAPLING_REFRESH_MUTEX_TYPE "ssl-stapling-refresh"
1032
1033 apr_status_t ssl_die(server_rec *);
1034
1035 /**  Logfile Support  */
1036 void         ssl_log_ssl_error(const char *, int, int, server_rec *);
1037
1038 /* ssl_log_xerror, ssl_log_cxerror and ssl_log_rxerror are wrappers for the
1039  * respective ap_log_*error functions and take a certificate as an
1040  * additional argument (whose details are appended to the log message).
1041  * The other arguments are interpreted exactly as with their ap_log_*error
1042  * counterparts. */
1043 void ssl_log_xerror(const char *file, int line, int level,
1044                     apr_status_t rv, apr_pool_t *p, server_rec *s,
1045                     X509 *cert, const char *format, ...)
1046     __attribute__((format(printf,8,9)));
1047
1048 void ssl_log_cxerror(const char *file, int line, int level,
1049                      apr_status_t rv, conn_rec *c, X509 *cert,
1050                      const char *format, ...)
1051     __attribute__((format(printf,7,8)));
1052
1053 void ssl_log_rxerror(const char *file, int line, int level,
1054                      apr_status_t rv, request_rec *r, X509 *cert,
1055                      const char *format, ...)
1056     __attribute__((format(printf,7,8)));
1057
1058 #define SSLLOG_MARK              __FILE__,__LINE__
1059
1060 /**  Variables  */
1061
1062 /* Register variables for the lifetime of the process pool 'p'. */
1063 void         ssl_var_register(apr_pool_t *p);
1064 char        *ssl_var_lookup(apr_pool_t *, server_rec *, conn_rec *, request_rec *, char *);
1065 apr_array_header_t *ssl_ext_list(apr_pool_t *p, conn_rec *c, int peer, const char *extension);
1066
1067 void         ssl_var_log_config_register(apr_pool_t *p);
1068
1069 /* Extract SSL_*_DN_* variables into table 't' from SSL object 'ssl',
1070  * allocating from 'p': */
1071 void modssl_var_extract_dns(apr_table_t *t, SSL *ssl, apr_pool_t *p);
1072
1073 /* Extract SSL_*_SAN_* variables (subjectAltName entries) into table 't'
1074  * from SSL object 'ssl', allocating from 'p'. */
1075 void modssl_var_extract_san_entries(apr_table_t *t, SSL *ssl, apr_pool_t *p);
1076
1077 #ifndef OPENSSL_NO_OCSP
1078 /* Perform OCSP validation of the current cert in the given context.
1079  * Returns non-zero on success or zero on failure.  On failure, the
1080  * context error code is set. */
1081 int modssl_verify_ocsp(X509_STORE_CTX *ctx, SSLSrvConfigRec *sc,
1082                        server_rec *s, conn_rec *c, apr_pool_t *pool);
1083
1084 /* OCSP helper interface; dispatches the given OCSP request to the
1085  * responder at the given URI.  Returns the decoded OCSP response
1086  * object, or NULL on error (in which case, errors will have been
1087  * logged).  Pool 'p' is used for temporary allocations. */
1088 OCSP_RESPONSE *modssl_dispatch_ocsp_request(const apr_uri_t *uri,
1089                                             apr_interval_time_t timeout,
1090                                             OCSP_REQUEST *request,
1091                                             conn_rec *c, apr_pool_t *p);
1092
1093 /* Initialize OCSP trusted certificate list */
1094 void ssl_init_ocsp_certificates(server_rec *s, modssl_ctx_t *mctx);
1095
1096 #endif
1097
1098 /* Retrieve DH parameters for given key length.  Return value should
1099  * be treated as unmutable, since it is stored in process-global
1100  * memory. */
1101 DH *modssl_get_dh_params(unsigned keylen);
1102
1103 /* Returns non-zero if the request was made over SSL/TLS.  If sslconn
1104  * is non-NULL and the request is using SSL/TLS, sets *sslconn to the
1105  * corresponding SSLConnRec structure for the connection. */
1106 int modssl_request_is_tls(const request_rec *r, SSLConnRec **sslconn);
1107
1108 /* Returns non-zero if the cert/key filename should be handled through
1109  * the configure ENGINE. */
1110 int modssl_is_engine_key(const char *name);
1111
1112 #if HAVE_VALGRIND
1113 extern int ssl_running_on_valgrind;
1114 #endif
1115
1116 int ssl_is_challenge(conn_rec *c, const char *servername, 
1117                      X509 **pcert, EVP_PKEY **pkey);
1118
1119 #endif /* SSL_PRIVATE_H */
1120 /** @} */
1121