ssl_engine_pphrase.c revision 10efba1d3523c83810086181703a8719a8a0e98a
/* _ _
** _ __ ___ ___ __| | ___ ___| | mod_ssl
** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
** |_____|
** Pass Phrase Dialog
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. 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
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``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 THE APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*/
/* ``Treat your password like your
toothbrush. Don't let anybody
else use it, and get a new one
every six months.''
-- Clifford Stoll */
#include "mod_ssl.h"
/*
* Return true if the named file exists and is readable
*/
{
apr_file_t *fd;
return stat;
return APR_EGENERAL;
return stat;
if (mtime) {
}
return APR_SUCCESS;
}
/* _________________________________________________________________
**
** Pass Phrase and Private Key Handling
** _________________________________________________________________
*/
#define STDERR_FILENO_STORE 50
#define BUILTIN_DIALOG_BACKOFF 2
#define BUILTIN_DIALOG_RETRIES 5
{
char *cpVHostID;
char szPath[MAX_STRING_LEN];
unsigned char *ucp;
int nPassPhrase;
int nPassPhraseCur;
char *cpPassPhraseCur;
int nPassPhraseRetry;
int nPassPhraseDialog;
int nPassPhraseDialogCur;
char **cpp;
int i, j;
char *an;
char *cp;
apr_time_t pkey_mtime = 0;
int isterm = 1;
/*
* Start with a fresh pass phrase array
*/
aPassPhrase = ssl_ds_array_make(p, sizeof(char *));
nPassPhrase = 0;
nPassPhraseDialog = 0;
/*
* Walk through all configured servers
*/
continue;
"Init: Loading certificate & private key of SSL-aware server %s",
/*
* Read in server certificate(s): This is the easy part
* because this file isn't encrypted in any way.
*/
"Init: Server %s should be SSL-aware but has no certificate configured "
"[Hint: SSLCertificateFile]", cpVHostID);
ssl_die();
}
"Init: Can't open server certificate file %s", szPath);
ssl_die();
}
"Init: Unable to read server certificate from file %s", szPath);
ssl_die();
}
/*
* check algorithm type of certificate and make
* sure only one certificate per type is used.
*/
"Init: Multiple %s server certificates not allowed", an);
ssl_die();
}
/*
* Insert the certificate into global module configuration to let it
* survive the processing between the 1st Apache API init round (where
* we operate here) and the 2nd Apache init round (where the
* certificate is actually used to configure mod_ssl's per-server
* configuration structures).
*/
/*
* Free the X509 structure
*/
/*
* Read in the private key: This is the non-trivial part, because the
* key is typically encrypted, so a pass phrase dialog has to be used
* to request it from the user (or it has to be alternatively gathered
* from a dialog program). The important point here is that ISPs
* usually have hundrets of virtual servers configured and a lot of
* them use SSL, so really we have to minimize the pass phrase
* dialogs.
*
* The idea is this: When N virtual hosts are configured and all of
* them use encrypted private keys with different pass phrases, we
* have no chance and have to pop up N pass phrase dialogs. But
* usually the admin is clever enough and uses the same pass phrase
* for more private key files (typically he even uses one single pass
* phrase for all). When this is the case we can minimize the dialogs
*/
/*
* Try to read the private key file with the help of
* the callback function which serves the pass
* phrases to OpenSSL
*/
nPassPhraseCur = 0;
nPassPhraseRetry = 0;
nPassPhraseDialogCur = 0;
pPrivateKey = NULL;
for (;;) {
/*
* Try to read the private key file with the help of
* the callback function which serves the pass
* phrases to OpenSSL
*/
"Init: Can't open server private key file %s",szPath);
ssl_die();
}
/*
* isatty() returns false once httpd has detached from the terminal.
* if the private key is encrypted and SSLPassPhraseDialog is configured to "builtin"
* it isn't possible to prompt for a password. in this case if we already have a
* of course this will not work if the server was started without LoadModule ssl_module
* configured, then restarted with it configured. but we fall through with a chance of
* success if the key is not encrypted. and in the case of fallthrough, pkey_mtime and
* isterm values are used to give a better idea as to what failed.
*/
{
"%s reusing existing private key on restart",
return;
}
}
/*
* when the private key file now was readable,
* it's fine and we go out of the loop
*/
if (bReadable)
break;
/*
* when we have more remembered pass phrases
* try to reuse these first.
*/
if (nPassPhraseCur < nPassPhrase) {
continue;
}
/*
* else it's not readable and we have no more
* remembered pass phrases. Then this has to mean
* that the callback function popped up the dialog
* but a wrong pass phrase was entered. We give the
* user (but not the dialog program) a few more
* chances...
*/
&& cpPassPhraseCur != NULL
&& nPassPhraseRetry < BUILTIN_DIALOG_RETRIES ) {
"(%d more retr%s permitted).\n",
continue;
}
/*
* Ok, anything else now means a fatal error.
*/
if (cpPassPhraseCur == NULL) {
"Init: Unable read passphrase "
"[Hint: key introduced or changed before restart?]");
}
else {
}
}
}
else {
}
}
ssl_die();
}
if (pPrivateKey == NULL) {
"Init: Unable to read server private key from file %s [Hint: Perhaps it is in a separate file? See SSLCertificateKeyFile]", szPath);
ssl_die();
}
/*
* check algorithm type of private key and make
* sure only one private key per type is used.
*/
"Init: Multiple %s server private keys not allowed", an);
ssl_die();
}
/*
* Log the type of reading
*/
if (nPassPhraseDialogCur == 0)
"Init: (%s) unencrypted %s private key - pass phrase not required",
else {
if (cpPassPhraseCur != NULL)
"Init: (%s) encrypted %s private key - pass phrase requested",
else
"Init: (%s) encrypted %s private key - pass phrase reused",
}
/*
* Ok, when we have one more pass phrase store it
*/
if (cpPassPhraseCur != NULL) {
*cpp = cpPassPhraseCur;
nPassPhrase++;
}
/*
* Insert private key into the global module configuration
* (we convert it to a stand-alone DER byte sequence
* because the SSL library uses static variables inside a
* RSA structure which do not survive DSO reloads!)
*/
/*
* Free the private key structure
*/
}
}
/*
* Let the user know when we're successful.
*/
if (nPassPhraseDialog > 0) {
sc = mySrvConfig(s);
}
}
/*
* Wipe out the used memory from the
* pass phrase array and then deallocate it
*/
if (!ssl_ds_array_isempty(aPassPhrase)) {
}
return;
}
{
server_rec *s;
apr_pool_t *p;
int *pnPassPhraseCur;
char **cppPassPhraseCur;
char *cpVHostID;
char *cpAlgoType;
int *pnPassPhraseDialog;
int *pnPassPhraseDialogCur;
int stderr_store;
char **cpp;
int len = -1;
/*
* Reconnect to the context of ssl_phrase_Handle()
*/
sc = mySrvConfig(s);
(*pnPassPhraseDialog)++;
(*pnPassPhraseDialogCur)++;
/*
* When remembered pass phrases are available use them...
*/
return len;
}
/*
* Builtin dialog
*/
char *prompt;
int i;
#ifdef WIN32
#endif
ssl_log(s, SSL_LOG_INFO,
"Init: Requesting pass phrase via builtin terminal dialog");
/*
* Reconnect STDERR to terminal (here STDOUT) because
* at our init stage Apache already connected STDERR
* to the general error logfile.
*/
#ifdef WIN32
#else
#endif
#ifdef WIN32
else
#else
#endif
/*
* The first time display a header to inform the user about what
* program he actually speaks to, which module is responsible for
* this terminal dialog and why to the hell he has to enter
* something...
*/
if (*pnPassPhraseDialog == 1) {
}
if (*pbPassPhraseDialogOnce) {
}
/*
* Emulate the OpenSSL internal pass phrase dialog
*/
prompt = "Enter pass phrase:";
for (;;) {
return (-1);
}
if (len < 1)
else
break;
}
/*
* Restore STDERR to Apache error logfile
*/
#ifdef WIN32
#endif
}
/*
* Filter program
*/
char *result;
ssl_log(s, SSL_LOG_INFO,
"Init: Requesting pass phrase from dialog filter program (%s)",
cmd);
}
/*
* Ok, we now have the pass phrase, so give it back
*/
/*
* And return it's length to OpenSSL...
*/
return (len);
}