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_CTRL_SET_TLSEXT_TICKET_KEY_CB
162 #define HAVE_TLS_SESSION_TICKETS
163 #define TLSEXT_TICKET_KEY_LEN 48
164 #ifndef tlsext_tick_md
165 #ifdef OPENSSL_NO_SHA256
166 #define tlsext_tick_md EVP_sha1
168 #define tlsext_tick_md EVP_sha256
174 /* mod_ssl headers */
175 #include "ssl_util_ssl.h"
177 APLOG_USE_MODULE(ssl);
180 * Provide reasonable default for some defines
183 #define PFALSE ((void *)FALSE)
186 #define PTRUE ((void *)TRUE)
196 #define RAND_MAX INT_MAX
200 * Provide reasonable defines for some types
203 #define UCHAR unsigned char
207 * Provide useful shorthands
209 #define strEQ(s1,s2) (strcmp(s1,s2) == 0)
210 #define strNE(s1,s2) (strcmp(s1,s2) != 0)
211 #define strEQn(s1,s2,n) (strncmp(s1,s2,n) == 0)
212 #define strNEn(s1,s2,n) (strncmp(s1,s2,n) != 0)
214 #define strcEQ(s1,s2) (strcasecmp(s1,s2) == 0)
215 #define strcNE(s1,s2) (strcasecmp(s1,s2) != 0)
216 #define strcEQn(s1,s2,n) (strncasecmp(s1,s2,n) == 0)
217 #define strcNEn(s1,s2,n) (strncasecmp(s1,s2,n) != 0)
219 #define strIsEmpty(s) (s == NULL || s[0] == NUL)
221 #define myConnConfig(c) \
222 (SSLConnRec *)ap_get_module_config(c->conn_config, &ssl_module)
223 #define myCtxConfig(sslconn, sc) (sslconn->is_proxy ? sc->proxy : sc->server)
224 #define myConnConfigSet(c, val) \
225 ap_set_module_config(c->conn_config, &ssl_module, val)
226 #define mySrvConfig(srv) (SSLSrvConfigRec *)ap_get_module_config(srv->module_config, &ssl_module)
227 #define myDirConfig(req) (SSLDirConfigRec *)ap_get_module_config(req->per_dir_config, &ssl_module)
228 #define myModConfig(srv) (mySrvConfig((srv)))->mc
229 #define mySrvFromConn(c) (myConnConfig(c))->server
230 #define mySrvConfigFromConn(c) mySrvConfig(mySrvFromConn(c))
231 #define myModConfigFromConn(c) myModConfig(mySrvFromConn(c))
233 #define myCtxVarSet(mc,num,val) mc->rCtx.pV##num = val
234 #define myCtxVarGet(mc,num,type) (type)(mc->rCtx.pV##num)
237 * Defaults for the configuration
239 #ifndef SSL_SESSION_CACHE_TIMEOUT
240 #define SSL_SESSION_CACHE_TIMEOUT 300
243 /* Default setting for per-dir reneg buffer. */
244 #ifndef DEFAULT_RENEG_BUFFER_SIZE
245 #define DEFAULT_RENEG_BUFFER_SIZE (128 * 1024)
248 /* Default for OCSP response validity */
249 #ifndef DEFAULT_OCSP_MAX_SKEW
250 #define DEFAULT_OCSP_MAX_SKEW (60 * 5)
253 /* Default timeout for OCSP queries */
254 #ifndef DEFAULT_OCSP_TIMEOUT
255 #define DEFAULT_OCSP_TIMEOUT 10
259 * Define the certificate algorithm types
262 typedef int ssl_algo_t;
264 #define SSL_ALGO_UNKNOWN (0)
265 #define SSL_ALGO_RSA (1<<0)
266 #define SSL_ALGO_DSA (1<<1)
267 #ifndef OPENSSL_NO_EC
268 #define SSL_ALGO_ECC (1<<2)
269 #define SSL_ALGO_ALL (SSL_ALGO_RSA|SSL_ALGO_DSA|SSL_ALGO_ECC)
271 #define SSL_ALGO_ALL (SSL_ALGO_RSA|SSL_ALGO_DSA)
274 #define SSL_AIDX_RSA (0)
275 #define SSL_AIDX_DSA (1)
276 #ifndef OPENSSL_NO_EC
277 #define SSL_AIDX_ECC (2)
278 #define SSL_AIDX_MAX (3)
280 #define SSL_AIDX_MAX (2)
285 * Define IDs for the temporary RSA keys and DH params
288 #define SSL_TMP_KEY_RSA_512 (0)
289 #define SSL_TMP_KEY_RSA_1024 (1)
290 #define SSL_TMP_KEY_DH_512 (2)
291 #define SSL_TMP_KEY_DH_1024 (3)
292 #define SSL_TMP_KEY_MAX (4)
295 * Define the SSL options
297 #define SSL_OPT_NONE (0)
298 #define SSL_OPT_RELSET (1<<0)
299 #define SSL_OPT_STDENVVARS (1<<1)
300 #define SSL_OPT_EXPORTCERTDATA (1<<3)
301 #define SSL_OPT_FAKEBASICAUTH (1<<4)
302 #define SSL_OPT_STRICTREQUIRE (1<<5)
303 #define SSL_OPT_OPTRENEGOTIATE (1<<6)
304 #define SSL_OPT_LEGACYDNFORMAT (1<<7)
305 typedef int ssl_opt_t;
308 * Define the SSL Protocol options
310 #define SSL_PROTOCOL_NONE (0)
311 #define SSL_PROTOCOL_SSLV2 (1<<0)
312 #define SSL_PROTOCOL_SSLV3 (1<<1)
313 #define SSL_PROTOCOL_TLSV1 (1<<2)
314 #define SSL_PROTOCOL_ALL (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1)
315 typedef int ssl_proto_t;
318 * Define the SSL verify levels
321 SSL_CVERIFY_UNSET = UNSET,
322 SSL_CVERIFY_NONE = 0,
323 SSL_CVERIFY_OPTIONAL = 1,
324 SSL_CVERIFY_REQUIRE = 2,
325 SSL_CVERIFY_OPTIONAL_NO_CA = 3
328 #define SSL_VERIFY_PEER_STRICT \
329 (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
331 #define ssl_verify_error_is_optional(errnum) \
332 ((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) \
333 || (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
334 || (errnum == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) \
335 || (errnum == X509_V_ERR_CERT_UNTRUSTED) \
336 || (errnum == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
342 SSL_CRLCHECK_UNSET = UNSET,
343 SSL_CRLCHECK_NONE = 0,
344 SSL_CRLCHECK_LEAF = 1,
345 SSL_CRLCHECK_CHAIN = 2
349 * Define the SSL pass phrase dialog types
352 SSL_PPTYPE_UNSET = UNSET,
353 SSL_PPTYPE_BUILTIN = 0,
354 SSL_PPTYPE_FILTER = 1,
359 * Define the Path Checking modes
361 #define SSL_PCM_EXISTS 1
362 #define SSL_PCM_ISREG 2
363 #define SSL_PCM_ISDIR 4
364 #define SSL_PCM_ISNONZERO 8
365 typedef unsigned int ssl_pathcheck_t;
368 * Define the SSL enabled state
371 SSL_ENABLED_UNSET = UNSET,
372 SSL_ENABLED_FALSE = 0,
373 SSL_ENABLED_TRUE = 1,
374 SSL_ENABLED_OPTIONAL = 3
378 * Define the SSL requirement structure
382 ap_expr_info_t *mpExpr;
386 * Define the SSL random number generator seeding source
389 SSL_RSCTX_STARTUP = 1,
390 SSL_RSCTX_CONNECT = 2
393 SSL_RSSRC_BUILTIN = 1,
406 * Define the structure of an ASN.1 anything
410 unsigned char *cpData;
411 apr_time_t source_mtime;
415 * Define the mod_ssl per-module configuration structure
416 * (i.e. the global configuration for each httpd process)
420 SSL_SHUTDOWN_TYPE_UNSET,
421 SSL_SHUTDOWN_TYPE_STANDARD,
422 SSL_SHUTDOWN_TYPE_UNCLEAN,
423 SSL_SHUTDOWN_TYPE_ACCURATE
424 } ssl_shutdown_type_e;
428 const char *client_dn;
430 ssl_shutdown_type_e shutdown_type;
431 const char *verify_info;
432 const char *verify_error;
438 /* Track the handshake/renegotiation state for the connection so
439 * that all client-initiated renegotiations can be rejected, as a
440 * partial fix for CVE-2009-3555. */
442 RENEG_INIT = 0, /* Before initial handshake */
443 RENEG_REJECT, /* After initial handshake; any client-initiated
444 * renegotiation should be rejected */
445 RENEG_ALLOW, /* A server-initated renegotiation is taking
446 * place (as dictated by configuration) */
447 RENEG_ABORT /* Renegotiation initiated by client, abort the
454 /* BIG FAT WARNING: SSLModConfigRec has unusual memory lifetime: it is
455 * allocated out of the "process" pool and only a single such
456 * structure is created and used for the lifetime of the process.
457 * (The process pool is s->process->pool and is stored in the .pPool
458 * field.) Most members of this structure are likewise allocated out
459 * of the process pool, but notably sesscache and sesscache_context
462 * The structure is treated as mostly immutable after a single config
463 * parse has completed; the post_config hook (ssl_init_Module) flips
464 * the bFixed flag to true and subsequent invocations of the config
465 * callbacks hence do nothing.
467 * This odd lifetime strategy is used so that encrypted private keys
468 * can be decrypted once at startup and continue to be used across
469 * subsequent server reloads where the interactive password prompt is
472 * It is really an ABI nightmare waiting to happen since DSOs are
473 * reloaded across restarts, and nothing prevents the struct type
474 * changing across such reloads, yet the cached structure will be
475 * assumed to match regardless.
477 * This should really be fixed using a smaller structure which only
478 * stores that which is absolutely necessary (the private keys, maybe
479 * the random seed), and have that structure be strictly ABI-versioned
487 /* OpenSSL SSL_SESS_CACHE_* flags: */
490 /* The configured provider, and associated private data
492 const ap_socache_provider_t *sesscache;
493 ap_socache_instance_t *sesscache_context;
495 apr_global_mutex_t *pMutex;
496 apr_array_header_t *aRandSeed;
497 apr_hash_t *tVHostKeys;
498 void *pTmpKeys[SSL_TMP_KEY_MAX];
500 /* Two hash tables of pointers to ssl_asn1_t structures. The
501 * structures are used to store certificates and private keys
502 * respectively, in raw DER format (serialized OpenSSL X509 and
503 * PrivateKey structures). The tables are indexed by (vhost-id,
504 * algorithm type) using the function ssl_asn1_table_keyfmt(); for
505 * example the string "vhost.example.com:443:RSA". */
506 apr_hash_t *tPublicCert;
507 apr_hash_t *tPrivateKey;
509 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
510 const char *szCryptoDevice;
513 #ifdef HAVE_OCSP_STAPLING
514 const ap_socache_provider_t *stapling_cache;
515 ap_socache_instance_t *stapling_cache_context;
516 apr_global_mutex_t *stapling_mutex;
520 void *pV1, *pV2, *pV3, *pV4, *pV5, *pV6, *pV7, *pV8, *pV9, *pV10;
524 /** Structure representing configured filenames for certs and keys for
525 * a given vhost, and the corresponding in-memory structures once the
526 * files are parsed. */
528 /* Lists of configured certs and keys for this server; from index
529 * 0 up to SSL_AIDX_MAX-1 or the first NULL pointer. Note that
530 * these arrays are NOT indexed by algorithm type, they are simply
531 * unordered lists. */
532 const char *cert_files[SSL_AIDX_MAX];
533 const char *key_files[SSL_AIDX_MAX];
534 /* Loaded certs and keys; these arrays ARE indexed by the
535 * algorithm type, i.e. keys[SSL_AIDX_RSA] maps to the RSA
537 X509 *certs[SSL_AIDX_MAX];
538 EVP_PKEY *keys[SSL_AIDX_MAX];
540 /** Certificates which specify the set of CA names which should be
541 * sent in the CertificateRequest message: */
542 const char *ca_name_path;
543 const char *ca_name_file;
544 } modssl_pk_server_t;
547 /** proxy can have any number of cert/key pairs */
548 const char *cert_file;
549 const char *cert_path;
550 const char *ca_cert_file;
551 STACK_OF(X509_INFO) *certs; /* Contains End Entity certs */
552 STACK_OF(X509) **ca_certs; /* Contains ONLY chain certs for
553 * each item in certs.
554 * (ptr to array of ptrs) */
557 /** stuff related to authentication that can also be per-dir */
559 /** known/trusted CAs */
560 const char *ca_cert_path;
561 const char *ca_cert_file;
563 const char *cipher_suite;
565 /** for client or downstream server authentication */
567 ssl_verify_t verify_mode;
570 #ifdef HAVE_TLS_SESSION_TICKETS
572 const char *file_path;
573 unsigned char key_name[16];
574 unsigned char hmac_secret[16];
575 unsigned char aes_key[16];
576 } modssl_ticket_key_t;
579 typedef struct SSLSrvConfigRec SSLSrvConfigRec;
582 SSLSrvConfigRec *sc; /** pointer back to server config */
585 /** we are one or the other */
586 modssl_pk_server_t *pks;
587 modssl_pk_proxy_t *pkp;
589 #ifdef HAVE_TLS_SESSION_TICKETS
590 modssl_ticket_key_t *ticket_key;
593 ssl_proto_t protocol;
595 /** config for handling encrypted keys */
596 ssl_pphrase_t pphrase_dialog_type;
597 const char *pphrase_dialog_path;
599 const char *cert_chain;
602 /** certificate revocation list */
603 const char *crl_path;
604 const char *crl_file;
605 ssl_crlcheck_t crl_check_mode;
607 #ifdef HAVE_OCSP_STAPLING
608 /** OCSP stapling options */
609 BOOL stapling_enabled;
610 long stapling_resptime_skew;
611 long stapling_resp_maxage;
612 int stapling_cache_timeout;
613 BOOL stapling_return_errors;
614 BOOL stapling_fake_trylater;
615 int stapling_errcache_timeout;
616 apr_interval_time_t stapling_responder_timeout;
617 const char *stapling_force_url;
620 modssl_auth_ctx_t auth;
622 BOOL ocsp_enabled; /* true if OCSP verification enabled */
623 BOOL ocsp_force_default; /* true if the default responder URL is
624 * used regardless of per-cert URL */
625 const char *ocsp_responder; /* default responder URL */
626 long ocsp_resptime_skew;
627 long ocsp_resp_maxage;
628 apr_interval_time_t ocsp_responder_timeout;
632 struct SSLSrvConfigRec {
634 ssl_enabled_t enabled;
636 const char *vhost_id;
638 int session_cache_timeout;
639 BOOL cipher_server_pref;
641 modssl_ctx_t *server;
643 ssl_enabled_t proxy_ssl_check_peer_expire;
644 ssl_enabled_t proxy_ssl_check_peer_cn;
645 #ifndef OPENSSL_NO_TLSEXT
646 ssl_enabled_t strict_sni_vhost_check;
654 * Define the mod_ssl per-directory configuration structure
655 * (i.e. the local configuration for all <Directory>
656 * and .htaccess contexts)
660 apr_array_header_t *aRequirement;
662 ssl_opt_t nOptionsAdd;
663 ssl_opt_t nOptionsDel;
664 const char *szCipherSuite;
665 ssl_verify_t nVerifyClient;
667 const char *szCACertificatePath;
668 const char *szCACertificateFile;
669 const char *szUserName;
670 apr_size_t nRenegBufferSize;
674 * function prototypes
677 /** API glue structures */
678 extern module AP_MODULE_DECLARE_DATA ssl_module;
680 /** configuration handling */
681 SSLModConfigRec *ssl_config_global_create(server_rec *);
682 void ssl_config_global_fix(SSLModConfigRec *);
683 BOOL ssl_config_global_isfixed(SSLModConfigRec *);
684 void *ssl_config_server_create(apr_pool_t *, server_rec *);
685 void *ssl_config_server_merge(apr_pool_t *, void *, void *);
686 void *ssl_config_perdir_create(apr_pool_t *, char *);
687 void *ssl_config_perdir_merge(apr_pool_t *, void *, void *);
688 const char *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, void *, const char *);
689 const char *ssl_cmd_SSLCryptoDevice(cmd_parms *, void *, const char *);
690 const char *ssl_cmd_SSLRandomSeed(cmd_parms *, void *, const char *, const char *, const char *);
691 const char *ssl_cmd_SSLEngine(cmd_parms *, void *, const char *);
692 const char *ssl_cmd_SSLCipherSuite(cmd_parms *, void *, const char *);
693 const char *ssl_cmd_SSLCertificateFile(cmd_parms *, void *, const char *);
694 const char *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, void *, const char *);
695 const char *ssl_cmd_SSLCertificateChainFile(cmd_parms *, void *, const char *);
696 const char *ssl_cmd_SSLPKCS7CertificateFile(cmd_parms *, void *, const char *);
697 const char *ssl_cmd_SSLCACertificatePath(cmd_parms *, void *, const char *);
698 const char *ssl_cmd_SSLCACertificateFile(cmd_parms *, void *, const char *);
699 const char *ssl_cmd_SSLCADNRequestPath(cmd_parms *, void *, const char *);
700 const char *ssl_cmd_SSLCADNRequestFile(cmd_parms *, void *, const char *);
701 const char *ssl_cmd_SSLCARevocationPath(cmd_parms *, void *, const char *);
702 const char *ssl_cmd_SSLCARevocationFile(cmd_parms *, void *, const char *);
703 const char *ssl_cmd_SSLCARevocationCheck(cmd_parms *, void *, const char *);
704 const char *ssl_cmd_SSLHonorCipherOrder(cmd_parms *cmd, void *dcfg, int flag);
705 const char *ssl_cmd_SSLVerifyClient(cmd_parms *, void *, const char *);
706 const char *ssl_cmd_SSLVerifyDepth(cmd_parms *, void *, const char *);
707 const char *ssl_cmd_SSLSessionCache(cmd_parms *, void *, const char *);
708 const char *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, void *, const char *);
709 const char *ssl_cmd_SSLProtocol(cmd_parms *, void *, const char *);
710 const char *ssl_cmd_SSLOptions(cmd_parms *, void *, const char *);
711 const char *ssl_cmd_SSLRequireSSL(cmd_parms *, void *);
712 const char *ssl_cmd_SSLRequire(cmd_parms *, void *, const char *);
713 const char *ssl_cmd_SSLUserName(cmd_parms *, void *, const char *);
714 const char *ssl_cmd_SSLRenegBufferSize(cmd_parms *cmd, void *dcfg, const char *arg);
715 const char *ssl_cmd_SSLStrictSNIVHostCheck(cmd_parms *cmd, void *dcfg, int flag);
716 const char *ssl_cmd_SSLInsecureRenegotiation(cmd_parms *cmd, void *dcfg, int flag);
718 const char *ssl_cmd_SSLProxyEngine(cmd_parms *cmd, void *dcfg, int flag);
719 const char *ssl_cmd_SSLProxyProtocol(cmd_parms *, void *, const char *);
720 const char *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, void *, const char *);
721 const char *ssl_cmd_SSLProxyVerify(cmd_parms *, void *, const char *);
722 const char *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, void *, const char *);
723 const char *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, void *, const char *);
724 const char *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, void *, const char *);
725 const char *ssl_cmd_SSLProxyCARevocationPath(cmd_parms *, void *, const char *);
726 const char *ssl_cmd_SSLProxyCARevocationFile(cmd_parms *, void *, const char *);
727 const char *ssl_cmd_SSLProxyCARevocationCheck(cmd_parms *, void *, const char *);
728 const char *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
729 const char *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
730 const char *ssl_cmd_SSLProxyMachineCertificateChainFile(cmd_parms *, void *, const char *);
731 #ifdef HAVE_TLS_SESSION_TICKETS
732 const char *ssl_cmd_SSLSessionTicketKeyFile(cmd_parms *cmd, void *dcfg, const char *arg);
734 const char *ssl_cmd_SSLProxyCheckPeerExpire(cmd_parms *cmd, void *dcfg, int flag);
735 const char *ssl_cmd_SSLProxyCheckPeerCN(cmd_parms *cmd, void *dcfg, int flag);
737 const char *ssl_cmd_SSLOCSPOverrideResponder(cmd_parms *cmd, void *dcfg, int flag);
738 const char *ssl_cmd_SSLOCSPDefaultResponder(cmd_parms *cmd, void *dcfg, const char *arg);
739 const char *ssl_cmd_SSLOCSPResponseTimeSkew(cmd_parms *cmd, void *dcfg, const char *arg);
740 const char *ssl_cmd_SSLOCSPResponseMaxAge(cmd_parms *cmd, void *dcfg, const char *arg);
741 const char *ssl_cmd_SSLOCSPResponderTimeout(cmd_parms *cmd, void *dcfg, const char *arg);
742 const char *ssl_cmd_SSLOCSPEnable(cmd_parms *cmd, void *dcfg, int flag);
744 const char *ssl_cmd_SSLFIPS(cmd_parms *cmd, void *dcfg, int flag);
746 /** module initialization */
747 int ssl_init_Module(apr_pool_t *, apr_pool_t *, apr_pool_t *, server_rec *);
748 void ssl_init_Engine(server_rec *, apr_pool_t *);
749 void ssl_init_ConfigureServer(server_rec *, apr_pool_t *, apr_pool_t *, SSLSrvConfigRec *);
750 void ssl_init_CheckServers(server_rec *, apr_pool_t *);
752 *ssl_init_FindCAList(server_rec *, apr_pool_t *, const char *, const char *);
753 void ssl_init_Child(apr_pool_t *, server_rec *);
754 apr_status_t ssl_init_ModuleKill(void *data);
756 /** Apache API hooks */
757 int ssl_hook_Auth(request_rec *);
758 int ssl_hook_UserCheck(request_rec *);
759 int ssl_hook_Access(request_rec *);
760 int ssl_hook_Fixup(request_rec *);
761 int ssl_hook_ReadReq(request_rec *);
762 int ssl_hook_Upgrade(request_rec *);
763 void ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s);
765 /** Apache authz provisders */
766 extern const authz_provider ssl_authz_provider_require_ssl;
767 extern const authz_provider ssl_authz_provider_verify_client;
769 /** OpenSSL callbacks */
770 RSA *ssl_callback_TmpRSA(SSL *, int, int);
771 DH *ssl_callback_TmpDH(SSL *, int, int);
772 #ifndef OPENSSL_NO_EC
773 EC_KEY *ssl_callback_TmpECDH(SSL *, int, int);
775 int ssl_callback_SSLVerify(int, X509_STORE_CTX *);
776 int ssl_callback_SSLVerify_CRL(int, X509_STORE_CTX *, conn_rec *);
777 int ssl_callback_proxy_cert(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
778 int ssl_callback_NewSessionCacheEntry(SSL *, SSL_SESSION *);
779 SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *, unsigned char *, int, int *);
780 void ssl_callback_DelSessionCacheEntry(SSL_CTX *, SSL_SESSION *);
781 void ssl_callback_Info(const SSL *, int, int);
782 #ifndef OPENSSL_NO_TLSEXT
783 int ssl_callback_ServerNameIndication(SSL *, int *, modssl_ctx_t *);
785 #ifdef HAVE_TLS_SESSION_TICKETS
786 int ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
787 EVP_CIPHER_CTX *, HMAC_CTX *, int);
790 /** Session Cache Support */
791 void ssl_scache_init(server_rec *, apr_pool_t *);
792 void ssl_scache_status_register(apr_pool_t *p);
793 void ssl_scache_kill(server_rec *);
794 BOOL ssl_scache_store(server_rec *, UCHAR *, int,
795 apr_time_t, SSL_SESSION *, apr_pool_t *);
796 SSL_SESSION *ssl_scache_retrieve(server_rec *, UCHAR *, int, apr_pool_t *);
797 void ssl_scache_remove(server_rec *, UCHAR *, int,
801 int ssl_proxy_enable(conn_rec *c);
802 int ssl_engine_disable(conn_rec *c);
804 /** OCSP Stapling Support */
805 #ifdef HAVE_OCSP_STAPLING
806 const char *ssl_cmd_SSLStaplingCache(cmd_parms *, void *, const char *);
807 const char *ssl_cmd_SSLUseStapling(cmd_parms *, void *, int);
808 const char *ssl_cmd_SSLStaplingResponseTimeSkew(cmd_parms *, void *, const char *);
809 const char *ssl_cmd_SSLStaplingResponseMaxAge(cmd_parms *, void *, const char *);
810 const char *ssl_cmd_SSLStaplingStandardCacheTimeout(cmd_parms *, void *, const char *);
811 const char *ssl_cmd_SSLStaplingErrorCacheTimeout(cmd_parms *, void *, const char *);
812 const char *ssl_cmd_SSLStaplingReturnResponderErrors(cmd_parms *, void *, int);
813 const char *ssl_cmd_SSLStaplingFakeTryLater(cmd_parms *, void *, int);
814 const char *ssl_cmd_SSLStaplingResponderTimeout(cmd_parms *, void *, const char *);
815 const char *ssl_cmd_SSLStaplingForceURL(cmd_parms *, void *, const char *);
816 void modssl_init_stapling(server_rec *, apr_pool_t *, apr_pool_t *, modssl_ctx_t *);
817 void ssl_stapling_ex_init(void);
818 int ssl_stapling_init_cert(server_rec *s, modssl_ctx_t *mctx, X509 *x);
822 void ssl_io_filter_init(conn_rec *, request_rec *r, SSL *);
823 void ssl_io_filter_register(apr_pool_t *);
824 long ssl_io_data_cb(BIO *, int, const char *, int, long, long);
826 /* ssl_io_buffer_fill fills the setaside buffering of the HTTP request
827 * to allow an SSL renegotiation to take place. */
828 int ssl_io_buffer_fill(request_rec *r, apr_size_t maxlen);
831 int ssl_rand_seed(server_rec *, apr_pool_t *, ssl_rsctx_t, char *);
833 /** Utility Functions */
834 char *ssl_util_vhostid(apr_pool_t *, server_rec *);
835 apr_file_t *ssl_util_ppopen(server_rec *, apr_pool_t *, const char *,
836 const char * const *);
837 void ssl_util_ppclose(server_rec *, apr_pool_t *, apr_file_t *);
838 char *ssl_util_readfilter(server_rec *, apr_pool_t *, const char *,
839 const char * const *);
840 BOOL ssl_util_path_check(ssl_pathcheck_t, const char *, apr_pool_t *);
841 ssl_algo_t ssl_util_algotypeof(X509 *, EVP_PKEY *);
842 char *ssl_util_algotypestr(ssl_algo_t);
843 void ssl_util_thread_setup(apr_pool_t *);
844 int ssl_init_ssl_connection(conn_rec *c, request_rec *r);
846 /** Pass Phrase Support */
847 void ssl_pphrase_Handle(server_rec *, apr_pool_t *);
849 /** Diffie-Hellman Parameter Support */
850 DH *ssl_dh_GetTmpParam(int);
851 DH *ssl_dh_GetParamFromFile(char *);
853 unsigned char *ssl_asn1_table_set(apr_hash_t *table,
857 ssl_asn1_t *ssl_asn1_table_get(apr_hash_t *table,
860 void ssl_asn1_table_unset(apr_hash_t *table,
863 const char *ssl_asn1_keystr(int keytype);
865 const char *ssl_asn1_table_keyfmt(apr_pool_t *p,
869 STACK_OF(X509) *ssl_read_pkcs7(server_rec *s, const char *pkcs7);
872 int ssl_mutex_init(server_rec *, apr_pool_t *);
873 int ssl_mutex_reinit(server_rec *, apr_pool_t *);
874 int ssl_mutex_on(server_rec *);
875 int ssl_mutex_off(server_rec *);
877 int ssl_stapling_mutex_reinit(server_rec *, apr_pool_t *);
879 /* mutex type names for Mutex directive */
880 #define SSL_CACHE_MUTEX_TYPE "ssl-cache"
881 #define SSL_STAPLING_MUTEX_TYPE "ssl-stapling"
883 /** Logfile Support */
885 void ssl_log_ssl_error(const char *, int, int, server_rec *);
887 /* ssl_log_xerror, ssl_log_cxerror and ssl_log_rxerror are wrappers for the
888 * respective ap_log_*error functions and take a certificate as an
889 * additional argument (whose details are appended to the log message).
890 * The other arguments are interpreted exactly as with their ap_log_*error
892 void ssl_log_xerror(const char *file, int line, int level,
893 apr_status_t rv, apr_pool_t *p, server_rec *s,
894 X509 *cert, const char *format, ...)
895 __attribute__((format(printf,8,9)));
897 void ssl_log_cxerror(const char *file, int line, int level,
898 apr_status_t rv, conn_rec *c, X509 *cert,
899 const char *format, ...)
900 __attribute__((format(printf,7,8)));
902 void ssl_log_rxerror(const char *file, int line, int level,
903 apr_status_t rv, request_rec *r, X509 *cert,
904 const char *format, ...)
905 __attribute__((format(printf,7,8)));
907 #define SSLLOG_MARK __FILE__,__LINE__
911 /* Register variables for the lifetime of the process pool 'p'. */
912 void ssl_var_register(apr_pool_t *p);
913 char *ssl_var_lookup(apr_pool_t *, server_rec *, conn_rec *, request_rec *, char *);
914 apr_array_header_t *ssl_ext_list(apr_pool_t *p, conn_rec *c, int peer, const char *extension);
916 void ssl_var_log_config_register(apr_pool_t *p);
918 /* Extract SSL_*_DN_* variables into table 't' from SSL object 'ssl',
919 * allocating from 'p': */
920 void modssl_var_extract_dns(apr_table_t *t, SSL *ssl, apr_pool_t *p);
922 #ifndef OPENSSL_NO_OCSP
923 /* Perform OCSP validation of the current cert in the given context.
924 * Returns non-zero on success or zero on failure. On failure, the
925 * context error code is set. */
926 int modssl_verify_ocsp(X509_STORE_CTX *ctx, SSLSrvConfigRec *sc,
927 server_rec *s, conn_rec *c, apr_pool_t *pool);
929 /* OCSP helper interface; dispatches the given OCSP request to the
930 * responder at the given URI. Returns the decoded OCSP response
931 * object, or NULL on error (in which case, errors will have been
932 * logged). Pool 'p' is used for temporary allocations. */
933 OCSP_RESPONSE *modssl_dispatch_ocsp_request(const apr_uri_t *uri,
934 apr_interval_time_t timeout,
935 OCSP_REQUEST *request,
936 conn_rec *c, apr_pool_t *p);
939 #endif /* SSL_PRIVATE_H */