|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* _ _
|
|
Packit |
90a5c9 |
* _ __ ___ ___ __| | ___ ___| | mod_ssl
|
|
Packit |
90a5c9 |
* | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
|
|
Packit |
90a5c9 |
* | | | | | | (_) | (_| | \__ \__ \ |
|
|
Packit |
90a5c9 |
* |_| |_| |_|\___/ \__,_|___|___/___/_|
|
|
Packit |
90a5c9 |
* |_____|
|
|
Packit |
90a5c9 |
* ssl_engine_log.c
|
|
Packit |
90a5c9 |
* Logging Facility
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
/* ``The difference between a computer
|
|
Packit |
90a5c9 |
industry job and open-source software
|
|
Packit |
90a5c9 |
hacking is about 30 hours a week.''
|
|
Packit |
90a5c9 |
-- Ralf S. Engelschall */
|
|
Packit |
90a5c9 |
#include "ssl_private.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* _________________________________________________________________
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
** Logfile Support
|
|
Packit |
90a5c9 |
** _________________________________________________________________
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const struct {
|
|
Packit |
90a5c9 |
const char *cpPattern;
|
|
Packit |
90a5c9 |
const char *cpAnnotation;
|
|
Packit |
90a5c9 |
} ssl_log_annotate[] = {
|
|
Packit |
90a5c9 |
{ "*envelope*bad*decrypt*", "wrong pass phrase!?" },
|
|
Packit |
90a5c9 |
{ "*CLIENT_HELLO*unknown*protocol*", "speaking not SSL to HTTPS port!?" },
|
|
Packit |
90a5c9 |
{ "*CLIENT_HELLO*http*request*", "speaking HTTP to HTTPS port!?" },
|
|
Packit |
90a5c9 |
{ "*SSL3_READ_BYTES:sslv3*alert*bad*certificate*", "Subject CN in certificate not server name or identical to CA!?" },
|
|
Packit |
90a5c9 |
{ "*self signed certificate in certificate chain*", "Client certificate signed by CA not known to server?" },
|
|
Packit |
90a5c9 |
{ "*peer did not return a certificate*", "No CAs known to server for verification?" },
|
|
Packit |
90a5c9 |
{ "*no shared cipher*", "Too restrictive SSLCipherSuite or using DSA server certificate?" },
|
|
Packit |
90a5c9 |
{ "*no start line*", "Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?" },
|
|
Packit |
90a5c9 |
{ "*bad password read*", "You entered an incorrect pass phrase!?" },
|
|
Packit |
90a5c9 |
{ "*bad mac decode*", "Browser still remembered details of a re-created server certificate?" },
|
|
Packit |
90a5c9 |
{ NULL, NULL }
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *ssl_log_annotation(const char *error)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (ssl_log_annotate[i].cpPattern != NULL
|
|
Packit |
90a5c9 |
&& ap_strcmp_match(error, ssl_log_annotate[i].cpPattern) != 0)
|
|
Packit |
90a5c9 |
i++;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return ssl_log_annotate[i].cpAnnotation;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t ssl_die(server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (s != NULL && s->is_virtual && s->error_fname != NULL)
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL, APLOGNO(02311)
|
|
Packit |
90a5c9 |
"Fatal error initialising mod_ssl, exiting. "
|
|
Packit |
90a5c9 |
"See %s for more information",
|
|
Packit |
90a5c9 |
ap_server_root_relative(s->process->pool,
|
|
Packit |
90a5c9 |
s->error_fname));
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, NULL, APLOGNO(02312)
|
|
Packit |
90a5c9 |
"Fatal error initialising mod_ssl, exiting.");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Prints the SSL library error information.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
void ssl_log_ssl_error(const char *file, int line, int level, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
unsigned long e;
|
|
Packit |
90a5c9 |
const char *data;
|
|
Packit |
90a5c9 |
int flags;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((e = ERR_peek_error_line_data(NULL, NULL, &data, &flags))) {
|
|
Packit |
90a5c9 |
const char *annotation;
|
|
Packit |
90a5c9 |
char err[256];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(flags & ERR_TXT_STRING)) {
|
|
Packit |
90a5c9 |
data = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ERR_error_string_n(e, err, sizeof err);
|
|
Packit |
90a5c9 |
annotation = ssl_log_annotation(err);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(file, line, APLOG_MODULE_INDEX, level, 0, s,
|
|
Packit |
90a5c9 |
"SSL Library Error: %s%s%s%s%s%s",
|
|
Packit |
90a5c9 |
/* %s */
|
|
Packit |
90a5c9 |
err,
|
|
Packit |
90a5c9 |
/* %s%s%s */
|
|
Packit |
90a5c9 |
data ? " (" : "", data ? data : "", data ? ")" : "",
|
|
Packit |
90a5c9 |
/* %s%s */
|
|
Packit |
90a5c9 |
annotation ? " -- " : "",
|
|
Packit |
90a5c9 |
annotation ? annotation : "");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Pop the error off the stack: */
|
|
Packit |
90a5c9 |
ERR_get_error();
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_log_cert_error(const char *file, int line, int level,
|
|
Packit |
90a5c9 |
apr_status_t rv, const server_rec *s,
|
|
Packit |
90a5c9 |
const conn_rec *c, const request_rec *r,
|
|
Packit |
90a5c9 |
apr_pool_t *p, X509 *cert, const char *format,
|
|
Packit |
90a5c9 |
va_list ap)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char buf[HUGE_STRING_LEN];
|
|
Packit |
90a5c9 |
int msglen, n;
|
|
Packit |
90a5c9 |
char *name;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_vsnprintf(buf, sizeof buf, format, ap);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
msglen = strlen(buf);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (cert) {
|
|
Packit |
90a5c9 |
BIO *bio = BIO_new(BIO_s_mem());
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (bio) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Limit the maximum length of the subject and issuer DN strings
|
|
Packit |
90a5c9 |
* in the log message. 300 characters should always be sufficient
|
|
Packit |
90a5c9 |
* for holding both the timestamp, module name, pid etc. stuff
|
|
Packit |
90a5c9 |
* at the beginning of the line and the trailing information about
|
|
Packit |
90a5c9 |
* serial, notbefore and notafter.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
int maxdnlen = (HUGE_STRING_LEN - msglen - 300) / 2;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_puts(bio, " [subject: ");
|
|
Packit |
90a5c9 |
name = modssl_X509_NAME_to_string(p, X509_get_subject_name(cert),
|
|
Packit |
90a5c9 |
maxdnlen);
|
|
Packit |
90a5c9 |
if (!strIsEmpty(name)) {
|
|
Packit |
90a5c9 |
BIO_puts(bio, name);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
BIO_puts(bio, "-empty-");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_puts(bio, " / issuer: ");
|
|
Packit |
90a5c9 |
name = modssl_X509_NAME_to_string(p, X509_get_issuer_name(cert),
|
|
Packit |
90a5c9 |
maxdnlen);
|
|
Packit |
90a5c9 |
if (!strIsEmpty(name)) {
|
|
Packit |
90a5c9 |
BIO_puts(bio, name);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
BIO_puts(bio, "-empty-");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_puts(bio, " / serial: ");
|
|
Packit |
90a5c9 |
if (i2a_ASN1_INTEGER(bio, X509_get_serialNumber(cert)) == -1)
|
|
Packit |
90a5c9 |
BIO_puts(bio, "(ERROR)");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_puts(bio, " / notbefore: ");
|
|
Packit |
90a5c9 |
ASN1_TIME_print(bio, X509_get_notBefore(cert));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_puts(bio, " / notafter: ");
|
|
Packit |
90a5c9 |
ASN1_TIME_print(bio, X509_get_notAfter(cert));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_puts(bio, "]");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
n = BIO_read(bio, buf + msglen, sizeof buf - msglen - 1);
|
|
Packit |
90a5c9 |
if (n > 0)
|
|
Packit |
90a5c9 |
buf[msglen + n] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_free(bio);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
apr_snprintf(buf + msglen, sizeof buf - msglen,
|
|
Packit |
90a5c9 |
" [certificate: -not available-]");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (r) {
|
|
Packit |
90a5c9 |
ap_log_rerror(file, line, APLOG_MODULE_INDEX, level, rv, r, "%s", buf);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (c) {
|
|
Packit |
90a5c9 |
ap_log_cerror(file, line, APLOG_MODULE_INDEX, level, rv, c, "%s", buf);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (s) {
|
|
Packit |
90a5c9 |
ap_log_error(file, line, APLOG_MODULE_INDEX, level, rv, s, "%s", buf);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Wrappers for ap_log_error/ap_log_cerror/ap_log_rerror which log additional
|
|
Packit |
90a5c9 |
* details of the X509 cert. For ssl_log_xerror, a pool needs to be passed in
|
|
Packit |
90a5c9 |
* as well (for temporary allocation of the cert's subject/issuer name strings,
|
|
Packit |
90a5c9 |
* in the other cases we use the connection and request pool, respectively).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
void ssl_log_xerror(const char *file, int line, int level, apr_status_t rv,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp, server_rec *s, X509 *cert,
|
|
Packit |
90a5c9 |
const char *fmt, ...)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (APLOG_IS_LEVEL(s,level)) {
|
|
Packit |
90a5c9 |
va_list ap;
|
|
Packit |
90a5c9 |
va_start(ap, fmt);
|
|
Packit |
90a5c9 |
ssl_log_cert_error(file, line, level, rv, s, NULL, NULL, ptemp,
|
|
Packit |
90a5c9 |
cert, fmt, ap);
|
|
Packit |
90a5c9 |
va_end(ap);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void ssl_log_cxerror(const char *file, int line, int level, apr_status_t rv,
|
|
Packit |
90a5c9 |
conn_rec *c, X509 *cert, const char *fmt, ...)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (APLOG_IS_LEVEL(mySrvFromConn(c),level)) {
|
|
Packit |
90a5c9 |
va_list ap;
|
|
Packit |
90a5c9 |
va_start(ap, fmt);
|
|
Packit |
90a5c9 |
ssl_log_cert_error(file, line, level, rv, NULL, c, NULL, c->pool,
|
|
Packit |
90a5c9 |
cert, fmt, ap);
|
|
Packit |
90a5c9 |
va_end(ap);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void ssl_log_rxerror(const char *file, int line, int level, apr_status_t rv,
|
|
Packit |
90a5c9 |
request_rec *r, X509 *cert, const char *fmt, ...)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (APLOG_R_IS_LEVEL(r,level)) {
|
|
Packit |
90a5c9 |
va_list ap;
|
|
Packit |
90a5c9 |
va_start(ap, fmt);
|
|
Packit |
90a5c9 |
ssl_log_cert_error(file, line, level, rv, NULL, NULL, r, r->pool,
|
|
Packit |
90a5c9 |
cert, fmt, ap);
|
|
Packit |
90a5c9 |
va_end(ap);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|