xref: /freebsd/crypto/openssl/doc/man3/OSSL_CMP_log_open.pod (revision aa7957345732816fb0ba8308798d2f79f45597f9)
1b077aed3SPierre Pronchery=pod
2b077aed3SPierre Pronchery
3b077aed3SPierre Pronchery=head1 NAME
4b077aed3SPierre Pronchery
5b077aed3SPierre ProncheryOSSL_CMP_log_open,
6b077aed3SPierre ProncheryOSSL_CMP_log_close,
7b077aed3SPierre ProncheryOSSL_CMP_severity,
8b077aed3SPierre ProncheryOSSL_CMP_LOG_EMERG,
9b077aed3SPierre ProncheryOSSL_CMP_LOG_ALERT,
10b077aed3SPierre ProncheryOSSL_CMP_LOG_CRIT,
11b077aed3SPierre ProncheryOSSL_CMP_LOG_ERR,
12b077aed3SPierre ProncheryOSSL_CMP_LOG_WARNING,
13b077aed3SPierre ProncheryOSSL_CMP_LOG_NOTICE,
14b077aed3SPierre ProncheryOSSL_CMP_LOG_INFO,
15b077aed3SPierre ProncheryOSSL_CMP_LOG_DEBUG,
16b077aed3SPierre ProncheryOSSL_CMP_LOG_TRACE,
17b077aed3SPierre Pronchery
18b077aed3SPierre ProncheryOSSL_CMP_log_cb_t,
19b077aed3SPierre ProncheryOSSL_CMP_print_to_bio,
20b077aed3SPierre ProncheryOSSL_CMP_print_errors_cb
21b077aed3SPierre Pronchery- functions for logging and error reporting
22b077aed3SPierre Pronchery
23b077aed3SPierre Pronchery=head1 SYNOPSIS
24b077aed3SPierre Pronchery
25b077aed3SPierre Pronchery #include <openssl/cmp_util.h>
26b077aed3SPierre Pronchery
27b077aed3SPierre Pronchery int  OSSL_CMP_log_open(void);
28b077aed3SPierre Pronchery void OSSL_CMP_log_close(void);
29b077aed3SPierre Pronchery
30b077aed3SPierre Pronchery /* severity level declarations resemble those from syslog.h */
31b077aed3SPierre Pronchery typedef int OSSL_CMP_severity;
32b077aed3SPierre Pronchery #define OSSL_CMP_LOG_EMERG   0
33b077aed3SPierre Pronchery #define OSSL_CMP_LOG_ALERT   1
34b077aed3SPierre Pronchery #define OSSL_CMP_LOG_CRIT    2
35b077aed3SPierre Pronchery #define OSSL_CMP_LOG_ERR     3
36b077aed3SPierre Pronchery #define OSSL_CMP_LOG_WARNING 4
37b077aed3SPierre Pronchery #define OSSL_CMP_LOG_NOTICE  5
38b077aed3SPierre Pronchery #define OSSL_CMP_LOG_INFO    6
39b077aed3SPierre Pronchery #define OSSL_CMP_LOG_DEBUG   7
40b077aed3SPierre Pronchery #define OSSL_CMP_LOG_TRACE   8
41b077aed3SPierre Pronchery
42b077aed3SPierre Pronchery typedef int (*OSSL_CMP_log_cb_t)(const char *component,
43b077aed3SPierre Pronchery                                  const char *file, int line,
44b077aed3SPierre Pronchery                                  OSSL_CMP_severity level, const char *msg);
45b077aed3SPierre Pronchery int OSSL_CMP_print_to_bio(BIO *bio, const char *component, const char *file,
46b077aed3SPierre Pronchery                           int line, OSSL_CMP_severity level, const char *msg);
47b077aed3SPierre Pronchery void OSSL_CMP_print_errors_cb(OSSL_CMP_log_cb_t log_fn);
48b077aed3SPierre Pronchery
49b077aed3SPierre Pronchery=head1 DESCRIPTION
50b077aed3SPierre Pronchery
51b077aed3SPierre ProncheryThe logging and error reporting facility described here contains
52b077aed3SPierre Proncheryconvenience functions for CMP-specific logging,
53b077aed3SPierre Proncheryincluding a string prefix mirroring the severity levels of syslog.h,
54b077aed3SPierre Proncheryand enhancements of the error queue mechanism needed for large diagnostic
55b077aed3SPierre Proncherymessages produced by the CMP library in case of certificate validation failures.
56b077aed3SPierre Pronchery
57b077aed3SPierre ProncheryWhen an interesting activity is performed or an error occurs, some detail
58b077aed3SPierre Proncheryshould be provided for user information, debugging, and auditing purposes.
59b077aed3SPierre ProncheryA CMP application can obtain this information by providing a callback function
60b077aed3SPierre Proncherywith the following type:
61b077aed3SPierre Pronchery
62b077aed3SPierre Pronchery typedef int (*OSSL_CMP_log_cb_t)(const char *component,
63b077aed3SPierre Pronchery                                  const char *file, int line,
64b077aed3SPierre Pronchery                                  OSSL_CMP_severity level, const char *msg);
65b077aed3SPierre Pronchery
66b077aed3SPierre ProncheryThe parameters may provide
67b077aed3SPierre Proncherysome component info (which may be a module name and/or function name) or NULL,
68b077aed3SPierre Proncherya file pathname or NULL,
69b077aed3SPierre Proncherya line number or 0 indicating the source code location,
70b077aed3SPierre Proncherya severity level, and
71b077aed3SPierre Proncherya message string describing the nature of the event, terminated by '\n'.
72b077aed3SPierre Pronchery
73b077aed3SPierre ProncheryEven when an activity is successful some warnings may be useful and some degree
74b077aed3SPierre Proncheryof auditing may be required. Therefore, the logging facility supports a severity
75b077aed3SPierre Proncherylevel and the callback function has a I<level> parameter indicating such a
76b077aed3SPierre Proncherylevel, such that error, warning, info, debug, etc. can be treated differently.
77b077aed3SPierre ProncheryThe callback is activated only when the severity level is sufficient according
78b077aed3SPierre Proncheryto the current level of verbosity, which by default is B<OSSL_CMP_LOG_INFO>.
79b077aed3SPierre Pronchery
80b077aed3SPierre ProncheryThe callback function may itself do non-trivial tasks like writing to
81b077aed3SPierre Proncherya log file or remote stream, which in turn may fail.
82b077aed3SPierre ProncheryTherefore, the function should return 1 on success and 0 on failure.
83b077aed3SPierre Pronchery
84b077aed3SPierre ProncheryOSSL_CMP_log_open() initializes the CMP-specific logging facility to output
85b077aed3SPierre Proncheryeverything to STDOUT. It fails if the integrated tracing is disabled or STDIO
86b077aed3SPierre Proncheryis not available. It may be called during application startup.
87b077aed3SPierre ProncheryAlternatively, L<OSSL_CMP_CTX_set_log_cb(3)> can be used for more flexibility.
88b077aed3SPierre ProncheryAs long as neither if the two is used any logging output is ignored.
89b077aed3SPierre Pronchery
90b077aed3SPierre ProncheryOSSL_CMP_log_close() may be called when all activities are finished to flush
91b077aed3SPierre Proncheryany pending CMP-specific log output and deallocate related resources.
92*aa795734SPierre ProncheryIt may be called multiple times. It does get called at OpenSSL shutdown.
93b077aed3SPierre Pronchery
94b077aed3SPierre ProncheryOSSL_CMP_print_to_bio() prints the given component info, filename, line number,
95b077aed3SPierre Proncheryseverity level, and log message or error queue message to the given I<bio>.
96b077aed3SPierre ProncheryI<component> usually is a function or module name.
97b077aed3SPierre ProncheryIf it is NULL, empty, or "(unknown function)" then "CMP" is used as fallback.
98b077aed3SPierre Pronchery
99b077aed3SPierre ProncheryOSSL_CMP_print_errors_cb() outputs any entries in the OpenSSL error queue.
100b077aed3SPierre ProncheryIt is similar to L<ERR_print_errors_cb(3)> but uses the CMP log callback
101b077aed3SPierre Proncheryfunction I<log_fn> for uniformity with CMP logging if not NULL. Otherwise it
102b077aed3SPierre Proncheryprints to STDERR using L<OSSL_CMP_print_to_bio(3)> (unless B<OPENSSL_NO_STDIO>
103b077aed3SPierre Proncheryis defined).
104b077aed3SPierre Pronchery
105b077aed3SPierre Pronchery=head1 RETURN VALUES
106b077aed3SPierre Pronchery
107b077aed3SPierre ProncheryOSSL_CMP_log_close() and OSSL_CMP_print_errors_cb() do not return anything.
108b077aed3SPierre Pronchery
109b077aed3SPierre ProncheryAll other functions return 1 on success, 0 on error.
110b077aed3SPierre Pronchery
111b077aed3SPierre Pronchery=head1 HISTORY
112b077aed3SPierre Pronchery
113b077aed3SPierre ProncheryThe OpenSSL CMP support was added in OpenSSL 3.0.
114b077aed3SPierre Pronchery
115b077aed3SPierre Pronchery=head1 COPYRIGHT
116b077aed3SPierre Pronchery
117*aa795734SPierre ProncheryCopyright 2007-2023 The OpenSSL Project Authors. All Rights Reserved.
118b077aed3SPierre Pronchery
119b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
120b077aed3SPierre Proncherythis file except in compliance with the License.  You can obtain a copy
121b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at
122b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
123b077aed3SPierre Pronchery
124b077aed3SPierre Pronchery=cut
125