📄 ssl_engine_init.c
字号:
/* _ _** _ __ ___ ___ __| | ___ ___| | mod_ssl** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org** |_____|** ssl_engine_init.c** Initialization of Servers*//* ==================================================================== * Copyright (c) 1998-2006 Ralf S. Engelschall. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by * Ralf S. Engelschall <rse@engelschall.com> for use in the * mod_ssl project (http://www.modssl.org/)." * * 4. The names "mod_ssl" must not be used to endorse or promote * products derived from this software without prior written * permission. For written permission, please contact * rse@engelschall.com. * * 5. Products derived from this software may not be called "mod_ssl" * nor may "mod_ssl" appear in their names without prior * written permission of Ralf S. Engelschall. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by * Ralf S. Engelschall <rse@engelschall.com> for use in the * mod_ssl project (http://www.modssl.org/)." * * THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RALF S. ENGELSCHALL OR * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== *//* ==================================================================== * Copyright (c) 1995-1999 Ben Laurie. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by Ben Laurie * for use in the Apache-SSL HTTP server project." * * 4. The name "Apache-SSL Server" must not be used to * endorse or promote products derived from this software without * prior written permission. * * 5. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Ben Laurie * for use in the Apache-SSL HTTP server project." * * THIS SOFTWARE IS PROVIDED BY BEN LAURIE ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEN LAURIE OR * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ /* ``Recursive, adj.; see Recursive.'' -- Unknown */#include "mod_ssl.h"/* _________________________________________________________________**** Module Initialization** _________________________________________________________________*//* * Per-module initialization */void ssl_init_Module(server_rec *s, pool *p){ SSLModConfigRec *mc = myModConfig(); SSLSrvConfigRec *sc; server_rec *s2; char *cp; mc->nInitCount++; /* * Let us cleanup on restarts and exists */ ap_register_cleanup(p, s, ssl_init_ModuleKill, ssl_init_ChildKill); /* * Any init round fixes the global config */ ssl_config_global_create(); /* just to avoid problems */ ssl_config_global_fix(); /* * try to fix the configuration and open the dedicated SSL * logfile as early as possible */ for (s2 = s; s2 != NULL; s2 = s2->next) { sc = mySrvConfig(s2); /* Fix up stuff that may not have been set */ if (sc->bEnabled == UNSET) sc->bEnabled = FALSE; if (sc->nVerifyClient == SSL_CVERIFY_UNSET) sc->nVerifyClient = SSL_CVERIFY_NONE; if (sc->nVerifyDepth == UNSET) sc->nVerifyDepth = 1;#ifdef SSL_EXPERIMENTAL_PROXY if (sc->nProxyVerifyDepth == UNSET) sc->nProxyVerifyDepth = 1;#endif if (sc->nSessionCacheTimeout == UNSET) sc->nSessionCacheTimeout = SSL_SESSION_CACHE_TIMEOUT; if (sc->nPassPhraseDialogType == SSL_PPTYPE_UNSET) sc->nPassPhraseDialogType = SSL_PPTYPE_BUILTIN; /* Open the dedicated SSL logfile */ ssl_log_open(s, s2, p); } /* * Identification */ if (mc->nInitCount == 1) { ssl_log(s, SSL_LOG_INFO, "Server: %s, Interface: %s, Library: %s", SERVER_BASEVERSION, ssl_var_lookup(p, NULL, NULL, NULL, "SSL_VERSION_INTERFACE"), ssl_var_lookup(p, NULL, NULL, NULL, "SSL_VERSION_LIBRARY"));#ifdef WIN32 ssl_log(s, SSL_LOG_WARN, "You are using mod_ssl under Win32. " "This combination is *NOT* officially supported. " "Use it at your own risk!");#endif } /* * Initialization round information */ if (mc->nInitCount == 1) ssl_log(s, SSL_LOG_INFO, "Init: 1st startup round (still not detached)"); else if (mc->nInitCount == 2) ssl_log(s, SSL_LOG_INFO, "Init: 2nd startup round (already detached)"); else ssl_log(s, SSL_LOG_INFO, "Init: %d%s restart round (already detached)", mc->nInitCount-2, (mc->nInitCount-2) == 1 ? "st" : "nd");#ifdef SSL_VENDOR ap_hook_use("ap::mod_ssl::vendor::init_module", AP_HOOK_SIG3(void,ptr,ptr), AP_HOOK_ALL, s, p);#endif /* * The initialization phase inside the Apache API is totally bogus. * We actually have three non-trivial problems: * * 1. Under Unix the API does a 2-round initialization of modules while * under Win32 it doesn't. This means we have to make sure that at * least the pass phrase dialog doesn't occur twice. We overcome this * problem by using a counter (mc->nInitCount) which has to * survive the init rounds. * * 2. Between the first and the second round Apache detaches from * the terminal under Unix. This means that our pass phrase dialog * _has_ to be done in the first round and _cannot_ be done in the * second round. * * 3. When Dynamic Shared Object (DSO) mechanism is used under Unix the * module segment (code & data) gets unloaded and re-loaded between * the first and the second round. This means no global data survives * between first and the second init round. We overcome this by using * an entry ("ssl_module") inside the ap_global_ctx. * * The situation as a table: * * Unix/static Unix/DSO Win32 Action Required * (-DSHARED_MODULE) (-DWIN32) * ----------- ----------------- --------- ----------------------------------- * - load module - - * init init init SSL library init, Pass Phrase Dialog * detach detach - - * - reload module - - * init init - SSL library init, mod_ssl init * * Ok, now try to solve this totally ugly situation... */#ifdef SHARED_MODULE ssl_log(s, SSL_LOG_INFO, "Init: %snitializing %s library", mc->nInitCount == 1 ? "I" : "Rei", SSL_LIBRARY_NAME);#ifdef SSL_EXPERIMENTAL_ENGINE ssl_init_Engine(s, p);#endif ssl_init_SSLLibrary();#else if (mc->nInitCount <= 2) { ssl_log(s, SSL_LOG_INFO, "Init: %snitializing %s library", mc->nInitCount == 1 ? "I" : "Rei", SSL_LIBRARY_NAME);#ifdef SSL_EXPERIMENTAL_ENGINE ssl_init_Engine(s, p);#endif ssl_init_SSLLibrary(); }#endif if (mc->nInitCount == 1) { ssl_pphrase_Handle(s, p); ssl_init_TmpKeysHandle(SSL_TKP_GEN, s, p);#ifndef WIN32 return;#endif } /* * Warn the user that he should use the session cache. * But we can operate without it, of course. */ if (mc->nSessionCacheMode == SSL_SCMODE_UNSET) { ssl_log(s, SSL_LOG_WARN, "Init: Session Cache is not configured [hint: SSLSessionCache]"); mc->nSessionCacheMode = SSL_SCMODE_NONE; } /* * initialize the mutex handling and session caching */ ssl_mutex_init(s, p); ssl_scache_init(s, p); /* * Seed the Pseudo Random Number Generator (PRNG) */ ssl_rand_seed(s, p, SSL_RSCTX_STARTUP, "Init: "); /* * allocate the temporary RSA keys and DH params */ ssl_init_TmpKeysHandle(SSL_TKP_ALLOC, s, p); /* * initialize servers */ ssl_log(s, SSL_LOG_INFO, "Init: Initializing (virtual) servers for SSL"); for (s2 = s; s2 != NULL; s2 = s2->next) { sc = mySrvConfig(s2); /* * Either now skip this server when SSL is disabled for * it or give out some information about what we're * configuring. */ if (!sc->bEnabled) continue; ssl_log(s2, SSL_LOG_INFO, "Init: Configuring server %s for SSL protocol", ssl_util_vhostid(p, s2)); /* * Read the server certificate and key */ ssl_init_ConfigureServer(s2, p, sc); } /* * Configuration consistency checks */ ssl_init_CheckServers(s, p); /* * Announce mod_ssl and SSL library in HTTP Server field * as ``mod_ssl/X.X.X OpenSSL/X.X.X'' */ if ((cp = ssl_var_lookup(p, NULL, NULL, NULL, "SSL_VERSION_PRODUCT")) != NULL && cp[0] != NUL) ap_add_version_component(cp); ap_add_version_component(ssl_var_lookup(p, NULL, NULL, NULL, "SSL_VERSION_INTERFACE")); ap_add_version_component(ssl_var_lookup(p, NULL, NULL, NULL, "SSL_VERSION_LIBRARY")); return;}/* * Initialize SSL library (also already needed for the pass phrase dialog) */void ssl_init_SSLLibrary(void){#ifdef WIN32 CRYPTO_malloc_init();#endif SSL_load_error_strings(); SSL_library_init(); ssl_util_thread_setup(); X509V3_add_standard_extensions(); return;}/* * Support for external a Crypto Device ("engine"), usually * a hardware accellerator card for crypto operations. */#ifdef SSL_EXPERIMENTAL_ENGINEvoid ssl_init_Engine(server_rec *s, pool *p){ SSLModConfigRec *mc = myModConfig(); ENGINE *e; if (mc->szCryptoDevice != NULL) { if ((e = ENGINE_by_id(mc->szCryptoDevice)) == NULL) { ssl_log(s, SSL_LOG_ERROR|SSL_ADD_SSLERR, "Init: Failed to load Crypto Device API `%s'", mc->szCryptoDevice); ssl_die(); } if (strEQ(mc->szCryptoDevice, "chil")) ENGINE_ctrl(e, ENGINE_CTRL_CHIL_SET_FORKCHECK, 1, 0, 0); if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) { ssl_log(s, SSL_LOG_ERROR|SSL_ADD_SSLERR, "Init: Failed to enable Crypto Device API `%s'", mc->szCryptoDevice); ssl_die(); } ENGINE_free(e); } return;}#endif/* * Handle the Temporary RSA Keys and DH Params */void ssl_init_TmpKeysHandle(int action, server_rec *s, pool *p){ SSLModConfigRec *mc = myModConfig(); ssl_asn1_t *asn1; unsigned char *ucp; RSA *rsa; DH *dh; /* Generate Keys and Params */ if (action == SSL_TKP_GEN) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -