The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17#ifdef WITH_TLS
18/**
19 * $Id: 1680548019c7764ea326fd790380edee60dcafdf $
20 *
21 * @file lib/tls/log.h
22 * @brief Prototypes for TLS logging functions
23 *
24 * @copyright 2017 The FreeRADIUS project
25 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
26 */
27RCSIDH(tls_log_h, "$Id: 1680548019c7764ea326fd790380edee60dcafdf $")
28
29#include "openssl_user_macros.h"
30
31
32#include <freeradius-devel/server/request.h>
33#include <openssl/bio.h>
34
35#include <freeradius-devel/tls/base.h>
36
37/** Write out a certificate chain to the request or global log
38 *
39 * @param[in] _request The current request or NULL if you want to write to the global log.
40 * @param[in] _log_type Type of log message to create.
41 * @param[in] _chain A stack of X509 certificates representing the chain.
42 * @param[in] _leaf The leaf certificate. May be NULL.
43 */
44#define fr_tls_chain_log(_request, _log_type, _chain, _leaf) \
45 _fr_tls_chain_log( __FILE__, __LINE__, _request, _log_type, _chain, _leaf)
46void _fr_tls_chain_log(char const *file, int line,
47 request_t *request, fr_log_type_t log_type, STACK_OF(X509) *chain, X509 *leaf);
48
49/** Write out a certificate chain with a marker to the request or global log
50 *
51 * @param[in] _request The current request or NULL if you want to write to the global log.
52 * @param[in] _log_type Type of log message to create.
53 * @param[in] _chain A stack of X509 certificates representing the chain.
54 * @param[in] _leaf The leaf certificate. May be NULL.
55 * @param[in] _marker Emit a marker for this certificate.
56 */
57#define fr_tls_chain_marker_log(_request, _log_type, _chain, _leaf, _marker) \
58 _fr_tls_chain_marker_log( __FILE__, __LINE__, _request, _log_type, _chain, _leaf, _marker)
59void _fr_tls_chain_marker_log(char const *file, int line,
60 request_t *request, fr_log_type_t log_type, STACK_OF(X509) *chain, X509 *leaf,
61 X509 *marker);
62
63/** Write out a collection of X509 objects to the request or global log
64 *
65 * @param[in] _request The current request or NULL if you want to write to the global log.
66 * @param[in] _log_type Type of log message to create.
67 * @param[in] _objects to print to the log
68 */
69#define fr_tls_x509_objects_log(_request, _log_type, _objects) \
70 _fr_tls_x509_objects_log( __FILE__, __LINE__, _request, _log_type, _objects)
71void _fr_tls_x509_objects_log(char const *file, int line,
73 STACK_OF(X509_OBJECT) *objects);
74
75int fr_tls_log_io_error(request_t *request, int err, char const *msg, ...)
76 CC_HINT(format (printf, 3, 4));
77
78/** Print the OpenSSL error stack, under a message of our own
79 *
80 * For a failure which an OpenSSL call reported. The stack holds why, and
81 * this drains it, so use it whenever an OpenSSL call has just returned an
82 * error. Draining also keeps a stale entry from surfacing under some later,
83 * unrelated message.
84 *
85 * Use fr_tls_log_error() instead for a failure the server found for itself,
86 * where the stack holds nothing to drain.
87 */
88int fr_tls_log_perror(request_t *request, char const *msg, ...) CC_HINT(format (printf, 2, 3));
89
90/** Print the OpenSSL error stack, for a call unrelated to any TLS connection
91 *
92 * The same as fr_tls_log_perror(), without the `(TLS) ` prefix. Use it
93 * wherever OpenSSL is called for something which is not a TLS connection:
94 * signing a value, hashing a password, reading a key from disk. Calling
95 * those TLS would send a reader looking for a connection which is not there.
96 *
97 * RPERROR_SSL() is how a module reaches this.
98 */
99int fr_openssl_log_perror(request_t *request, char const *msg, ...) CC_HINT(format (printf, 2, 3));
100
101/** Print the OpenSSL error stack for the current request
102 *
103 * For a module which called an OpenSSL function unrelated to any TLS
104 * connection. Takes `request` from the enclosing scope, as every R* macro
105 * does, and a NULL `request` logs globally.
106 *
107 * @param[in] _fmt printf style format string.
108 * @param[in] ... printf arguments.
109 */
110#define RPERROR_SSL(_fmt, ...) fr_openssl_log_perror(request, _fmt, ## __VA_ARGS__)
111
112/** Log an error which the server found for itself
113 *
114 * For a check the server made, rather than something an OpenSSL call
115 * reported: a configuration which cannot work, a policy section which could
116 * not be pushed, a peer which offered the wrong thing. The OpenSSL error
117 * stack holds nothing for these, so there is nothing to drain, and
118 * fr_tls_log_perror() would print an empty line where the reason should be.
119 *
120 * Every message carries a `(TLS) ` prefix. LOG_PREFIX supplies `tls - ` only
121 * when there is no request, so without this prefix the messages which matter
122 * most, the ones attached to a request, are the ones with nothing to say
123 * where they came from.
124 *
125 * The request branch is REDEBUG and not RERROR on purpose. RERROR logs at
126 * L_DBG_LVL_OFF, which would put every TLS connection failure into
127 * radiusd.log. An administrator decides which failures are worth recording,
128 * by writing a `fail session { ... }` policy, so the library says what
129 * happened at debug level and leaves the decision alone.
130 *
131 * Needs a `request` in scope, as every R* macro does. A NULL `request` logs
132 * globally, which is why this macro still exists: nearly every caller has a
133 * request and uses REDEBUG directly, and what is left is the handful of
134 * places where the request may genuinely be absent.
135 *
136 * @param[in] _fmt printf style format string.
137 * @param[in] ... printf arguments.
138 */
139#define fr_tls_log_error(_fmt, ...) ROPTIONAL(REDEBUG, ERROR, "(TLS) " _fmt, ## __VA_ARGS__)
140
141void fr_tls_log_clear(void);
142
143/** Return a BIO that writes to the log of the specified request
144 *
145 * @note BIO should be considered invalid if the request yields
146 *
147 * @param[in] _request to associate with the logging BIO.
148 * @param[in] _type of log messages.
149 * @param[in] _lvl to print log messages at.
150 * @return A BIO.
151 */
152#define fr_tls_request_log_bio(_request, _type, _lvl) \
153 _fr_tls_request_log_bio(__FILE__, __LINE__, _request, _type, _lvl)
154BIO *_fr_tls_request_log_bio(char const *file, int line, request_t *request,
155 fr_log_type_t type, fr_log_lvl_t lvl) CC_HINT(nonnull);
156
157/** Return a BIO that writes to the global log
158 *
159 * @note BIO should be considered invalid if the request yields
160 *
161 * @param[in] _type of log messages.
162 * @param[in] _lvl to print log messages at.
163 * @return A BIO.
164 */
165#define fr_tls_global_log_bio(_type, _lvl) \
166 _fr_tls_global_log_bio(__FILE__, __LINE__, _type, _lvl)
167BIO *_fr_tls_global_log_bio(char const *file, int line, fr_log_type_t type, fr_log_lvl_t lvl);
168
169int fr_tls_log_init(void); /* Called from fr_openssl_init() */
170
171void fr_tls_log_free(void); /* Called from fr_openssl_init() */
172#endif
log_entry msg
Definition acutest.h:947
void int line
Definition acutest.h:810
static uint8_t request[4]
#define RCSIDH(h, id)
Definition build.h:604
fr_log_lvl_t
Definition log.h:64
fr_log_type_t
Definition log.h:51
fr_aka_sim_id_type_t type
int nonnull(2, 5))