Apache HTTPD
ssl_engine_log.c
Go to the documentation of this file.
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17/* _ _
18 * _ __ ___ ___ __| | ___ ___| | mod_ssl
19 * | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
20 * | | | | | | (_) | (_| | \__ \__ \ |
21 * |_| |_| |_|\___/ \__,_|___|___/___/_|
22 * |_____|
23 * ssl_engine_log.c
24 * Logging Facility
25 */
26 /* ``The difference between a computer
27 industry job and open-source software
28 hacking is about 30 hours a week.''
29 -- Ralf S. Engelschall */
30#include "ssl_private.h"
31
32/* _________________________________________________________________
33**
34** Logfile Support
35** _________________________________________________________________
36*/
37
38static const struct {
39 const char *cpPattern;
40 const char *cpAnnotation;
41} ssl_log_annotate[] = {
42 { "*envelope*bad*decrypt*", "wrong pass phrase!?" },
43 { "*CLIENT_HELLO*unknown*protocol*", "speaking not SSL to HTTPS port!?" },
44 { "*CLIENT_HELLO*http*request*", "speaking HTTP to HTTPS port!?" },
45 { "*SSL3_READ_BYTES:sslv3*alert*bad*certificate*", "Subject CN in certificate not server name or identical to CA!?" },
46 { "*self signed certificate in certificate chain*", "Client certificate signed by CA not known to server?" },
47 { "*peer did not return a certificate*", "No CAs known to server for verification?" },
48 { "*no shared cipher*", "Too restrictive SSLCipherSuite or using DSA server certificate?" },
49 { "*no start line*", "Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?" },
50 { "*bad password read*", "You entered an incorrect pass phrase!?" },
51 { "*bad mac decode*", "Browser still remembered details of a re-created server certificate?" },
52 { NULL, NULL }
53};
54
55static const char *ssl_log_annotation(const char *error)
56{
57 int i = 0;
58
61 i++;
62
63 return ssl_log_annotate[i].cpAnnotation;
64}
65
67{
68 if (s != NULL && s->is_virtual && s->error_fname != NULL)
70 "Fatal error initialising mod_ssl, exiting. "
71 "See %s for more information",
72 ap_server_root_relative(s->process->pool,
73 s->error_fname));
74 else
76 "Fatal error initialising mod_ssl, exiting.");
77
78 return APR_EGENERAL;
79}
80
81static APR_INLINE
82unsigned long modssl_ERR_peek_error_data(const char **data, int *flags)
83{
84#if OPENSSL_VERSION_NUMBER < 0x30000000L
86#else
88#endif
89}
90
91/*
92 * Prints the SSL library error information.
93 */
94void ssl_log_ssl_error(const char *file, int line, int level, server_rec *s)
95{
96 unsigned long e;
97 const char *data;
98 int flags;
99
100 while ((e = modssl_ERR_peek_error_data(&data, &flags))) {
101 const char *annotation;
102 char err[256];
103
104 if (!(flags & ERR_TXT_STRING)) {
105 data = NULL;
106 }
107
108 ERR_error_string_n(e, err, sizeof err);
110
111 ap_log_error(file, line, APLOG_MODULE_INDEX, level, 0, s,
112 "SSL Library Error: %s%s%s%s%s%s",
113 /* %s */
114 err,
115 /* %s%s%s */
116 data ? " (" : "", data ? data : "", data ? ")" : "",
117 /* %s%s */
118 annotation ? " -- " : "",
119 annotation ? annotation : "");
120
121 /* Pop the error off the stack: */
123 }
124}
125
126static void ssl_log_cert_error(const char *file, int line, int level,
127 apr_status_t rv, const server_rec *s,
128 const conn_rec *c, const request_rec *r,
129 apr_pool_t *p, X509 *cert, const char *format,
130 va_list ap)
131{
132 char buf[HUGE_STRING_LEN];
133 int msglen, n;
134 char *name;
135
136 msglen = apr_vsnprintf(buf, sizeof buf, format, ap);
137
138 if (cert) {
139 BIO *bio = BIO_new(BIO_s_mem());
140
141 if (bio) {
142 /*
143 * Limit the maximum length of the subject and issuer DN strings
144 * in the log message. 300 characters should always be sufficient
145 * for holding both the timestamp, module name, pid etc. stuff
146 * at the beginning of the line and the trailing information about
147 * serial, notbefore and notafter.
148 */
149 int maxdnlen = (HUGE_STRING_LEN - msglen - 300) / 2;
150
151 BIO_puts(bio, " [subject: ");
153 maxdnlen);
154 if (!strIsEmpty(name)) {
155 BIO_puts(bio, name);
156 } else {
157 BIO_puts(bio, "-empty-");
158 }
159
160 BIO_puts(bio, " / issuer: ");
162 maxdnlen);
163 if (!strIsEmpty(name)) {
164 BIO_puts(bio, name);
165 } else {
166 BIO_puts(bio, "-empty-");
167 }
168
169 BIO_puts(bio, " / serial: ");
171 BIO_puts(bio, "(ERROR)");
172
173 BIO_puts(bio, " / notbefore: ");
175
176 BIO_puts(bio, " / notafter: ");
178
179 BIO_puts(bio, "]");
180
181 n = BIO_read(bio, buf + msglen, sizeof buf - msglen - 1);
182 if (n > 0)
183 buf[msglen + n] = '\0';
184
185 BIO_free(bio);
186 }
187 }
188 else {
189 apr_snprintf(buf + msglen, sizeof buf - msglen,
190 " [certificate: -not available-]");
191 }
192
193 if (r) {
194 ap_log_rerror(file, line, APLOG_MODULE_INDEX, level, rv, r, "%s", buf);
195 }
196 else if (c) {
197 ap_log_cerror(file, line, APLOG_MODULE_INDEX, level, rv, c, "%s", buf);
198 }
199 else if (s) {
200 ap_log_error(file, line, APLOG_MODULE_INDEX, level, rv, s, "%s", buf);
201 }
202
203}
204
205/*
206 * Wrappers for ap_log_error/ap_log_cerror/ap_log_rerror which log additional
207 * details of the X509 cert. For ssl_log_xerror, a pool needs to be passed in
208 * as well (for temporary allocation of the cert's subject/issuer name strings,
209 * in the other cases we use the connection and request pool, respectively).
210 */
211void ssl_log_xerror(const char *file, int line, int level, apr_status_t rv,
212 apr_pool_t *ptemp, server_rec *s, X509 *cert,
213 const char *fmt, ...)
214{
215 if (APLOG_IS_LEVEL(s,level)) {
216 va_list ap;
217 va_start(ap, fmt);
218 ssl_log_cert_error(file, line, level, rv, s, NULL, NULL, ptemp,
219 cert, fmt, ap);
220 va_end(ap);
221 }
222}
223
224void ssl_log_cxerror(const char *file, int line, int level, apr_status_t rv,
225 conn_rec *c, X509 *cert, const char *fmt, ...)
226{
227 if (APLOG_IS_LEVEL(mySrvFromConn(c),level)) {
228 va_list ap;
229 va_start(ap, fmt);
230 ssl_log_cert_error(file, line, level, rv, NULL, c, NULL, c->pool,
231 cert, fmt, ap);
232 va_end(ap);
233 }
234}
235
236void ssl_log_rxerror(const char *file, int line, int level, apr_status_t rv,
237 request_rec *r, X509 *cert, const char *fmt, ...)
238{
239 if (APLOG_R_IS_LEVEL(r,level)) {
240 va_list ap;
241 va_start(ap, fmt);
242 ssl_log_cert_error(file, line, level, rv, NULL, NULL, r, r->pool,
243 cert, fmt, ap);
244 va_end(ap);
245 }
246}
int n
Definition ap_regex.h:278
char * ap_server_root_relative(apr_pool_t *p, const char *fname)
Definition config.c:1594
request_rec * r
#define HUGE_STRING_LEN
Definition httpd.h:303
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_rerror
Definition http_log.h:454
#define ap_log_error
Definition http_log.h:370
#define ap_log_cerror
Definition http_log.h:498
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_IS_LEVEL(s, level)
Definition http_log.h:223
#define APLOG_R_IS_LEVEL(r, level)
Definition http_log.h:229
#define APLOG_EMERG
Definition http_log.h:64
#define APLOG_MODULE_INDEX
Definition http_log.h:168
const unsigned char * buf
Definition util_md5.h:50
#define APR_EGENERAL
Definition apr_errno.h:313
apr_bucket * e
apr_pool_t const char apr_dbd_t const char ** error
Definition apr_dbd.h:143
const char apr_ssize_t int flags
Definition apr_encode.h:168
apr_status_t ssl_die(server_rec *s)
#define mySrvFromConn(c)
#define X509_get_notAfter
void ssl_log_ssl_error(const char *file, int line, int level, server_rec *s)
#define X509_get_notBefore
char * modssl_X509_NAME_to_string(apr_pool_t *p, X509_NAME *dn, int maxlen)
int ap_strcmp_match(const char *str, const char *expected)
Definition util.c:175
apr_size_t size
int apr_status_t
Definition apr_errno.h:44
const char * format
void * data
const char apr_file_t * file
apr_vformatter_buff_t const char * fmt
Definition apr_lib.h:175
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_vformatter_buff_t const char va_list ap
Definition apr_lib.h:176
const char * s
Definition apr_strings.h:95
apr_int32_t apr_int32_t apr_int32_t err
apr_pool_t * p
Definition md_event.c:32
#define strIsEmpty(s)
Definition mod_nw_ssl.c:98
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
void ssl_log_rxerror(const char *file, int line, int level, apr_status_t rv, request_rec *r, X509 *cert, const char *fmt,...)
static const struct @39 ssl_log_annotate[]
static void ssl_log_cert_error(const char *file, int line, int level, apr_status_t rv, const server_rec *s, const conn_rec *c, const request_rec *r, apr_pool_t *p, X509 *cert, const char *format, va_list ap)
const char * cpAnnotation
void ssl_log_xerror(const char *file, int line, int level, apr_status_t rv, apr_pool_t *ptemp, server_rec *s, X509 *cert, const char *fmt,...)
static const char * ssl_log_annotation(const char *error)
void ssl_log_cxerror(const char *file, int line, int level, apr_status_t rv, conn_rec *c, X509 *cert, const char *fmt,...)
static APR_INLINE unsigned long modssl_ERR_peek_error_data(const char **data, int *flags)
const char * cpPattern
char * name
Internal interfaces private to mod_ssl.
Structure to store things which are per connection.
Definition httpd.h:1152
A structure that represents the current request.
Definition httpd.h:845
apr_pool_t * pool
Definition httpd.h:847
A structure to store information for each virtual server.
Definition httpd.h:1322