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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @brief Internal interfaces private to mod_ssl.
24 * @defgroup MOD_SSL_PRIVATE Private
31 #include "http_config.h"
32 #include "http_core.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"
44 #include "apr_strings.h"
45 #define APR_WANT_STRFUNC
46 #define APR_WANT_MEMFUNC
48 #include "apr_tables.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"
57 /* The #ifdef macros are only defined AFTER including the above
58 * therefore we cannot include these system files at the top :-(
60 #ifdef APR_HAVE_STDLIB_H
63 #if APR_HAVE_SYS_TIME_H
67 #include <unistd.h> /* needed for STDIN_FILENO et.al., at least on FreeBSD */
79 #define BOOL unsigned int
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>
96 /* Avoid tripping over an engine build installed globally and detected
97 * when the user points at an explicit non-engine flavor of OpenSSL
99 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
100 #include <openssl/engine.h>
103 #if (OPENSSL_VERSION_NUMBER < 0x0090700f)
104 #error mod_ssl requires OpenSSL 0.9.7 or later
107 /* ...shifting sands of OpenSSL... */
108 #if (OPENSSL_VERSION_NUMBER >= 0x0090707f)
109 #define MODSSL_D2I_SSL_SESSION_CONST const
111 #define MODSSL_D2I_SSL_SESSION_CONST
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
120 #define MODSSL_D2I_ASN1_type_bytes_CONST
121 #define MODSSL_D2I_PrivateKey_CONST
122 #define MODSSL_D2I_X509_CONST
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
133 #if (OPENSSL_VERSION_NUMBER >= 0x009080a0) && defined(OPENSSL_FIPS)
137 #if (OPENSSL_VERSION_NUMBER >= 0x10000000)
138 #define MODSSL_SSL_CIPHER_CONST const
139 #define MODSSL_SSL_METHOD_CONST const
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
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
154 #ifndef OPENSSL_NO_TLSEXT
155 #ifndef SSL_CTRL_SET_TLSEXT_HOSTNAME
156 #define OPENSSL_NO_TLSEXT
160 #ifndef OPENSSL_NO_TLSEXT
161 #ifdef SSL_CTX_set_tlsext_ticket_key_cb
162 #define HAVE_TLSEXT_TICKETS
166 /* mod_ssl headers */
167 #include "ssl_util_ssl.h"
169 APLOG_USE_MODULE(ssl);
172 * Provide reasonable default for some defines
175 #define PFALSE ((void *)FALSE)
178 #define PTRUE ((void *)TRUE)
188 #define RAND_MAX INT_MAX
192 * Provide reasonable defines for some types
195 #define UCHAR unsigned char
199 * Provide useful shorthands
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)
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)
211 #define strIsEmpty(s) (s == NULL || s[0] == NUL)
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))
225 #define myCtxVarSet(mc,num,val) mc->rCtx.pV##num = val
226 #define myCtxVarGet(mc,num,type) (type)(mc->rCtx.pV##num)
229 * Defaults for the configuration
231 #ifndef SSL_SESSION_CACHE_TIMEOUT
232 #define SSL_SESSION_CACHE_TIMEOUT 300
235 /* Default setting for per-dir reneg buffer. */
236 #ifndef DEFAULT_RENEG_BUFFER_SIZE
237 #define DEFAULT_RENEG_BUFFER_SIZE (128 * 1024)
240 /* Default for OCSP response validity */
241 #ifndef DEFAULT_OCSP_MAX_SKEW
242 #define DEFAULT_OCSP_MAX_SKEW (60 * 5)
245 /* Default timeout for OCSP queries */
246 #ifndef DEFAULT_OCSP_TIMEOUT
247 #define DEFAULT_OCSP_TIMEOUT 10
251 * Define the certificate algorithm types
254 typedef int ssl_algo_t;
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)
263 #define SSL_ALGO_ALL (SSL_ALGO_RSA|SSL_ALGO_DSA)
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)
272 #define SSL_AIDX_MAX (2)
277 * Define IDs for the temporary RSA keys and DH params
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)
287 * Define the SSL options
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;
300 * Define the SSL Protocol options
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;
310 * Define the SSL verify levels
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
320 #define SSL_VERIFY_PEER_STRICT \
321 (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
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))
334 SSL_CRLCHECK_UNSET = UNSET,
335 SSL_CRLCHECK_NONE = 0,
336 SSL_CRLCHECK_LEAF = 1,
337 SSL_CRLCHECK_CHAIN = 2
341 * Define the SSL pass phrase dialog types
344 SSL_PPTYPE_UNSET = UNSET,
345 SSL_PPTYPE_BUILTIN = 0,
346 SSL_PPTYPE_FILTER = 1,
351 * Define the Path Checking modes
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;
360 * Define the SSL enabled state
363 SSL_ENABLED_UNSET = UNSET,
364 SSL_ENABLED_FALSE = 0,
365 SSL_ENABLED_TRUE = 1,
366 SSL_ENABLED_OPTIONAL = 3
370 * Define the SSL requirement structure
374 ap_expr_info_t *mpExpr;
378 * Define the SSL random number generator seeding source
381 SSL_RSCTX_STARTUP = 1,
382 SSL_RSCTX_CONNECT = 2
385 SSL_RSSRC_BUILTIN = 1,
398 * Define the structure of an ASN.1 anything
402 unsigned char *cpData;
403 apr_time_t source_mtime;
407 * Define the mod_ssl per-module configuration structure
408 * (i.e. the global configuration for each httpd process)
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;
420 const char *client_dn;
422 ssl_shutdown_type_e shutdown_type;
423 const char *verify_info;
424 const char *verify_error;
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. */
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
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
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.
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
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.
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
479 /* OpenSSL SSL_SESS_CACHE_* flags: */
482 /* The configured provider, and associated private data
484 const ap_socache_provider_t *sesscache;
485 ap_socache_instance_t *sesscache_context;
487 apr_global_mutex_t *pMutex;
488 apr_array_header_t *aRandSeed;
489 apr_hash_t *tVHostKeys;
490 void *pTmpKeys[SSL_TMP_KEY_MAX];
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;
501 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
502 const char *szCryptoDevice;
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;
512 void *pV1, *pV2, *pV3, *pV4, *pV5, *pV6, *pV7, *pV8, *pV9, *pV10;
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. */
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
529 X509 *certs[SSL_AIDX_MAX];
530 EVP_PKEY *keys[SSL_AIDX_MAX];
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;
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) */
549 /** stuff related to authentication that can also be per-dir */
551 /** known/trusted CAs */
552 const char *ca_cert_path;
553 const char *ca_cert_file;
555 const char *cipher_suite;
557 /** for client or downstream server authentication */
559 ssl_verify_t verify_mode;
563 #ifdef HAVE_TLSEXT_TICKETS
565 /* 48 bytes: 16 for keyname, 16 for HMAC secret, 16 for AES private key */
566 #define TLSEXT_TICKET_KEYLEN (48)
569 /* Human readable name, used in the configuration */
570 const char *conf_name;
572 unsigned char hmac_secret[16];
573 unsigned char aes_key[16];
577 typedef struct SSLSrvConfigRec SSLSrvConfigRec;
580 SSLSrvConfigRec *sc; /** pointer back to server config */
583 /** we are one or the other */
584 modssl_pk_server_t *pks;
585 modssl_pk_proxy_t *pkp;
587 ssl_proto_t protocol;
589 /** config for handling encrypted keys */
590 ssl_pphrase_t pphrase_dialog_type;
591 const char *pphrase_dialog_path;
593 const char *cert_chain;
596 /** certificate revocation list */
597 const char *crl_path;
598 const char *crl_file;
599 ssl_crlcheck_t crl_check_mode;
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;
614 modssl_auth_ctx_t auth;
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;
626 struct SSLSrvConfigRec {
628 ssl_enabled_t enabled;
630 const char *vhost_id;
632 int session_cache_timeout;
633 BOOL cipher_server_pref;
635 modssl_ctx_t *server;
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;
645 #ifdef HAVE_TLSEXT_TICKETS
646 const char *default_ticket_name;
647 modssl_ticket_t* default_ticket;
648 apr_array_header_t* tickets;
653 * Define the mod_ssl per-directory configuration structure
654 * (i.e. the local configuration for all <Directory>
655 * and .htaccess contexts)
659 apr_array_header_t *aRequirement;
661 ssl_opt_t nOptionsAdd;
662 ssl_opt_t nOptionsDel;
663 const char *szCipherSuite;
664 ssl_verify_t nVerifyClient;
666 const char *szCACertificatePath;
667 const char *szCACertificateFile;
668 const char *szUserName;
669 apr_size_t nRenegBufferSize;
673 * function prototypes
676 /** API glue structures */
677 extern module AP_MODULE_DECLARE_DATA ssl_module;
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);
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);
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);
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);
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 *);
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);
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);
763 /** Apache authz provisders */
764 extern const authz_provider ssl_authz_provider_require_ssl;
765 extern const authz_provider ssl_authz_provider_verify_client;
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);
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 *);
784 #ifdef HAVE_TLSEXT_TICKETS
785 int ssl_callback_tlsext_tickets(SSL *ssl,
786 unsigned char *keyname,
788 EVP_CIPHER_CTX *cipher_ctx,
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,
804 int ssl_proxy_enable(conn_rec *c);
805 int ssl_engine_disable(conn_rec *c);
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);
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);
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);
834 int ssl_rand_seed(server_rec *, apr_pool_t *, ssl_rsctx_t, char *);
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);
849 /** Pass Phrase Support */
850 void ssl_pphrase_Handle(server_rec *, apr_pool_t *);
852 /** Diffie-Hellman Parameter Support */
853 DH *ssl_dh_GetTmpParam(int);
854 DH *ssl_dh_GetParamFromFile(char *);
856 unsigned char *ssl_asn1_table_set(apr_hash_t *table,
860 ssl_asn1_t *ssl_asn1_table_get(apr_hash_t *table,
863 void ssl_asn1_table_unset(apr_hash_t *table,
866 const char *ssl_asn1_keystr(int keytype);
868 const char *ssl_asn1_table_keyfmt(apr_pool_t *p,
872 STACK_OF(X509) *ssl_read_pkcs7(server_rec *s, const char *pkcs7);
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 *);
880 int ssl_stapling_mutex_reinit(server_rec *, apr_pool_t *);
882 /* mutex type names for Mutex directive */
883 #define SSL_CACHE_MUTEX_TYPE "ssl-cache"
884 #define SSL_STAPLING_MUTEX_TYPE "ssl-stapling"
886 /** Logfile Support */
888 void ssl_log_ssl_error(const char *, int, int, server_rec *);
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
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)));
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)));
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)));
910 #define SSLLOG_MARK __FILE__,__LINE__
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);
919 void ssl_var_log_config_register(apr_pool_t *p);
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);
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);
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);
942 #endif /* SSL_PRIVATE_H */