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/opensslv.h>
86 #if (OPENSSL_VERSION_NUMBER >= 0x10001000)
87 /* must be defined before including ssl.h */
88 #define OPENSSL_NO_SSL_INTERN
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>
101 /* Avoid tripping over an engine build installed globally and detected
102 * when the user points at an explicit non-engine flavor of OpenSSL
104 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
105 #include <openssl/engine.h>
108 #if (OPENSSL_VERSION_NUMBER < 0x0090700f)
109 #error mod_ssl requires OpenSSL 0.9.7 or later
112 /* ...shifting sands of OpenSSL... */
113 #if (OPENSSL_VERSION_NUMBER >= 0x0090707f)
114 #define MODSSL_D2I_SSL_SESSION_CONST const
116 #define MODSSL_D2I_SSL_SESSION_CONST
119 #if (OPENSSL_VERSION_NUMBER >= 0x00908000)
120 #define HAVE_GENERATE_EX
121 #define MODSSL_D2I_ASN1_type_bytes_CONST const
122 #define MODSSL_D2I_PrivateKey_CONST const
123 #define MODSSL_D2I_X509_CONST const
125 #define MODSSL_D2I_ASN1_type_bytes_CONST
126 #define MODSSL_D2I_PrivateKey_CONST
127 #define MODSSL_D2I_X509_CONST
130 #if OPENSSL_VERSION_NUMBER >= 0x00908080 && !defined(OPENSSL_NO_OCSP) \
131 && !defined(OPENSSL_NO_TLSEXT)
132 #define HAVE_OCSP_STAPLING
133 #if (OPENSSL_VERSION_NUMBER < 0x10000000)
134 #define sk_OPENSSL_STRING_pop sk_pop
138 #if (OPENSSL_VERSION_NUMBER >= 0x009080a0) && defined(OPENSSL_FIPS)
142 #if OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_NEXTPROTONEG) \
143 && !defined(OPENSSL_NO_TLSEXT)
147 #ifdef SSL_CONF_FLAG_FILE
148 #define HAVE_SSL_CONF_CMD
151 #if (OPENSSL_VERSION_NUMBER >= 0x10000000)
152 #define MODSSL_SSL_CIPHER_CONST const
153 #define MODSSL_SSL_METHOD_CONST const
155 #define MODSSL_SSL_CIPHER_CONST
156 #define MODSSL_SSL_METHOD_CONST
157 /* ECC support came along in OpenSSL 1.0.0 */
158 #define OPENSSL_NO_EC
161 #ifndef PEM_F_DEF_CALLBACK
162 #ifdef PEM_F_PEM_DEF_CALLBACK
163 /** In OpenSSL 0.9.8 PEM_F_DEF_CALLBACK was renamed */
164 #define PEM_F_DEF_CALLBACK PEM_F_PEM_DEF_CALLBACK
168 #ifndef OPENSSL_NO_TLSEXT
169 #ifndef SSL_CTRL_SET_TLSEXT_HOSTNAME
170 #define OPENSSL_NO_TLSEXT
174 #ifndef OPENSSL_NO_TLSEXT
175 #ifdef SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB
176 #define HAVE_TLS_SESSION_TICKETS
177 #define TLSEXT_TICKET_KEY_LEN 48
178 #ifndef tlsext_tick_md
179 #ifdef OPENSSL_NO_SHA256
180 #define tlsext_tick_md EVP_sha1
182 #define tlsext_tick_md EVP_sha256
188 #ifdef SSL_OP_NO_TLSv1_2
192 #if !defined(OPENSSL_NO_COMP) && !defined(SSL_OP_NO_COMPRESSION) \
193 && OPENSSL_VERSION_NUMBER < 0x00908000L
194 #define OPENSSL_NO_COMP
197 /* SRP support came in OpenSSL 1.0.1 */
198 #ifndef OPENSSL_NO_SRP
199 #ifdef SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB
200 #include <openssl/srp.h>
202 #define OPENSSL_NO_SRP
206 /* mod_ssl headers */
207 #include "ssl_util_ssl.h"
209 APLOG_USE_MODULE(ssl);
212 * Provide reasonable default for some defines
215 #define PFALSE ((void *)FALSE)
218 #define PTRUE ((void *)TRUE)
228 #define RAND_MAX INT_MAX
232 * Provide reasonable defines for some types
235 #define UCHAR unsigned char
239 * Provide useful shorthands
241 #define strEQ(s1,s2) (strcmp(s1,s2) == 0)
242 #define strNE(s1,s2) (strcmp(s1,s2) != 0)
243 #define strEQn(s1,s2,n) (strncmp(s1,s2,n) == 0)
244 #define strNEn(s1,s2,n) (strncmp(s1,s2,n) != 0)
246 #define strcEQ(s1,s2) (strcasecmp(s1,s2) == 0)
247 #define strcNE(s1,s2) (strcasecmp(s1,s2) != 0)
248 #define strcEQn(s1,s2,n) (strncasecmp(s1,s2,n) == 0)
249 #define strcNEn(s1,s2,n) (strncasecmp(s1,s2,n) != 0)
251 #define strIsEmpty(s) (s == NULL || s[0] == NUL)
253 #define myConnConfig(c) \
254 (SSLConnRec *)ap_get_module_config(c->conn_config, &ssl_module)
255 #define myCtxConfig(sslconn, sc) (sslconn->is_proxy ? sc->proxy : sc->server)
256 #define myConnConfigSet(c, val) \
257 ap_set_module_config(c->conn_config, &ssl_module, val)
258 #define mySrvConfig(srv) (SSLSrvConfigRec *)ap_get_module_config(srv->module_config, &ssl_module)
259 #define myDirConfig(req) (SSLDirConfigRec *)ap_get_module_config(req->per_dir_config, &ssl_module)
260 #define myModConfig(srv) (mySrvConfig((srv)))->mc
261 #define mySrvFromConn(c) (myConnConfig(c))->server
262 #define mySrvConfigFromConn(c) mySrvConfig(mySrvFromConn(c))
263 #define myModConfigFromConn(c) myModConfig(mySrvFromConn(c))
265 #define myCtxVarSet(mc,num,val) mc->rCtx.pV##num = val
266 #define myCtxVarGet(mc,num,type) (type)(mc->rCtx.pV##num)
269 * Defaults for the configuration
271 #ifndef SSL_SESSION_CACHE_TIMEOUT
272 #define SSL_SESSION_CACHE_TIMEOUT 300
275 /* Default setting for per-dir reneg buffer. */
276 #ifndef DEFAULT_RENEG_BUFFER_SIZE
277 #define DEFAULT_RENEG_BUFFER_SIZE (128 * 1024)
280 /* Default for OCSP response validity */
281 #ifndef DEFAULT_OCSP_MAX_SKEW
282 #define DEFAULT_OCSP_MAX_SKEW (60 * 5)
285 /* Default timeout for OCSP queries */
286 #ifndef DEFAULT_OCSP_TIMEOUT
287 #define DEFAULT_OCSP_TIMEOUT 10
291 * Define the certificate algorithm types
294 typedef int ssl_algo_t;
296 #define SSL_ALGO_UNKNOWN (0)
297 #define SSL_ALGO_RSA (1<<0)
298 #define SSL_ALGO_DSA (1<<1)
299 #ifndef OPENSSL_NO_EC
300 #define SSL_ALGO_ECC (1<<2)
301 #define SSL_ALGO_ALL (SSL_ALGO_RSA|SSL_ALGO_DSA|SSL_ALGO_ECC)
303 #define SSL_ALGO_ALL (SSL_ALGO_RSA|SSL_ALGO_DSA)
306 #define SSL_AIDX_RSA (0)
307 #define SSL_AIDX_DSA (1)
308 #ifndef OPENSSL_NO_EC
309 #define SSL_AIDX_ECC (2)
310 #define SSL_AIDX_MAX (3)
312 #define SSL_AIDX_MAX (2)
317 * Define IDs for the temporary RSA keys and DH params
320 #define SSL_TMP_KEY_RSA_512 (0)
321 #define SSL_TMP_KEY_RSA_1024 (1)
322 #define SSL_TMP_KEY_DH_512 (2)
323 #define SSL_TMP_KEY_DH_1024 (3)
324 #ifndef OPENSSL_NO_EC
325 #define SSL_TMP_KEY_EC_256 (4)
326 #define SSL_TMP_KEY_MAX (5)
328 #define SSL_TMP_KEY_MAX (4)
332 * Define the SSL options
334 #define SSL_OPT_NONE (0)
335 #define SSL_OPT_RELSET (1<<0)
336 #define SSL_OPT_STDENVVARS (1<<1)
337 #define SSL_OPT_EXPORTCERTDATA (1<<3)
338 #define SSL_OPT_FAKEBASICAUTH (1<<4)
339 #define SSL_OPT_STRICTREQUIRE (1<<5)
340 #define SSL_OPT_OPTRENEGOTIATE (1<<6)
341 #define SSL_OPT_LEGACYDNFORMAT (1<<7)
342 typedef int ssl_opt_t;
345 * Define the SSL Protocol options
347 #define SSL_PROTOCOL_NONE (0)
348 #define SSL_PROTOCOL_SSLV2 (1<<0)
349 #define SSL_PROTOCOL_SSLV3 (1<<1)
350 #define SSL_PROTOCOL_TLSV1 (1<<2)
352 #define SSL_PROTOCOL_TLSV1_1 (1<<3)
353 #define SSL_PROTOCOL_TLSV1_2 (1<<4)
354 #define SSL_PROTOCOL_ALL (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1| \
355 SSL_PROTOCOL_TLSV1_1|SSL_PROTOCOL_TLSV1_2)
357 #define SSL_PROTOCOL_ALL (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1)
359 typedef int ssl_proto_t;
362 * Define the SSL verify levels
365 SSL_CVERIFY_UNSET = UNSET,
366 SSL_CVERIFY_NONE = 0,
367 SSL_CVERIFY_OPTIONAL = 1,
368 SSL_CVERIFY_REQUIRE = 2,
369 SSL_CVERIFY_OPTIONAL_NO_CA = 3
372 #define SSL_VERIFY_PEER_STRICT \
373 (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
375 #define ssl_verify_error_is_optional(errnum) \
376 ((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) \
377 || (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
378 || (errnum == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) \
379 || (errnum == X509_V_ERR_CERT_UNTRUSTED) \
380 || (errnum == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
386 SSL_CRLCHECK_UNSET = UNSET,
387 SSL_CRLCHECK_NONE = 0,
388 SSL_CRLCHECK_LEAF = 1,
389 SSL_CRLCHECK_CHAIN = 2
393 * Define the SSL pass phrase dialog types
396 SSL_PPTYPE_UNSET = UNSET,
397 SSL_PPTYPE_BUILTIN = 0,
398 SSL_PPTYPE_FILTER = 1,
403 * Define the Path Checking modes
405 #define SSL_PCM_EXISTS 1
406 #define SSL_PCM_ISREG 2
407 #define SSL_PCM_ISDIR 4
408 #define SSL_PCM_ISNONZERO 8
409 typedef unsigned int ssl_pathcheck_t;
412 * Define the SSL enabled state
415 SSL_ENABLED_UNSET = UNSET,
416 SSL_ENABLED_FALSE = 0,
417 SSL_ENABLED_TRUE = 1,
418 SSL_ENABLED_OPTIONAL = 3
422 * Define the SSL requirement structure
426 ap_expr_info_t *mpExpr;
430 * Define the SSL random number generator seeding source
433 SSL_RSCTX_STARTUP = 1,
434 SSL_RSCTX_CONNECT = 2
437 SSL_RSSRC_BUILTIN = 1,
450 * Define the structure of an ASN.1 anything
454 unsigned char *cpData;
455 apr_time_t source_mtime;
459 * Define the mod_ssl per-module configuration structure
460 * (i.e. the global configuration for each httpd process)
464 SSL_SHUTDOWN_TYPE_UNSET,
465 SSL_SHUTDOWN_TYPE_STANDARD,
466 SSL_SHUTDOWN_TYPE_UNCLEAN,
467 SSL_SHUTDOWN_TYPE_ACCURATE
468 } ssl_shutdown_type_e;
472 const char *client_dn;
474 ssl_shutdown_type_e shutdown_type;
475 const char *verify_info;
476 const char *verify_error;
481 NON_SSL_OK = 0, /* is SSL request, or error handling completed */
482 NON_SSL_SEND_HDR_SEP, /* Need to send the header separator */
483 NON_SSL_SET_ERROR_MSG /* Need to set the error message */
486 /* Track the handshake/renegotiation state for the connection so
487 * that all client-initiated renegotiations can be rejected, as a
488 * partial fix for CVE-2009-3555. */
490 RENEG_INIT = 0, /* Before initial handshake */
491 RENEG_REJECT, /* After initial handshake; any client-initiated
492 * renegotiation should be rejected */
493 RENEG_ALLOW, /* A server-initated renegotiation is taking
494 * place (as dictated by configuration) */
495 RENEG_ABORT /* Renegotiation initiated by client, abort the
502 /* BIG FAT WARNING: SSLModConfigRec has unusual memory lifetime: it is
503 * allocated out of the "process" pool and only a single such
504 * structure is created and used for the lifetime of the process.
505 * (The process pool is s->process->pool and is stored in the .pPool
506 * field.) Most members of this structure are likewise allocated out
507 * of the process pool, but notably sesscache and sesscache_context
510 * The structure is treated as mostly immutable after a single config
511 * parse has completed; the post_config hook (ssl_init_Module) flips
512 * the bFixed flag to true and subsequent invocations of the config
513 * callbacks hence do nothing.
515 * This odd lifetime strategy is used so that encrypted private keys
516 * can be decrypted once at startup and continue to be used across
517 * subsequent server reloads where the interactive password prompt is
520 * It is really an ABI nightmare waiting to happen since DSOs are
521 * reloaded across restarts, and nothing prevents the struct type
522 * changing across such reloads, yet the cached structure will be
523 * assumed to match regardless.
525 * This should really be fixed using a smaller structure which only
526 * stores that which is absolutely necessary (the private keys, maybe
527 * the random seed), and have that structure be strictly ABI-versioned
535 /* OpenSSL SSL_SESS_CACHE_* flags: */
538 /* The configured provider, and associated private data
540 const ap_socache_provider_t *sesscache;
541 ap_socache_instance_t *sesscache_context;
543 apr_global_mutex_t *pMutex;
544 apr_array_header_t *aRandSeed;
545 apr_hash_t *tVHostKeys;
546 void *pTmpKeys[SSL_TMP_KEY_MAX];
548 /* Two hash tables of pointers to ssl_asn1_t structures. The
549 * structures are used to store certificates and private keys
550 * respectively, in raw DER format (serialized OpenSSL X509 and
551 * PrivateKey structures). The tables are indexed by (vhost-id,
552 * algorithm type) using the function ssl_asn1_table_keyfmt(); for
553 * example the string "vhost.example.com:443:RSA". */
554 apr_hash_t *tPublicCert;
555 apr_hash_t *tPrivateKey;
557 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
558 const char *szCryptoDevice;
561 #ifdef HAVE_OCSP_STAPLING
562 const ap_socache_provider_t *stapling_cache;
563 ap_socache_instance_t *stapling_cache_context;
564 apr_global_mutex_t *stapling_mutex;
568 void *pV1, *pV2, *pV3, *pV4, *pV5, *pV6, *pV7, *pV8, *pV9, *pV10;
572 /** Structure representing configured filenames for certs and keys for
573 * a given vhost, and the corresponding in-memory structures once the
574 * files are parsed. */
576 /* Lists of configured certs and keys for this server; from index
577 * 0 up to SSL_AIDX_MAX-1 or the first NULL pointer. Note that
578 * these arrays are NOT indexed by algorithm type, they are simply
579 * unordered lists. */
580 const char *cert_files[SSL_AIDX_MAX];
581 const char *key_files[SSL_AIDX_MAX];
582 /* Loaded certs and keys; these arrays ARE indexed by the
583 * algorithm type, i.e. keys[SSL_AIDX_RSA] maps to the RSA
585 X509 *certs[SSL_AIDX_MAX];
586 EVP_PKEY *keys[SSL_AIDX_MAX];
588 /** Certificates which specify the set of CA names which should be
589 * sent in the CertificateRequest message: */
590 const char *ca_name_path;
591 const char *ca_name_file;
592 } modssl_pk_server_t;
595 /** proxy can have any number of cert/key pairs */
596 const char *cert_file;
597 const char *cert_path;
598 const char *ca_cert_file;
599 STACK_OF(X509_INFO) *certs; /* Contains End Entity certs */
600 STACK_OF(X509) **ca_certs; /* Contains ONLY chain certs for
601 * each item in certs.
602 * (ptr to array of ptrs) */
605 /** stuff related to authentication that can also be per-dir */
607 /** known/trusted CAs */
608 const char *ca_cert_path;
609 const char *ca_cert_file;
611 const char *cipher_suite;
613 /** for client or downstream server authentication */
615 ssl_verify_t verify_mode;
618 #ifdef HAVE_TLS_SESSION_TICKETS
620 const char *file_path;
621 unsigned char key_name[16];
622 unsigned char hmac_secret[16];
623 unsigned char aes_key[16];
624 } modssl_ticket_key_t;
627 #ifdef HAVE_SSL_CONF_CMD
634 typedef struct SSLSrvConfigRec SSLSrvConfigRec;
637 SSLSrvConfigRec *sc; /** pointer back to server config */
640 /** we are one or the other */
641 modssl_pk_server_t *pks;
642 modssl_pk_proxy_t *pkp;
644 #ifdef HAVE_TLS_SESSION_TICKETS
645 modssl_ticket_key_t *ticket_key;
648 ssl_proto_t protocol;
650 /** config for handling encrypted keys */
651 ssl_pphrase_t pphrase_dialog_type;
652 const char *pphrase_dialog_path;
654 const char *cert_chain;
657 /** certificate revocation list */
658 const char *crl_path;
659 const char *crl_file;
660 ssl_crlcheck_t crl_check_mode;
662 #ifdef HAVE_OCSP_STAPLING
663 /** OCSP stapling options */
664 BOOL stapling_enabled;
665 long stapling_resptime_skew;
666 long stapling_resp_maxage;
667 int stapling_cache_timeout;
668 BOOL stapling_return_errors;
669 BOOL stapling_fake_trylater;
670 int stapling_errcache_timeout;
671 apr_interval_time_t stapling_responder_timeout;
672 const char *stapling_force_url;
675 #ifndef OPENSSL_NO_SRP
677 char *srp_unknown_user_seed;
678 SRP_VBASE *srp_vbase;
681 modssl_auth_ctx_t auth;
683 BOOL ocsp_enabled; /* true if OCSP verification enabled */
684 BOOL ocsp_force_default; /* true if the default responder URL is
685 * used regardless of per-cert URL */
686 const char *ocsp_responder; /* default responder URL */
687 long ocsp_resptime_skew;
688 long ocsp_resp_maxage;
689 apr_interval_time_t ocsp_responder_timeout;
690 #ifdef HAVE_SSL_CONF_CMD
691 apr_array_header_t *ssl_ctx_param; /* parameters to pass to SSL_CTX */
695 struct SSLSrvConfigRec {
697 ssl_enabled_t enabled;
699 const char *vhost_id;
701 int session_cache_timeout;
702 BOOL cipher_server_pref;
704 modssl_ctx_t *server;
706 ssl_enabled_t proxy_ssl_check_peer_expire;
707 ssl_enabled_t proxy_ssl_check_peer_cn;
708 ssl_enabled_t proxy_ssl_check_peer_name;
709 #ifndef OPENSSL_NO_TLSEXT
710 ssl_enabled_t strict_sni_vhost_check;
715 #ifndef OPENSSL_NO_COMP
721 * Define the mod_ssl per-directory configuration structure
722 * (i.e. the local configuration for all <Directory>
723 * and .htaccess contexts)
727 apr_array_header_t *aRequirement;
729 ssl_opt_t nOptionsAdd;
730 ssl_opt_t nOptionsDel;
731 const char *szCipherSuite;
732 ssl_verify_t nVerifyClient;
734 const char *szCACertificatePath;
735 const char *szCACertificateFile;
736 const char *szUserName;
737 apr_size_t nRenegBufferSize;
741 * function prototypes
744 /** API glue structures */
745 extern module AP_MODULE_DECLARE_DATA ssl_module;
747 /** configuration handling */
748 SSLModConfigRec *ssl_config_global_create(server_rec *);
749 void ssl_config_global_fix(SSLModConfigRec *);
750 BOOL ssl_config_global_isfixed(SSLModConfigRec *);
751 void *ssl_config_server_create(apr_pool_t *, server_rec *);
752 void *ssl_config_server_merge(apr_pool_t *, void *, void *);
753 void *ssl_config_perdir_create(apr_pool_t *, char *);
754 void *ssl_config_perdir_merge(apr_pool_t *, void *, void *);
755 const char *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, void *, const char *);
756 const char *ssl_cmd_SSLCryptoDevice(cmd_parms *, void *, const char *);
757 const char *ssl_cmd_SSLRandomSeed(cmd_parms *, void *, const char *, const char *, const char *);
758 const char *ssl_cmd_SSLEngine(cmd_parms *, void *, const char *);
759 const char *ssl_cmd_SSLCipherSuite(cmd_parms *, void *, const char *);
760 const char *ssl_cmd_SSLCertificateFile(cmd_parms *, void *, const char *);
761 const char *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, void *, const char *);
762 const char *ssl_cmd_SSLCertificateChainFile(cmd_parms *, void *, const char *);
763 const char *ssl_cmd_SSLPKCS7CertificateFile(cmd_parms *, void *, const char *);
764 const char *ssl_cmd_SSLCACertificatePath(cmd_parms *, void *, const char *);
765 const char *ssl_cmd_SSLCACertificateFile(cmd_parms *, void *, const char *);
766 const char *ssl_cmd_SSLCADNRequestPath(cmd_parms *, void *, const char *);
767 const char *ssl_cmd_SSLCADNRequestFile(cmd_parms *, void *, const char *);
768 const char *ssl_cmd_SSLCARevocationPath(cmd_parms *, void *, const char *);
769 const char *ssl_cmd_SSLCARevocationFile(cmd_parms *, void *, const char *);
770 const char *ssl_cmd_SSLCARevocationCheck(cmd_parms *, void *, const char *);
771 const char *ssl_cmd_SSLHonorCipherOrder(cmd_parms *cmd, void *dcfg, int flag);
772 const char *ssl_cmd_SSLCompression(cmd_parms *, void *, int flag);
773 const char *ssl_cmd_SSLVerifyClient(cmd_parms *, void *, const char *);
774 const char *ssl_cmd_SSLVerifyDepth(cmd_parms *, void *, const char *);
775 const char *ssl_cmd_SSLSessionCache(cmd_parms *, void *, const char *);
776 const char *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, void *, const char *);
777 const char *ssl_cmd_SSLProtocol(cmd_parms *, void *, const char *);
778 const char *ssl_cmd_SSLOptions(cmd_parms *, void *, const char *);
779 const char *ssl_cmd_SSLRequireSSL(cmd_parms *, void *);
780 const char *ssl_cmd_SSLRequire(cmd_parms *, void *, const char *);
781 const char *ssl_cmd_SSLUserName(cmd_parms *, void *, const char *);
782 const char *ssl_cmd_SSLRenegBufferSize(cmd_parms *cmd, void *dcfg, const char *arg);
783 const char *ssl_cmd_SSLStrictSNIVHostCheck(cmd_parms *cmd, void *dcfg, int flag);
784 const char *ssl_cmd_SSLInsecureRenegotiation(cmd_parms *cmd, void *dcfg, int flag);
786 const char *ssl_cmd_SSLProxyEngine(cmd_parms *cmd, void *dcfg, int flag);
787 const char *ssl_cmd_SSLProxyProtocol(cmd_parms *, void *, const char *);
788 const char *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, void *, const char *);
789 const char *ssl_cmd_SSLProxyVerify(cmd_parms *, void *, const char *);
790 const char *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, void *, const char *);
791 const char *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, void *, const char *);
792 const char *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, void *, const char *);
793 const char *ssl_cmd_SSLProxyCARevocationPath(cmd_parms *, void *, const char *);
794 const char *ssl_cmd_SSLProxyCARevocationFile(cmd_parms *, void *, const char *);
795 const char *ssl_cmd_SSLProxyCARevocationCheck(cmd_parms *, void *, const char *);
796 const char *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
797 const char *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
798 const char *ssl_cmd_SSLProxyMachineCertificateChainFile(cmd_parms *, void *, const char *);
799 #ifdef HAVE_TLS_SESSION_TICKETS
800 const char *ssl_cmd_SSLSessionTicketKeyFile(cmd_parms *cmd, void *dcfg, const char *arg);
802 const char *ssl_cmd_SSLProxyCheckPeerExpire(cmd_parms *cmd, void *dcfg, int flag);
803 const char *ssl_cmd_SSLProxyCheckPeerCN(cmd_parms *cmd, void *dcfg, int flag);
804 const char *ssl_cmd_SSLProxyCheckPeerName(cmd_parms *cmd, void *dcfg, int flag);
806 const char *ssl_cmd_SSLOCSPOverrideResponder(cmd_parms *cmd, void *dcfg, int flag);
807 const char *ssl_cmd_SSLOCSPDefaultResponder(cmd_parms *cmd, void *dcfg, const char *arg);
808 const char *ssl_cmd_SSLOCSPResponseTimeSkew(cmd_parms *cmd, void *dcfg, const char *arg);
809 const char *ssl_cmd_SSLOCSPResponseMaxAge(cmd_parms *cmd, void *dcfg, const char *arg);
810 const char *ssl_cmd_SSLOCSPResponderTimeout(cmd_parms *cmd, void *dcfg, const char *arg);
811 const char *ssl_cmd_SSLOCSPEnable(cmd_parms *cmd, void *dcfg, int flag);
813 const char *ssl_cmd_SSLOpenSSLConfCmd(cmd_parms *cmd, void *dcfg, const char *arg1, const char *arg2);
815 #ifndef OPENSSL_NO_SRP
816 const char *ssl_cmd_SSLSRPVerifierFile(cmd_parms *cmd, void *dcfg, const char *arg);
817 const char *ssl_cmd_SSLSRPUnknownUserSeed(cmd_parms *cmd, void *dcfg, const char *arg);
820 const char *ssl_cmd_SSLFIPS(cmd_parms *cmd, void *dcfg, int flag);
822 /** module initialization */
823 int ssl_init_Module(apr_pool_t *, apr_pool_t *, apr_pool_t *, server_rec *);
824 void ssl_init_Engine(server_rec *, apr_pool_t *);
825 void ssl_init_ConfigureServer(server_rec *, apr_pool_t *, apr_pool_t *, SSLSrvConfigRec *);
826 void ssl_init_CheckServers(server_rec *, apr_pool_t *);
828 *ssl_init_FindCAList(server_rec *, apr_pool_t *, const char *, const char *);
829 void ssl_init_Child(apr_pool_t *, server_rec *);
830 apr_status_t ssl_init_ModuleKill(void *data);
832 /** Apache API hooks */
833 int ssl_hook_Auth(request_rec *);
834 int ssl_hook_UserCheck(request_rec *);
835 int ssl_hook_Access(request_rec *);
836 int ssl_hook_Fixup(request_rec *);
837 int ssl_hook_ReadReq(request_rec *);
838 int ssl_hook_Upgrade(request_rec *);
839 void ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s);
841 /** Apache authz provisders */
842 extern const authz_provider ssl_authz_provider_require_ssl;
843 extern const authz_provider ssl_authz_provider_verify_client;
845 /** OpenSSL callbacks */
846 RSA *ssl_callback_TmpRSA(SSL *, int, int);
847 DH *ssl_callback_TmpDH(SSL *, int, int);
848 #ifndef OPENSSL_NO_EC
849 EC_KEY *ssl_callback_TmpECDH(SSL *, int, int);
851 int ssl_callback_SSLVerify(int, X509_STORE_CTX *);
852 int ssl_callback_SSLVerify_CRL(int, X509_STORE_CTX *, conn_rec *);
853 int ssl_callback_proxy_cert(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
854 int ssl_callback_NewSessionCacheEntry(SSL *, SSL_SESSION *);
855 SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *, unsigned char *, int, int *);
856 void ssl_callback_DelSessionCacheEntry(SSL_CTX *, SSL_SESSION *);
857 void ssl_callback_Info(const SSL *, int, int);
858 #ifndef OPENSSL_NO_TLSEXT
859 int ssl_callback_ServerNameIndication(SSL *, int *, modssl_ctx_t *);
861 #ifdef HAVE_TLS_SESSION_TICKETS
862 int ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
863 EVP_CIPHER_CTX *, HMAC_CTX *, int);
865 int ssl_callback_AdvertiseNextProtos(SSL *ssl, const unsigned char **data, unsigned int *len, void *arg);
867 /** Session Cache Support */
868 void ssl_scache_init(server_rec *, apr_pool_t *);
869 void ssl_scache_status_register(apr_pool_t *p);
870 void ssl_scache_kill(server_rec *);
871 BOOL ssl_scache_store(server_rec *, UCHAR *, int,
872 apr_time_t, SSL_SESSION *, apr_pool_t *);
873 SSL_SESSION *ssl_scache_retrieve(server_rec *, UCHAR *, int, apr_pool_t *);
874 void ssl_scache_remove(server_rec *, UCHAR *, int,
878 int ssl_proxy_enable(conn_rec *c);
879 int ssl_engine_disable(conn_rec *c);
881 /** OCSP Stapling Support */
882 #ifdef HAVE_OCSP_STAPLING
883 const char *ssl_cmd_SSLStaplingCache(cmd_parms *, void *, const char *);
884 const char *ssl_cmd_SSLUseStapling(cmd_parms *, void *, int);
885 const char *ssl_cmd_SSLStaplingResponseTimeSkew(cmd_parms *, void *, const char *);
886 const char *ssl_cmd_SSLStaplingResponseMaxAge(cmd_parms *, void *, const char *);
887 const char *ssl_cmd_SSLStaplingStandardCacheTimeout(cmd_parms *, void *, const char *);
888 const char *ssl_cmd_SSLStaplingErrorCacheTimeout(cmd_parms *, void *, const char *);
889 const char *ssl_cmd_SSLStaplingReturnResponderErrors(cmd_parms *, void *, int);
890 const char *ssl_cmd_SSLStaplingFakeTryLater(cmd_parms *, void *, int);
891 const char *ssl_cmd_SSLStaplingResponderTimeout(cmd_parms *, void *, const char *);
892 const char *ssl_cmd_SSLStaplingForceURL(cmd_parms *, void *, const char *);
893 void modssl_init_stapling(server_rec *, apr_pool_t *, apr_pool_t *, modssl_ctx_t *);
894 void ssl_stapling_ex_init(void);
895 int ssl_stapling_init_cert(server_rec *s, modssl_ctx_t *mctx, X509 *x);
897 #ifndef OPENSSL_NO_SRP
898 int ssl_callback_SRPServerParams(SSL *, int *, void *);
902 void ssl_io_filter_init(conn_rec *, request_rec *r, SSL *);
903 void ssl_io_filter_register(apr_pool_t *);
904 long ssl_io_data_cb(BIO *, int, const char *, int, long, long);
906 /* ssl_io_buffer_fill fills the setaside buffering of the HTTP request
907 * to allow an SSL renegotiation to take place. */
908 int ssl_io_buffer_fill(request_rec *r, apr_size_t maxlen);
911 int ssl_rand_seed(server_rec *, apr_pool_t *, ssl_rsctx_t, char *);
913 /** Utility Functions */
914 char *ssl_util_vhostid(apr_pool_t *, server_rec *);
915 apr_file_t *ssl_util_ppopen(server_rec *, apr_pool_t *, const char *,
916 const char * const *);
917 void ssl_util_ppclose(server_rec *, apr_pool_t *, apr_file_t *);
918 char *ssl_util_readfilter(server_rec *, apr_pool_t *, const char *,
919 const char * const *);
920 BOOL ssl_util_path_check(ssl_pathcheck_t, const char *, apr_pool_t *);
921 ssl_algo_t ssl_util_algotypeof(X509 *, EVP_PKEY *);
922 char *ssl_util_algotypestr(ssl_algo_t);
923 void ssl_util_thread_setup(apr_pool_t *);
924 int ssl_init_ssl_connection(conn_rec *c, request_rec *r);
926 /** Pass Phrase Support */
927 void ssl_pphrase_Handle(server_rec *, apr_pool_t *);
929 /** Diffie-Hellman Parameter Support */
930 DH *ssl_dh_GetTmpParam(int);
931 DH *ssl_dh_GetParamFromFile(char *);
933 unsigned char *ssl_asn1_table_set(apr_hash_t *table,
937 ssl_asn1_t *ssl_asn1_table_get(apr_hash_t *table,
940 void ssl_asn1_table_unset(apr_hash_t *table,
943 const char *ssl_asn1_keystr(int keytype);
945 const char *ssl_asn1_table_keyfmt(apr_pool_t *p,
949 STACK_OF(X509) *ssl_read_pkcs7(server_rec *s, const char *pkcs7);
952 int ssl_mutex_init(server_rec *, apr_pool_t *);
953 int ssl_mutex_reinit(server_rec *, apr_pool_t *);
954 int ssl_mutex_on(server_rec *);
955 int ssl_mutex_off(server_rec *);
957 int ssl_stapling_mutex_reinit(server_rec *, apr_pool_t *);
959 /* mutex type names for Mutex directive */
960 #define SSL_CACHE_MUTEX_TYPE "ssl-cache"
961 #define SSL_STAPLING_MUTEX_TYPE "ssl-stapling"
963 /** Logfile Support */
964 void ssl_die(server_rec *);
965 void ssl_log_ssl_error(const char *, int, int, server_rec *);
967 /* ssl_log_xerror, ssl_log_cxerror and ssl_log_rxerror are wrappers for the
968 * respective ap_log_*error functions and take a certificate as an
969 * additional argument (whose details are appended to the log message).
970 * The other arguments are interpreted exactly as with their ap_log_*error
972 void ssl_log_xerror(const char *file, int line, int level,
973 apr_status_t rv, apr_pool_t *p, server_rec *s,
974 X509 *cert, const char *format, ...)
975 __attribute__((format(printf,8,9)));
977 void ssl_log_cxerror(const char *file, int line, int level,
978 apr_status_t rv, conn_rec *c, X509 *cert,
979 const char *format, ...)
980 __attribute__((format(printf,7,8)));
982 void ssl_log_rxerror(const char *file, int line, int level,
983 apr_status_t rv, request_rec *r, X509 *cert,
984 const char *format, ...)
985 __attribute__((format(printf,7,8)));
987 #define SSLLOG_MARK __FILE__,__LINE__
991 /* Register variables for the lifetime of the process pool 'p'. */
992 void ssl_var_register(apr_pool_t *p);
993 char *ssl_var_lookup(apr_pool_t *, server_rec *, conn_rec *, request_rec *, char *);
994 apr_array_header_t *ssl_ext_list(apr_pool_t *p, conn_rec *c, int peer, const char *extension);
996 void ssl_var_log_config_register(apr_pool_t *p);
998 /* Extract SSL_*_DN_* variables into table 't' from SSL object 'ssl',
999 * allocating from 'p': */
1000 void modssl_var_extract_dns(apr_table_t *t, SSL *ssl, apr_pool_t *p);
1002 #ifndef OPENSSL_NO_OCSP
1003 /* Perform OCSP validation of the current cert in the given context.
1004 * Returns non-zero on success or zero on failure. On failure, the
1005 * context error code is set. */
1006 int modssl_verify_ocsp(X509_STORE_CTX *ctx, SSLSrvConfigRec *sc,
1007 server_rec *s, conn_rec *c, apr_pool_t *pool);
1009 /* OCSP helper interface; dispatches the given OCSP request to the
1010 * responder at the given URI. Returns the decoded OCSP response
1011 * object, or NULL on error (in which case, errors will have been
1012 * logged). Pool 'p' is used for temporary allocations. */
1013 OCSP_RESPONSE *modssl_dispatch_ocsp_request(const apr_uri_t *uri,
1014 apr_interval_time_t timeout,
1015 OCSP_REQUEST *request,
1016 conn_rec *c, apr_pool_t *p);
1020 extern int ssl_running_on_valgrind;
1023 #endif /* SSL_PRIVATE_H */