ssl_engine_log.c revision 35b9e4d5f3452cad4b3bec6829ce87a5ce9e9227
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** _ __ ___ ___ __| | ___ ___| | mod_ssl
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** Logging Facility
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton/* ====================================================================
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * The Apache Software License, Version 1.1
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * reserved.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Redistribution and use in source and binary forms, with or without
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * modification, are permitted provided that the following conditions
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 1. Redistributions of source code must retain the above copyright
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * notice, this list of conditions and the following disclaimer.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 2. Redistributions in binary form must reproduce the above copyright
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * notice, this list of conditions and the following disclaimer in
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * the documentation and/or other materials provided with the
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * distribution.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 3. The end-user documentation included with the redistribution,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * if any, must include the following acknowledgment:
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * "This product includes software developed by the
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Apache Software Foundation (http://www.apache.org/)."
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Alternately, this acknowledgment may appear in the software itself,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * if and wherever such third-party acknowledgments normally appear.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 4. The names "Apache" and "Apache Software Foundation" must
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * not be used to endorse or promote products derived from this
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * software without prior written permission. For written
12b2973ae4fdb19829e3ccd9d5d3938451c67f41jorton * permission, please contact apache@apache.org.
91ef999a69527d2a64983681c92aaef9270697b4rpluem * 5. Products derived from this software may not be called "Apache",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * nor may "Apache" appear in their name, without prior written
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * permission of the Apache Software Foundation.
338eb440128c076c0418429cbc4845148d52a09ejorton * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * SUCH DAMAGE.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * ====================================================================
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim /* ``The difference between a computer
0de29985d3f84de428d0744b9dafb8a6b086d034jorton industry job and open-source software
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton hacking is about 30 hours a week.''
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton -- Ralf S. Engelschall */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton/* _________________________________________________________________
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** Logfile Support
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** _________________________________________________________________
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * Open the SSL logfile
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonvoid ssl_log_open(server_rec *s_main, server_rec *s, apr_pool_t *p)
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim const char *szLogFile;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Short-circuit for inherited logfiles in order to save
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * filedescriptors in mass-vhost situation. Be careful, this works
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * fine because the close happens implicitly by the pool facility.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ((s != s_main) &&
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ((pl = ap_open_piped_log(p, szLogFile)) == NULL) {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim "Cannot open reliable pipe to SSL logfile filter %s", szLogFile);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton szLogFile = ap_server_root_relative(p, sc->log_file_name);
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonstatic struct {
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonstatic struct {
185aa71728867671e105178b4c66fbc22b65ae26sf { "*CLIENT_HELLO*unknown*protocol*", "speaking not SSL to HTTPS port!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*CLIENT_HELLO*http*request*", "speaking HTTP to HTTPS port!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*SSL3_READ_BYTES:sslv3*alert*bad*certificate*", "Subject CN in certificate not server name or identical to CA!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*self signed certificate in certificate chain*", "Client certificate signed by CA not known to server?" },
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim { "*peer did not return a certificate*", "No CAs known to server for verification?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*no shared cipher*", "Too restrictive SSLCipherSuite or using DSA server certificate?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*no start line*", "Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?" },
185aa71728867671e105178b4c66fbc22b65ae26sf { "*bad password read*", "You entered an incorrect pass phrase!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*bad mac decode*", "Browser still remembered details of a re-created server certificate?" },
3efea4a958cbb2e193a2f34ba5afdfe216a34324jorton for (i = 0; ssl_log_annotate[i].cpPattern != NULL; i++) {
185aa71728867671e105178b4c66fbc22b65ae26sf if (ap_strcmp_match(error, ssl_log_annotate[i].cpPattern) == 0) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonvoid ssl_log(server_rec *s, int level, const char *msg, ...)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton unsigned long e;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* initialization */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* strip out additional flags */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* reduce flags when not reasonable in context */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* we log only levels below, except for errors */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* determine the time entry string */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_strftime(tstr, &len, 80, "[%d/%b/%Y %H:%M:%S", &t);
ad412abff68c20db6deb528298c772b9ac4a0706jorton apr_snprintf(tstr + strlen(tstr), 80 - strlen(tstr), " %05d] ",
185aa71728867671e105178b4c66fbc22b65ae26sf (unsigned int)getpid());
ad412abff68c20db6deb528298c772b9ac4a0706jorton /* determine whether newline should be written */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* determine level name */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton for (i = 0; ssl_log_level2string[i].nLevel != 0; i++) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_snprintf(lstr, sizeof(lstr), "[%s]", ssl_log_level2string[i].szLevel);
1de839c61281d58dc75715c1ae06b4b00764c4efjorton /* create custom message */
1de839c61281d58dc75715c1ae06b4b00764c4efjorton /* write out SSLog message */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton astr = " (System and " SSL_LIBRARY_NAME " library errors follow)";
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton astr = " (" SSL_LIBRARY_NAME " library error follows)";
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* write out additional attachment messages */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (level <= sc->log_level && sc->log_file != NULL) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_snprintf(str, sizeof(str), "%s%sSystem: %s (errno: %d)%s",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton "System: %s (errno: %d)",
0de29985d3f84de428d0744b9dafb8a6b086d034jorton while ((e = ERR_get_error())) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* make sure the next log starts from a clean base */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* ERR_clear_error(); */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* cleanup and return */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * This is used for fatal errors and here
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * it is common module practice to really
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * exit from the complete program.