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