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 < 0x0090801f)
109 #error mod_ssl requires OpenSSL 0.9.8a or later
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)
118 #if (OPENSSL_VERSION_NUMBER >= 0x10000000)
119 #define MODSSL_SSL_CIPHER_CONST const
120 #define MODSSL_SSL_METHOD_CONST const
122 #define MODSSL_SSL_CIPHER_CONST
123 #define MODSSL_SSL_METHOD_CONST
126 #if defined(OPENSSL_FIPS)
130 #if defined(SSL_OP_NO_TLSv1_2)
134 #if defined(SSL_CONF_FLAG_FILE)
135 #define HAVE_SSL_CONF_CMD
139 * The following features all depend on TLS extension support.
140 * Within this block, check again for features (not version numbers).
142 #if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name)
146 /* ECC: make sure we have at least 1.0.0 */
147 #if !defined(OPENSSL_NO_EC) && defined(TLSEXT_ECPOINTFORMAT_uncompressed)
152 #if !defined(OPENSSL_NO_OCSP) && defined(SSL_CTX_set_tlsext_status_cb)
153 #define HAVE_OCSP_STAPLING
154 /* backward compatibility with OpenSSL < 1.0 */
155 #ifndef sk_OPENSSL_STRING_num
156 #define sk_OPENSSL_STRING_num sk_num
158 #ifndef sk_OPENSSL_STRING_value
159 #define sk_OPENSSL_STRING_value sk_value
161 #ifndef sk_OPENSSL_STRING_pop
162 #define sk_OPENSSL_STRING_pop sk_pop
166 /* TLS session tickets */
167 #if defined(SSL_CTX_set_tlsext_ticket_key_cb)
168 #define HAVE_TLS_SESSION_TICKETS
169 #define TLSEXT_TICKET_KEY_LEN 48
170 #ifndef tlsext_tick_md
171 #ifdef OPENSSL_NO_SHA256
172 #define tlsext_tick_md EVP_sha1
174 #define tlsext_tick_md EVP_sha256
179 /* Next Protocol Negotiation */
180 #if !defined(OPENSSL_NO_NEXTPROTONEG) && defined(OPENSSL_NPN_NEGOTIATED)
184 /* Secure Remote Password */
185 #if !defined(OPENSSL_NO_SRP) && defined(SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB)
187 #include <openssl/srp.h>
190 #endif /* !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name) */
192 /* mod_ssl headers */
193 #include "ssl_util_ssl.h"
195 APLOG_USE_MODULE(ssl);
198 * Provide reasonable default for some defines
201 #define PFALSE ((void *)FALSE)
204 #define PTRUE ((void *)TRUE)
214 #define RAND_MAX INT_MAX
218 * Provide reasonable defines for some types
221 #define UCHAR unsigned char
225 * Provide useful shorthands
227 #define strEQ(s1,s2) (strcmp(s1,s2) == 0)
228 #define strNE(s1,s2) (strcmp(s1,s2) != 0)
229 #define strEQn(s1,s2,n) (strncmp(s1,s2,n) == 0)
230 #define strNEn(s1,s2,n) (strncmp(s1,s2,n) != 0)
232 #define strcEQ(s1,s2) (strcasecmp(s1,s2) == 0)
233 #define strcNE(s1,s2) (strcasecmp(s1,s2) != 0)
234 #define strcEQn(s1,s2,n) (strncasecmp(s1,s2,n) == 0)
235 #define strcNEn(s1,s2,n) (strncasecmp(s1,s2,n) != 0)
237 #define strIsEmpty(s) (s == NULL || s[0] == NUL)
239 #define myConnConfig(c) \
240 (SSLConnRec *)ap_get_module_config(c->conn_config, &ssl_module)
241 #define myCtxConfig(sslconn, sc) (sslconn->is_proxy ? sc->proxy : sc->server)
242 #define myConnConfigSet(c, val) \
243 ap_set_module_config(c->conn_config, &ssl_module, val)
244 #define mySrvConfig(srv) (SSLSrvConfigRec *)ap_get_module_config(srv->module_config, &ssl_module)
245 #define myDirConfig(req) (SSLDirConfigRec *)ap_get_module_config(req->per_dir_config, &ssl_module)
246 #define myModConfig(srv) (mySrvConfig((srv)))->mc
247 #define mySrvFromConn(c) (myConnConfig(c))->server
248 #define mySrvConfigFromConn(c) mySrvConfig(mySrvFromConn(c))
249 #define myModConfigFromConn(c) myModConfig(mySrvFromConn(c))
252 * Defaults for the configuration
254 #ifndef SSL_SESSION_CACHE_TIMEOUT
255 #define SSL_SESSION_CACHE_TIMEOUT 300
258 /* Default setting for per-dir reneg buffer. */
259 #ifndef DEFAULT_RENEG_BUFFER_SIZE
260 #define DEFAULT_RENEG_BUFFER_SIZE (128 * 1024)
263 /* Default for OCSP response validity */
264 #ifndef DEFAULT_OCSP_MAX_SKEW
265 #define DEFAULT_OCSP_MAX_SKEW (60 * 5)
268 /* Default timeout for OCSP queries */
269 #ifndef DEFAULT_OCSP_TIMEOUT
270 #define DEFAULT_OCSP_TIMEOUT 10
274 * Define the SSL options
276 #define SSL_OPT_NONE (0)
277 #define SSL_OPT_RELSET (1<<0)
278 #define SSL_OPT_STDENVVARS (1<<1)
279 #define SSL_OPT_EXPORTCERTDATA (1<<3)
280 #define SSL_OPT_FAKEBASICAUTH (1<<4)
281 #define SSL_OPT_STRICTREQUIRE (1<<5)
282 #define SSL_OPT_OPTRENEGOTIATE (1<<6)
283 #define SSL_OPT_LEGACYDNFORMAT (1<<7)
284 typedef int ssl_opt_t;
287 * Define the SSL Protocol options
289 #define SSL_PROTOCOL_NONE (0)
290 #define SSL_PROTOCOL_SSLV2 (1<<0)
291 #define SSL_PROTOCOL_SSLV3 (1<<1)
292 #define SSL_PROTOCOL_TLSV1 (1<<2)
294 #define SSL_PROTOCOL_TLSV1_1 (1<<3)
295 #define SSL_PROTOCOL_TLSV1_2 (1<<4)
296 #define SSL_PROTOCOL_ALL (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1| \
297 SSL_PROTOCOL_TLSV1_1|SSL_PROTOCOL_TLSV1_2)
299 #define SSL_PROTOCOL_ALL (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1)
301 typedef int ssl_proto_t;
304 * Define the SSL verify levels
307 SSL_CVERIFY_UNSET = UNSET,
308 SSL_CVERIFY_NONE = 0,
309 SSL_CVERIFY_OPTIONAL = 1,
310 SSL_CVERIFY_REQUIRE = 2,
311 SSL_CVERIFY_OPTIONAL_NO_CA = 3
314 #define SSL_VERIFY_PEER_STRICT \
315 (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
317 #define ssl_verify_error_is_optional(errnum) \
318 ((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) \
319 || (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
320 || (errnum == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) \
321 || (errnum == X509_V_ERR_CERT_UNTRUSTED) \
322 || (errnum == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
328 SSL_CRLCHECK_UNSET = UNSET,
329 SSL_CRLCHECK_NONE = 0,
330 SSL_CRLCHECK_LEAF = 1,
331 SSL_CRLCHECK_CHAIN = 2
335 * Define the SSL pass phrase dialog types
338 SSL_PPTYPE_UNSET = UNSET,
339 SSL_PPTYPE_BUILTIN = 0,
340 SSL_PPTYPE_FILTER = 1,
345 * Define the Path Checking modes
347 #define SSL_PCM_EXISTS 1
348 #define SSL_PCM_ISREG 2
349 #define SSL_PCM_ISDIR 4
350 #define SSL_PCM_ISNONZERO 8
351 typedef unsigned int ssl_pathcheck_t;
354 * Define the SSL enabled state
357 SSL_ENABLED_UNSET = UNSET,
358 SSL_ENABLED_FALSE = 0,
359 SSL_ENABLED_TRUE = 1,
360 SSL_ENABLED_OPTIONAL = 3
364 * Define the SSL requirement structure
368 ap_expr_info_t *mpExpr;
372 * Define the SSL random number generator seeding source
375 SSL_RSCTX_STARTUP = 1,
376 SSL_RSCTX_CONNECT = 2
379 SSL_RSSRC_BUILTIN = 1,
392 * Define the structure of an ASN.1 anything
396 unsigned char *cpData;
397 apr_time_t source_mtime;
401 * Define the mod_ssl per-module configuration structure
402 * (i.e. the global configuration for each httpd process)
406 SSL_SHUTDOWN_TYPE_UNSET,
407 SSL_SHUTDOWN_TYPE_STANDARD,
408 SSL_SHUTDOWN_TYPE_UNCLEAN,
409 SSL_SHUTDOWN_TYPE_ACCURATE
410 } ssl_shutdown_type_e;
414 const char *client_dn;
416 ssl_shutdown_type_e shutdown_type;
417 const char *verify_info;
418 const char *verify_error;
423 NON_SSL_OK = 0, /* is SSL request, or error handling completed */
424 NON_SSL_SEND_HDR_SEP, /* Need to send the header separator */
425 NON_SSL_SET_ERROR_MSG /* Need to set the error message */
428 /* Track the handshake/renegotiation state for the connection so
429 * that all client-initiated renegotiations can be rejected, as a
430 * partial fix for CVE-2009-3555. */
432 RENEG_INIT = 0, /* Before initial handshake */
433 RENEG_REJECT, /* After initial handshake; any client-initiated
434 * renegotiation should be rejected */
435 RENEG_ALLOW, /* A server-initiated renegotiation is taking
436 * place (as dictated by configuration) */
437 RENEG_ABORT /* Renegotiation initiated by client, abort the
442 /* Poor man's inter-module optional hooks for NPN. */
443 apr_array_header_t *npn_advertfns; /* list of ssl_npn_advertise_protos callbacks */
444 apr_array_header_t *npn_negofns; /* list of ssl_npn_proto_negotiated callbacks. */
450 /* BIG FAT WARNING: SSLModConfigRec has unusual memory lifetime: it is
451 * allocated out of the "process" pool and only a single such
452 * structure is created and used for the lifetime of the process.
453 * (The process pool is s->process->pool and is stored in the .pPool
454 * field.) Most members of this structure are likewise allocated out
455 * of the process pool, but notably sesscache and sesscache_context
458 * The structure is treated as mostly immutable after a single config
459 * parse has completed; the post_config hook (ssl_init_Module) flips
460 * the bFixed flag to true and subsequent invocations of the config
461 * callbacks hence do nothing.
463 * This odd lifetime strategy is used so that encrypted private keys
464 * can be decrypted once at startup and continue to be used across
465 * subsequent server reloads where the interactive password prompt is
468 * It is really an ABI nightmare waiting to happen since DSOs are
469 * reloaded across restarts, and nothing prevents the struct type
470 * changing across such reloads, yet the cached structure will be
471 * assumed to match regardless.
473 * This should really be fixed using a smaller structure which only
474 * stores that which is absolutely necessary (the private keys, maybe
475 * the random seed), and have that structure be strictly ABI-versioned
483 /* OpenSSL SSL_SESS_CACHE_* flags: */
486 /* The configured provider, and associated private data
488 const ap_socache_provider_t *sesscache;
489 ap_socache_instance_t *sesscache_context;
491 apr_global_mutex_t *pMutex;
492 apr_array_header_t *aRandSeed;
493 apr_hash_t *tVHostKeys;
495 /* A hash table of pointers to ssl_asn1_t structures. The structures
496 * are used to store private keys in raw DER format (serialized OpenSSL
497 * PrivateKey structures). The table is indexed by (vhost-id,
498 * index), for example the string "vhost.example.com:443:0". */
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 /** Structure representing configured filenames for certs and keys for
515 /* Lists of configured certs and keys for this server */
516 apr_array_header_t *cert_files;
517 apr_array_header_t *key_files;
519 /** Certificates which specify the set of CA names which should be
520 * sent in the CertificateRequest message: */
521 const char *ca_name_path;
522 const char *ca_name_file;
523 } modssl_pk_server_t;
526 /** proxy can have any number of cert/key pairs */
527 const char *cert_file;
528 const char *cert_path;
529 const char *ca_cert_file;
530 STACK_OF(X509_INFO) *certs; /* Contains End Entity certs */
531 STACK_OF(X509) **ca_certs; /* Contains ONLY chain certs for
532 * each item in certs.
533 * (ptr to array of ptrs) */
536 /** stuff related to authentication that can also be per-dir */
538 /** known/trusted CAs */
539 const char *ca_cert_path;
540 const char *ca_cert_file;
542 const char *cipher_suite;
544 /** for client or downstream server authentication */
546 ssl_verify_t verify_mode;
549 #ifdef HAVE_TLS_SESSION_TICKETS
551 const char *file_path;
552 unsigned char key_name[16];
553 unsigned char hmac_secret[16];
554 unsigned char aes_key[16];
555 } modssl_ticket_key_t;
558 #ifdef HAVE_SSL_CONF_CMD
565 typedef struct SSLSrvConfigRec SSLSrvConfigRec;
568 SSLSrvConfigRec *sc; /** pointer back to server config */
571 /** we are one or the other */
572 modssl_pk_server_t *pks;
573 modssl_pk_proxy_t *pkp;
575 #ifdef HAVE_TLS_SESSION_TICKETS
576 modssl_ticket_key_t *ticket_key;
579 ssl_proto_t protocol;
581 /** config for handling encrypted keys */
582 ssl_pphrase_t pphrase_dialog_type;
583 const char *pphrase_dialog_path;
585 const char *cert_chain;
587 /** certificate revocation list */
588 const char *crl_path;
589 const char *crl_file;
590 ssl_crlcheck_t crl_check_mode;
592 #ifdef HAVE_OCSP_STAPLING
593 /** OCSP stapling options */
594 BOOL stapling_enabled;
595 long stapling_resptime_skew;
596 long stapling_resp_maxage;
597 int stapling_cache_timeout;
598 BOOL stapling_return_errors;
599 BOOL stapling_fake_trylater;
600 int stapling_errcache_timeout;
601 apr_interval_time_t stapling_responder_timeout;
602 const char *stapling_force_url;
607 char *srp_unknown_user_seed;
608 SRP_VBASE *srp_vbase;
611 modssl_auth_ctx_t auth;
613 BOOL ocsp_enabled; /* true if OCSP verification enabled */
614 BOOL ocsp_force_default; /* true if the default responder URL is
615 * used regardless of per-cert URL */
616 const char *ocsp_responder; /* default responder URL */
617 long ocsp_resptime_skew;
618 long ocsp_resp_maxage;
619 apr_interval_time_t ocsp_responder_timeout;
620 BOOL ocsp_use_request_nonce;
622 #ifdef HAVE_SSL_CONF_CMD
623 SSL_CONF_CTX *ssl_ctx_config; /* Configuration context */
624 apr_array_header_t *ssl_ctx_param; /* parameters to pass to SSL_CTX */
628 struct SSLSrvConfigRec {
630 ssl_enabled_t enabled;
632 const char *vhost_id;
634 int session_cache_timeout;
635 BOOL cipher_server_pref;
637 modssl_ctx_t *server;
639 ssl_enabled_t proxy_ssl_check_peer_expire;
640 ssl_enabled_t proxy_ssl_check_peer_cn;
641 ssl_enabled_t proxy_ssl_check_peer_name;
643 ssl_enabled_t strict_sni_vhost_check;
648 #ifndef OPENSSL_NO_COMP
651 BOOL session_tickets;
655 * Define the mod_ssl per-directory configuration structure
656 * (i.e. the local configuration for all <Directory>
657 * and .htaccess contexts)
661 apr_array_header_t *aRequirement;
663 ssl_opt_t nOptionsAdd;
664 ssl_opt_t nOptionsDel;
665 const char *szCipherSuite;
666 ssl_verify_t nVerifyClient;
668 const char *szCACertificatePath;
669 const char *szCACertificateFile;
670 const char *szUserName;
671 apr_size_t nRenegBufferSize;
675 * function prototypes
678 /** API glue structures */
679 extern module AP_MODULE_DECLARE_DATA ssl_module;
681 /** configuration handling */
682 SSLModConfigRec *ssl_config_global_create(server_rec *);
683 void ssl_config_global_fix(SSLModConfigRec *);
684 BOOL ssl_config_global_isfixed(SSLModConfigRec *);
685 void *ssl_config_server_create(apr_pool_t *, server_rec *);
686 void *ssl_config_server_merge(apr_pool_t *, void *, void *);
687 void *ssl_config_perdir_create(apr_pool_t *, char *);
688 void *ssl_config_perdir_merge(apr_pool_t *, void *, void *);
689 const char *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, void *, const char *);
690 const char *ssl_cmd_SSLCryptoDevice(cmd_parms *, void *, const char *);
691 const char *ssl_cmd_SSLRandomSeed(cmd_parms *, void *, const char *, const char *, const char *);
692 const char *ssl_cmd_SSLEngine(cmd_parms *, void *, const char *);
693 const char *ssl_cmd_SSLCipherSuite(cmd_parms *, void *, const char *);
694 const char *ssl_cmd_SSLCertificateFile(cmd_parms *, void *, const char *);
695 const char *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, void *, const char *);
696 const char *ssl_cmd_SSLCertificateChainFile(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_SSLCompression(cmd_parms *, void *, int flag);
706 const char *ssl_cmd_SSLSessionTickets(cmd_parms *, void *, int flag);
707 const char *ssl_cmd_SSLVerifyClient(cmd_parms *, void *, const char *);
708 const char *ssl_cmd_SSLVerifyDepth(cmd_parms *, void *, const char *);
709 const char *ssl_cmd_SSLSessionCache(cmd_parms *, void *, const char *);
710 const char *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, void *, const char *);
711 const char *ssl_cmd_SSLProtocol(cmd_parms *, void *, const char *);
712 const char *ssl_cmd_SSLOptions(cmd_parms *, void *, const char *);
713 const char *ssl_cmd_SSLRequireSSL(cmd_parms *, void *);
714 const char *ssl_cmd_SSLRequire(cmd_parms *, void *, const char *);
715 const char *ssl_cmd_SSLUserName(cmd_parms *, void *, const char *);
716 const char *ssl_cmd_SSLRenegBufferSize(cmd_parms *cmd, void *dcfg, const char *arg);
717 const char *ssl_cmd_SSLStrictSNIVHostCheck(cmd_parms *cmd, void *dcfg, int flag);
718 const char *ssl_cmd_SSLInsecureRenegotiation(cmd_parms *cmd, void *dcfg, int flag);
720 const char *ssl_cmd_SSLProxyEngine(cmd_parms *cmd, void *dcfg, int flag);
721 const char *ssl_cmd_SSLProxyProtocol(cmd_parms *, void *, const char *);
722 const char *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, void *, const char *);
723 const char *ssl_cmd_SSLProxyVerify(cmd_parms *, void *, const char *);
724 const char *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, void *, const char *);
725 const char *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, void *, const char *);
726 const char *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, void *, const char *);
727 const char *ssl_cmd_SSLProxyCARevocationPath(cmd_parms *, void *, const char *);
728 const char *ssl_cmd_SSLProxyCARevocationFile(cmd_parms *, void *, const char *);
729 const char *ssl_cmd_SSLProxyCARevocationCheck(cmd_parms *, void *, const char *);
730 const char *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
731 const char *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
732 const char *ssl_cmd_SSLProxyMachineCertificateChainFile(cmd_parms *, void *, const char *);
733 #ifdef HAVE_TLS_SESSION_TICKETS
734 const char *ssl_cmd_SSLSessionTicketKeyFile(cmd_parms *cmd, void *dcfg, const char *arg);
736 const char *ssl_cmd_SSLProxyCheckPeerExpire(cmd_parms *cmd, void *dcfg, int flag);
737 const char *ssl_cmd_SSLProxyCheckPeerCN(cmd_parms *cmd, void *dcfg, int flag);
738 const char *ssl_cmd_SSLProxyCheckPeerName(cmd_parms *cmd, void *dcfg, int flag);
740 const char *ssl_cmd_SSLOCSPOverrideResponder(cmd_parms *cmd, void *dcfg, int flag);
741 const char *ssl_cmd_SSLOCSPDefaultResponder(cmd_parms *cmd, void *dcfg, const char *arg);
742 const char *ssl_cmd_SSLOCSPResponseTimeSkew(cmd_parms *cmd, void *dcfg, const char *arg);
743 const char *ssl_cmd_SSLOCSPResponseMaxAge(cmd_parms *cmd, void *dcfg, const char *arg);
744 const char *ssl_cmd_SSLOCSPResponderTimeout(cmd_parms *cmd, void *dcfg, const char *arg);
745 const char *ssl_cmd_SSLOCSPUseRequestNonce(cmd_parms *cmd, void *dcfg, int flag);
746 const char *ssl_cmd_SSLOCSPEnable(cmd_parms *cmd, void *dcfg, int flag);
748 #ifdef HAVE_SSL_CONF_CMD
749 const char *ssl_cmd_SSLOpenSSLConfCmd(cmd_parms *cmd, void *dcfg, const char *arg1, const char *arg2);
753 const char *ssl_cmd_SSLSRPVerifierFile(cmd_parms *cmd, void *dcfg, const char *arg);
754 const char *ssl_cmd_SSLSRPUnknownUserSeed(cmd_parms *cmd, void *dcfg, const char *arg);
757 const char *ssl_cmd_SSLFIPS(cmd_parms *cmd, void *dcfg, int flag);
759 /** module initialization */
760 apr_status_t ssl_init_Module(apr_pool_t *, apr_pool_t *, apr_pool_t *, server_rec *);
761 apr_status_t ssl_init_Engine(server_rec *, apr_pool_t *);
762 apr_status_t ssl_init_ConfigureServer(server_rec *, apr_pool_t *, apr_pool_t *, SSLSrvConfigRec *,
763 apr_array_header_t *);
764 apr_status_t ssl_init_CheckServers(server_rec *, apr_pool_t *);
766 *ssl_init_FindCAList(server_rec *, apr_pool_t *, const char *, const char *);
767 void ssl_init_Child(apr_pool_t *, server_rec *);
768 apr_status_t ssl_init_ModuleKill(void *data);
770 /** Apache API hooks */
771 int ssl_hook_Auth(request_rec *);
772 int ssl_hook_UserCheck(request_rec *);
773 int ssl_hook_Access(request_rec *);
774 int ssl_hook_Fixup(request_rec *);
775 int ssl_hook_ReadReq(request_rec *);
776 int ssl_hook_Upgrade(request_rec *);
777 void ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s);
779 /** Apache authz provisders */
780 extern const authz_provider ssl_authz_provider_require_ssl;
781 extern const authz_provider ssl_authz_provider_verify_client;
783 /** OpenSSL callbacks */
784 DH *ssl_callback_TmpDH(SSL *, int, int);
785 int ssl_callback_SSLVerify(int, X509_STORE_CTX *);
786 int ssl_callback_SSLVerify_CRL(int, X509_STORE_CTX *, conn_rec *);
787 int ssl_callback_proxy_cert(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
788 int ssl_callback_NewSessionCacheEntry(SSL *, SSL_SESSION *);
789 SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *, unsigned char *, int, int *);
790 void ssl_callback_DelSessionCacheEntry(SSL_CTX *, SSL_SESSION *);
791 void ssl_callback_Info(const SSL *, int, int);
793 int ssl_callback_ServerNameIndication(SSL *, int *, modssl_ctx_t *);
795 #ifdef HAVE_TLS_SESSION_TICKETS
796 int ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
797 EVP_CIPHER_CTX *, HMAC_CTX *, int);
799 int ssl_callback_AdvertiseNextProtos(SSL *ssl, const unsigned char **data, unsigned int *len, void *arg);
801 /** Session Cache Support */
802 apr_status_t ssl_scache_init(server_rec *, apr_pool_t *);
803 void ssl_scache_status_register(apr_pool_t *p);
804 void ssl_scache_kill(server_rec *);
805 BOOL ssl_scache_store(server_rec *, UCHAR *, int,
806 apr_time_t, SSL_SESSION *, apr_pool_t *);
807 SSL_SESSION *ssl_scache_retrieve(server_rec *, UCHAR *, int, apr_pool_t *);
808 void ssl_scache_remove(server_rec *, UCHAR *, int,
811 /** OCSP Stapling Support */
812 #ifdef HAVE_OCSP_STAPLING
813 const char *ssl_cmd_SSLStaplingCache(cmd_parms *, void *, const char *);
814 const char *ssl_cmd_SSLUseStapling(cmd_parms *, void *, int);
815 const char *ssl_cmd_SSLStaplingResponseTimeSkew(cmd_parms *, void *, const char *);
816 const char *ssl_cmd_SSLStaplingResponseMaxAge(cmd_parms *, void *, const char *);
817 const char *ssl_cmd_SSLStaplingStandardCacheTimeout(cmd_parms *, void *, const char *);
818 const char *ssl_cmd_SSLStaplingErrorCacheTimeout(cmd_parms *, void *, const char *);
819 const char *ssl_cmd_SSLStaplingReturnResponderErrors(cmd_parms *, void *, int);
820 const char *ssl_cmd_SSLStaplingFakeTryLater(cmd_parms *, void *, int);
821 const char *ssl_cmd_SSLStaplingResponderTimeout(cmd_parms *, void *, const char *);
822 const char *ssl_cmd_SSLStaplingForceURL(cmd_parms *, void *, const char *);
823 apr_status_t modssl_init_stapling(server_rec *, apr_pool_t *, apr_pool_t *, modssl_ctx_t *);
824 void ssl_stapling_certinfo_hash_init(apr_pool_t *);
825 int ssl_stapling_init_cert(server_rec *, apr_pool_t *, apr_pool_t *,
826 modssl_ctx_t *, X509 *);
829 int ssl_callback_SRPServerParams(SSL *, int *, void *);
833 void ssl_io_filter_init(conn_rec *, request_rec *r, SSL *);
834 void ssl_io_filter_register(apr_pool_t *);
835 long ssl_io_data_cb(BIO *, int, const char *, int, long, long);
837 /* ssl_io_buffer_fill fills the setaside buffering of the HTTP request
838 * to allow an SSL renegotiation to take place. */
839 int ssl_io_buffer_fill(request_rec *r, apr_size_t maxlen);
842 int ssl_rand_seed(server_rec *, apr_pool_t *, ssl_rsctx_t, char *);
844 /** Utility Functions */
845 char *ssl_util_vhostid(apr_pool_t *, server_rec *);
846 apr_file_t *ssl_util_ppopen(server_rec *, apr_pool_t *, const char *,
847 const char * const *);
848 void ssl_util_ppclose(server_rec *, apr_pool_t *, apr_file_t *);
849 char *ssl_util_readfilter(server_rec *, apr_pool_t *, const char *,
850 const char * const *);
851 BOOL ssl_util_path_check(ssl_pathcheck_t, const char *, apr_pool_t *);
852 void ssl_util_thread_setup(apr_pool_t *);
853 int ssl_init_ssl_connection(conn_rec *c, request_rec *r);
855 /** Pass Phrase Support */
856 apr_status_t ssl_load_encrypted_pkey(server_rec *, apr_pool_t *, int,
857 const char *, apr_array_header_t **);
859 /** Diffie-Hellman Parameter Support */
860 DH *ssl_dh_GetParamFromFile(const char *);
862 EC_GROUP *ssl_ec_GetParamFromFile(const char *);
865 unsigned char *ssl_asn1_table_set(apr_hash_t *table,
869 ssl_asn1_t *ssl_asn1_table_get(apr_hash_t *table,
872 void ssl_asn1_table_unset(apr_hash_t *table,
876 int ssl_mutex_init(server_rec *, apr_pool_t *);
877 int ssl_mutex_reinit(server_rec *, apr_pool_t *);
878 int ssl_mutex_on(server_rec *);
879 int ssl_mutex_off(server_rec *);
881 int ssl_stapling_mutex_reinit(server_rec *, apr_pool_t *);
883 /* mutex type names for Mutex directive */
884 #define SSL_CACHE_MUTEX_TYPE "ssl-cache"
885 #define SSL_STAPLING_MUTEX_TYPE "ssl-stapling"
887 apr_status_t ssl_die(server_rec *);
889 /** Logfile Support */
890 void ssl_log_ssl_error(const char *, int, int, server_rec *);
892 /* ssl_log_xerror, ssl_log_cxerror and ssl_log_rxerror are wrappers for the
893 * respective ap_log_*error functions and take a certificate as an
894 * additional argument (whose details are appended to the log message).
895 * The other arguments are interpreted exactly as with their ap_log_*error
897 void ssl_log_xerror(const char *file, int line, int level,
898 apr_status_t rv, apr_pool_t *p, server_rec *s,
899 X509 *cert, const char *format, ...)
900 __attribute__((format(printf,8,9)));
902 void ssl_log_cxerror(const char *file, int line, int level,
903 apr_status_t rv, conn_rec *c, X509 *cert,
904 const char *format, ...)
905 __attribute__((format(printf,7,8)));
907 void ssl_log_rxerror(const char *file, int line, int level,
908 apr_status_t rv, request_rec *r, X509 *cert,
909 const char *format, ...)
910 __attribute__((format(printf,7,8)));
912 #define SSLLOG_MARK __FILE__,__LINE__
916 /* Register variables for the lifetime of the process pool 'p'. */
917 void ssl_var_register(apr_pool_t *p);
918 char *ssl_var_lookup(apr_pool_t *, server_rec *, conn_rec *, request_rec *, char *);
919 apr_array_header_t *ssl_ext_list(apr_pool_t *p, conn_rec *c, int peer, const char *extension);
921 void ssl_var_log_config_register(apr_pool_t *p);
923 /* Extract SSL_*_DN_* variables into table 't' from SSL object 'ssl',
924 * allocating from 'p': */
925 void modssl_var_extract_dns(apr_table_t *t, SSL *ssl, apr_pool_t *p);
927 /* Extract SSL_*_SAN_* variables (subjectAltName entries) into table 't'
928 * from SSL object 'ssl', allocating from 'p'. */
929 void modssl_var_extract_san_entries(apr_table_t *t, SSL *ssl, apr_pool_t *p);
931 #ifndef OPENSSL_NO_OCSP
932 /* Perform OCSP validation of the current cert in the given context.
933 * Returns non-zero on success or zero on failure. On failure, the
934 * context error code is set. */
935 int modssl_verify_ocsp(X509_STORE_CTX *ctx, SSLSrvConfigRec *sc,
936 server_rec *s, conn_rec *c, apr_pool_t *pool);
938 /* OCSP helper interface; dispatches the given OCSP request to the
939 * responder at the given URI. Returns the decoded OCSP response
940 * object, or NULL on error (in which case, errors will have been
941 * logged). Pool 'p' is used for temporary allocations. */
942 OCSP_RESPONSE *modssl_dispatch_ocsp_request(const apr_uri_t *uri,
943 apr_interval_time_t timeout,
944 OCSP_REQUEST *request,
945 conn_rec *c, apr_pool_t *p);
948 /* Retrieve DH parameters for given key length. Return value should
949 * be treated as unmutable, since it is stored in process-global
951 DH *modssl_get_dh_params(unsigned keylen);
954 extern int ssl_running_on_valgrind;
957 #endif /* SSL_PRIVATE_H */