Debian Codegraph @

upstream/debian-unstable/man3/OSSL_trace_set_channel.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "OSSL_TRACE_SET_CHANNEL 3SSL"
58 .TH OSSL_TRACE_SET_CHANNEL 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 OSSL_trace_set_channel, OSSL_trace_set_prefix, OSSL_trace_set_suffix,
65 OSSL_trace_set_callback, OSSL_trace_cb \- Enabling trace output
66 .SH SYNOPSIS
67 .IX Header "SYNOPSIS"
68 .Vb 1
69 \& #include <openssl/trace.h>
70 \&
71 \& typedef size_t (*OSSL_trace_cb)(const char *buf, size_t cnt,
72 \& int category, int cmd, void *data);
73 \&
74 \& void OSSL_trace_set_channel(int category, BIO *bio);
75 \& void OSSL_trace_set_prefix(int category, const char *prefix);
76 \& void OSSL_trace_set_suffix(int category, const char *suffix);
77 \& void OSSL_trace_set_callback(int category, OSSL_trace_cb cb, void *data);
78 .Ve
79 .SH DESCRIPTION
80 .IX Header "DESCRIPTION"
81 If available (see "Configure Tracing" below), the application can request
82 internal trace output.
83 This output comes in form of free text for humans to read.
84 .PP
85 The trace output is divided into categories which can be
86 enabled individually.
87 Every category can be enabled individually by attaching a so-called
88 \&\fItrace channel\fR to it, which in the simplest case is just a BIO object
89 to which the application can write the tracing output for this category.
90 Alternatively, the application can provide a tracer callback in order to
91 get more finegrained trace information. This callback will be wrapped
92 internally by a dedicated BIO object.
93 .PP
94 For the tracing code, both trace channel types are indistinguishable.
95 These are called a \fIsimple trace channel\fR and a \fIcallback trace channel\fR,
96 respectively.
97 .PP
98 \&\fBOSSL_TRACE_ENABLED\fR\|(3) can be used to check whether tracing is currently
99 enabled for the given category.
100 Functions like \fBOSSL_TRACE1\fR\|(3) and macros like \fBOSSL_TRACE_BEGIN\fR\|(3)
101 can be used for producing free-text trace output.
102 .SS Functions
103 .IX Subsection "Functions"
104 \&\fBOSSL_trace_set_channel()\fR is used to enable the given trace \f(CW\*(C`category\*(C'\fR
105 by attaching the \fBBIO\fR \fIbio\fR object as (simple) trace channel.
106 On success the ownership of the BIO is transferred to the channel,
107 so the caller must not free it directly.
108 .PP
109 \&\fBOSSL_trace_set_prefix()\fR and \fBOSSL_trace_set_suffix()\fR can be used to add
110 an extra line for each channel, to be output before and after group of
111 tracing output.
112 What constitutes an output group is decided by the code that produces
113 the output.
114 The lines given here are considered immutable; for more dynamic
115 tracing prefixes, consider setting a callback with
116 \&\fBOSSL_trace_set_callback()\fR instead.
117 .PP
118 \&\fBOSSL_trace_set_callback()\fR is used to enable the given trace
119 \&\fIcategory\fR by giving it the tracer callback \fIcb\fR with the associated
120 data \fIdata\fR, which will simply be passed through to \fIcb\fR whenever
121 it's called. The callback function is internally wrapped by a
122 dedicated BIO object, the so-called \fIcallback trace channel\fR.
123 This should be used when it's desirable to do form the trace output to
124 something suitable for application needs where a prefix and suffix
125 line aren't enough.
126 .PP
127 \&\fBOSSL_trace_set_channel()\fR and \fBOSSL_trace_set_callback()\fR are mutually
128 exclusive, calling one of them will clear whatever was set by the
129 previous call.
130 .PP
131 Calling \fBOSSL_trace_set_channel()\fR with NULL for \fIchannel\fR or
132 \&\fBOSSL_trace_set_callback()\fR with NULL for \fIcb\fR disables tracing for
133 the given \fIcategory\fR.
134 .SS "Trace callback"
135 .IX Subsection "Trace callback"
136 The tracer callback must return a \fBsize_t\fR, which must be zero on
137 error and otherwise return the number of bytes that were output.
138 It receives a text buffer \fIbuf\fR with \fIcnt\fR bytes of text, as well as
139 the \fIcategory\fR, a control number \fIcmd\fR, and the \fIdata\fR that was
140 passed to \fBOSSL_trace_set_callback()\fR.
141 .PP
142 The possible control numbers are:
143 .IP \fBOSSL_TRACE_CTRL_BEGIN\fR 4
144 .IX Item "OSSL_TRACE_CTRL_BEGIN"
145 The callback is called from \fBOSSL_trace_begin()\fR, which gives the
146 callback the possibility to output a dynamic starting line, or set a
147 prefix that should be output at the beginning of each line, or
148 something other.
149 .IP \fBOSSL_TRACE_CTRL_WRITE\fR 4
150 .IX Item "OSSL_TRACE_CTRL_WRITE"
151 This callback is called whenever data is written to the BIO by some
152 regular BIO output routine.
153 An arbitrary number of \fBOSSL_TRACE_CTRL_WRITE\fR callbacks can occur
154 inside a group marked by a pair of \fBOSSL_TRACE_CTRL_BEGIN\fR and
155 \&\fBOSSL_TRACE_CTRL_END\fR calls, but never outside such a group.
156 .IP \fBOSSL_TRACE_CTRL_END\fR 4
157 .IX Item "OSSL_TRACE_CTRL_END"
158 The callback is called from \fBOSSL_trace_end()\fR, which gives the callback
159 the possibility to output a dynamic ending line, or reset the line
160 prefix that was set with \fBOSSL_TRACE_CTRL_BEGIN\fR, or something other.
161 .SS "Trace categories"
162 .IX Subsection "Trace categories"
163 The trace categories are simple numbers available through macros.
164 .IP \fBOSSL_TRACE_CATEGORY_TRACE\fR 4
165 .IX Item "OSSL_TRACE_CATEGORY_TRACE"
166 Traces the OpenSSL trace API itself.
167 .Sp
168 More precisely, this will generate trace output any time a new
169 trace hook is set.
170 .IP \fBOSSL_TRACE_CATEGORY_INIT\fR 4
171 .IX Item "OSSL_TRACE_CATEGORY_INIT"
172 Traces OpenSSL library initialization and cleanup.
173 .Sp
174 This needs special care, as OpenSSL will do automatic cleanup after
175 exit from \f(CWmain()\fR, and any tracing output done during this cleanup
176 will be lost if the tracing channel or callback were cleaned away
177 prematurely.
178 A suggestion is to make such cleanup part of a function that's
179 registered very early with \fBatexit\fR\|(3).
180 .IP \fBOSSL_TRACE_CATEGORY_TLS\fR 4
181 .IX Item "OSSL_TRACE_CATEGORY_TLS"
182 Traces the TLS/SSL protocol.
183 .IP \fBOSSL_TRACE_CATEGORY_TLS_CIPHER\fR 4
184 .IX Item "OSSL_TRACE_CATEGORY_TLS_CIPHER"
185 Traces the ciphers used by the TLS/SSL protocol.
186 .IP \fBOSSL_TRACE_CATEGORY_CONF\fR 4
187 .IX Item "OSSL_TRACE_CATEGORY_CONF"
188 Traces details about the provider and engine configuration.
189 .IP \fBOSSL_TRACE_CATEGORY_ENGINE_TABLE\fR 4
190 .IX Item "OSSL_TRACE_CATEGORY_ENGINE_TABLE"
191 Traces the ENGINE algorithm table selection.
192 .Sp
193 More precisely, functions like \fBENGINE_get_pkey_asn1_meth_engine()\fR,
194 \&\fBENGINE_get_pkey_meth_engine()\fR, \fBENGINE_get_cipher_engine()\fR,
195 \&\fBENGINE_get_digest_engine()\fR, will generate trace summaries of the
196 handling of internal tables.
197 .IP \fBOSSL_TRACE_CATEGORY_ENGINE_REF_COUNT\fR 4
198 .IX Item "OSSL_TRACE_CATEGORY_ENGINE_REF_COUNT"
199 Traces the ENGINE reference counting.
200 .Sp
201 More precisely, both reference counts in the ENGINE structure will be
202 monitored with a line of trace output generated for each change.
203 .IP \fBOSSL_TRACE_CATEGORY_PKCS5V2\fR 4
204 .IX Item "OSSL_TRACE_CATEGORY_PKCS5V2"
205 Traces PKCS#5 v2 key generation.
206 .IP \fBOSSL_TRACE_CATEGORY_PKCS12_KEYGEN\fR 4
207 .IX Item "OSSL_TRACE_CATEGORY_PKCS12_KEYGEN"
208 Traces PKCS#12 key generation.
209 .IP \fBOSSL_TRACE_CATEGORY_PKCS12_DECRYPT\fR 4
210 .IX Item "OSSL_TRACE_CATEGORY_PKCS12_DECRYPT"
211 Traces PKCS#12 decryption.
212 .IP \fBOSSL_TRACE_CATEGORY_X509V3_POLICY\fR 4
213 .IX Item "OSSL_TRACE_CATEGORY_X509V3_POLICY"
214 Traces X509v3 policy processing.
215 .Sp
216 More precisely, this generates the complete policy tree at various
217 point during evaluation.
218 .IP \fBOSSL_TRACE_CATEGORY_BN_CTX\fR 4
219 .IX Item "OSSL_TRACE_CATEGORY_BN_CTX"
220 Traces BIGNUM context operations.
221 .IP \fBOSSL_TRACE_CATEGORY_CMP\fR 4
222 .IX Item "OSSL_TRACE_CATEGORY_CMP"
223 Traces CMP client and server activity.
224 .IP \fBOSSL_TRACE_CATEGORY_STORE\fR 4
225 .IX Item "OSSL_TRACE_CATEGORY_STORE"
226 Traces STORE operations.
227 .IP \fBOSSL_TRACE_CATEGORY_DECODER\fR 4
228 .IX Item "OSSL_TRACE_CATEGORY_DECODER"
229 Traces decoder operations.
230 .IP \fBOSSL_TRACE_CATEGORY_ENCODER\fR 4
231 .IX Item "OSSL_TRACE_CATEGORY_ENCODER"
232 Traces encoder operations.
233 .IP \fBOSSL_TRACE_CATEGORY_REF_COUNT\fR 4
234 .IX Item "OSSL_TRACE_CATEGORY_REF_COUNT"
235 Traces decrementing certain ASN.1 structure references.
236 .IP \fBOSSL_TRACE_CATEGORY_HTTP\fR 4
237 .IX Item "OSSL_TRACE_CATEGORY_HTTP"
238 Traces the HTTP client, such as message headers being sent and received.
239 .PP
240 There is also \fBOSSL_TRACE_CATEGORY_ALL\fR, which works as a fallback
241 and can be used to get \fIall\fR trace output.
242 .PP
243 Note, however, that in this case all trace output will effectively be
244 associated with the 'ALL' category, which is undesirable if the
245 application intends to include the category name in the trace output.
246 In this case it is better to register separate channels for each
247 trace category instead.
248 .SH "RETURN VALUES"
249 .IX Header "RETURN VALUES"
250 \&\fBOSSL_trace_set_channel()\fR, \fBOSSL_trace_set_prefix()\fR,
251 \&\fBOSSL_trace_set_suffix()\fR, and \fBOSSL_trace_set_callback()\fR return 1 on
252 success, or 0 on failure.
253 .SH EXAMPLES
254 .IX Header "EXAMPLES"
255 In all examples below, the trace producing code is assumed to be
256 the following:
257 .PP
258 .Vb 3
259 \& int foo = 42;
260 \& const char bar[] = { 0, 1, 2, 3, 4, 5, 6, 7,
261 \& 8, 9, 10, 11, 12, 13, 14, 15 };
262 \&
263 \& OSSL_TRACE_BEGIN(TLS) {
264 \& BIO_puts(trc_out, "foo: ");
265 \& BIO_printf(trc_out, "%d\en", foo);
266 \& BIO_dump(trc_out, bar, sizeof(bar));
267 \& } OSSL_TRACE_END(TLS);
268 .Ve
269 .SS "Simple example"
270 .IX Subsection "Simple example"
271 An example with just a channel and constant prefix / suffix.
272 .PP
273 .Vb 6
274 \& int main(int argc, char *argv[])
275 \& {
276 \& BIO *err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
277 \& OSSL_trace_set_channel(OSSL_TRACE_CATEGORY_SSL, err);
278 \& OSSL_trace_set_prefix(OSSL_TRACE_CATEGORY_SSL, "BEGIN TRACE[TLS]");
279 \& OSSL_trace_set_suffix(OSSL_TRACE_CATEGORY_SSL, "END TRACE[TLS]");
280 \&
281 \& /* ... work ... */
282 \& }
283 .Ve
284 .PP
285 When the trace producing code above is performed, this will be output
286 on standard error:
287 .PP
288 .Vb 4
289 \& BEGIN TRACE[TLS]
290 \& foo: 42
291 \& 0000 \- 00 01 02 03 04 05 06 07\-08 09 0a 0b 0c 0d 0e 0f ................
292 \& END TRACE[TLS]
293 .Ve
294 .SS "Advanced example"
295 .IX Subsection "Advanced example"
296 This example uses the callback, and depends on pthreads functionality.
297 .PP
298 .Vb 5
299 \& static size_t cb(const char *buf, size_t cnt,
300 \& int category, int cmd, void *vdata)
301 \& {
302 \& BIO *bio = vdata;
303 \& const char *label = NULL;
304 \&
305 \& switch (cmd) {
306 \& case OSSL_TRACE_CTRL_BEGIN:
307 \& label = "BEGIN";
308 \& break;
309 \& case OSSL_TRACE_CTRL_END:
310 \& label = "END";
311 \& break;
312 \& }
313 \&
314 \& if (label != NULL) {
315 \& union {
316 \& pthread_t tid;
317 \& unsigned long ltid;
318 \& } tid;
319 \&
320 \& tid.tid = pthread_self();
321 \& BIO_printf(bio, "%s TRACE[%s]:%lx\en",
322 \& label, OSSL_trace_get_category_name(category), tid.ltid);
323 \& }
324 \& return (size_t)BIO_puts(bio, buf);
325 \& }
326 \&
327 \& int main(int argc, char *argv[])
328 \& {
329 \& BIO *err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
330 \& OSSL_trace_set_callback(OSSL_TRACE_CATEGORY_SSL, cb, err);
331 \&
332 \& /* ... work ... */
333 \& }
334 .Ve
335 .PP
336 The output is almost the same as for the simple example above.
337 .PP
338 .Vb 4
339 \& BEGIN TRACE[TLS]:7f9eb0193b80
340 \& foo: 42
341 \& 0000 \- 00 01 02 03 04 05 06 07\-08 09 0a 0b 0c 0d 0e 0f ................
342 \& END TRACE[TLS]:7f9eb0193b80
343 .Ve
344 .SH NOTES
345 .IX Header "NOTES"
346 .SS "Configure Tracing"
347 .IX Subsection "Configure Tracing"
348 By default, the OpenSSL library is built with tracing disabled. To
349 use the tracing functionality documented here, it is therefore
350 necessary to configure and build OpenSSL with the 'enable\-trace' option.
351 .PP
352 When the library is built with tracing disabled, the macro
353 \&\fBOPENSSL_NO_TRACE\fR is defined in \fI<openssl/opensslconf.h>\fR and all
354 functions described here are inoperational, i.e. will do nothing.
355 .SH "SEE ALSO"
356 .IX Header "SEE ALSO"
357 \&\fBOSSL_TRACE_ENABLED\fR\|(3), \fBOSSL_TRACE_BEGIN\fR\|(3), \fBOSSL_TRACE1\fR\|(3),
358 \&\fBatexit\fR\|(3)
359 .SH HISTORY
360 .IX Header "HISTORY"
361 \&\fBOSSL_trace_set_channel()\fR, \fBOSSL_trace_set_prefix()\fR,
362 \&\fBOSSL_trace_set_suffix()\fR, and \fBOSSL_trace_set_callback()\fR were all added
363 in OpenSSL 3.0.
364 .SH COPYRIGHT
365 .IX Header "COPYRIGHT"
366 Copyright 2019\-2023 The OpenSSL Project Authors. All Rights Reserved.
367 .PP
368 Licensed under the Apache License 2.0 (the "License"). You may not use
369 this file except in compliance with the License. You can obtain a copy
370 in the file LICENSE in the source distribution or at
371 <https://www.openssl.org/source/license.html>.