OSSL_TRACE_SET_CHANNEL(3ossl)
β¨ OSSL_TRACE_SET_CHANNEL β¨
the 3ossl manual page, but make it a group chat
πΈ NAME πΈ
OSSL_trace_set_channel, OSSL_trace_set_prefix, OSSL_trace_set_suffix, OSSL_trace_set_callback, OSSL_trace_cb β enabling trace output π
π SYNOPSIS π
#include <openssl/trace.h>
typedef size_t (*OSSL_trace_cb)(const char *buf, size_t cnt,
int category, int cmd, void *data);
void OSSL_trace_set_channel(int category, BIO *bio);
void OSSL_trace_set_prefix(int category, const char *prefix);
void OSSL_trace_set_suffix(int category, const char *suffix);
void OSSL_trace_set_callback(int category, OSSL_trace_cb cb, void *data);
π¦ DESCRIPTION π¦
Okay bestie, so β if it's available (peep "Configure Tracing" down below π), your app can ask for internal trace output. And what does that output look like? Free text. For humans. To read. It's giving "diary entry but for your library." π
The trace output is split into categories, and every single category can be switched on all by itself. How? By attaching a so-called trace channel to it. In the simplest case that's literally just a BIO object you write the tracing output for that category into. OR β if you're feeling fancy β you can hand over a tracer callback instead, which gets you way more finegrained trace info. Internally, that callback gets wrapped up in its own dedicated BIO object. Cute, right? π
Here's the thing though: to the tracing code itself, both channel types look exactly the same. They don't clock the difference. So we call them a simple trace channel and a callback trace channel, respectively. Periodt.
OSSL_TRACE_ENABLED(3) is your vibe-check function β use it to see whether tracing is currently enabled for a given category. And when you actually wanna produce that free-text trace output, functions like OSSL_TRACE1(3) and macros like OSSL_TRACE_BEGIN(3) are right there for you. π«Ά
π Functions π
OSSL_trace_set_channel()β turns on the given trace category by attaching theBIObioobject as a (simple) trace channel. On success, ownership of theBIOis transferred to the channel, so likeβ¦ the caller must NOT free it directly. Hands off, bestie. πOSSL_trace_set_prefix()andOSSL_trace_set_suffix()β these let you add an extra line per channel, output before and after a group of tracing output. What counts as an "output group"? That's up to whatever code produces the output, not you. And the lines you set here are considered immutable β locked in. If you want more dynamic tracing prefixes, set a callback withOSSL_trace_set_callback()instead. β¨OSSL_trace_set_callback()β turns on the given trace category by giving it the tracer callbackcbplus the associated datadata, anddatajust gets passed straight through tocbevery time it's called. The callback function is internally wrapped by a dedicatedBIOobject β the so-called callback trace channel. Reach for this when you wanna do form the trace output to something suitable for application needs where a prefix and suffix line just aren't enough. π
π¨OSSL_trace_set_channel()andOSSL_trace_set_callback()are mutually exclusive β calling one of them will clear whatever was set by the previous call. They do NOT coexist. It's one or the other, no cap.
Also! Calling OSSL_trace_set_channel() with NULL for channel, or OSSL_trace_set_callback() with NULL for cb, disables tracing for the given category. Off switch, unlocked. π₯
π Trace callback π
Your tracer callback has to return a size_t. It must be zero on error, and otherwise it returns the number of bytes that were output. Simple as that.
It receives:
- a text buffer
bufwithcntbytes of text, - the
category, - a control number
cmd, - and the
datathat was passed toOSSL_trace_set_callback().
The possible control numbers are:
OSSL_TRACE_CTRL_BEGINβ the callback gets called fromOSSL_trace_begin(). This hands your callback the opportunity to output a dynamic starting line, or set a prefix that should be output at the beginning of each line, or something other. Your call, bestie. β¨OSSL_TRACE_CTRL_WRITEβ this callback fires whenever data is written to theBIOby some regularBIOoutput routine. You can get an arbitrary number ofOSSL_TRACE_CTRL_WRITEcallbacks inside a group marked by a pair ofOSSL_TRACE_CTRL_BEGINandOSSL_TRACE_CTRL_ENDcalls β but never outside such a group. Boundaries, we love them. π«ΆOSSL_TRACE_CTRL_ENDβ the callback gets called fromOSSL_trace_end(). This is your moment to output a dynamic ending line, or reset the line prefix that was set withOSSL_TRACE_CTRL_BEGIN, or something other. Closure. πΈ
π Trace categories π
The trace categories are simple numbers, available through macros. Here's the whole roster, no skips:
OSSL_TRACE_CATEGORY_TRACEβ traces the OpenSSL trace API itself.
More precisely, this will generate trace output any time a new trace hook is set. π
OSSL_TRACE_CATEGORY_INITβ traces OpenSSL library initialization and cleanup.
β οΈ This one needs special care, bestie. OpenSSL does automatic cleanup after exit frommain(), and any tracing output done during that cleanup will be lost if the tracing channel or callback were cleaned away prematurely. A suggestion is to make such cleanup part of a function that's registered very early withatexit(3).
OSSL_TRACE_CATEGORY_TLSβ traces the TLS/SSL protocol.OSSL_TRACE_CATEGORY_TLS_CIPHERβ traces the ciphers used by the TLS/SSL protocol.OSSL_TRACE_CATEGORY_CONFβ traces details about the provider and engine configuration.OSSL_TRACE_CATEGORY_ENGINE_TABLEβ traces the ENGINE algorithm table selection.
More precisely, functions like ENGINE_get_pkey_asn1_meth_engine(), ENGINE_get_pkey_meth_engine(), ENGINE_get_cipher_engine(), ENGINE_get_digest_engine(), will generate trace summaries of the handling of internal tables.
OSSL_TRACE_CATEGORY_ENGINE_REF_COUNTβ traces the ENGINE reference counting.
More precisely, both reference counts in the ENGINE structure will be monitored with a line of trace output generated for each change. π₯
OSSL_TRACE_CATEGORY_PKCS5V2β traces PKCS#5 v2 key generation.OSSL_TRACE_CATEGORY_PKCS12_KEYGENβ traces PKCS#12 key generation.OSSL_TRACE_CATEGORY_PKCS12_DECRYPTβ traces PKCS#12 decryption.OSSL_TRACE_CATEGORY_X509V3_POLICYβ traces X509v3 policy processing.
More precisely, this generates the complete policy tree at various point during evaluation.
OSSL_TRACE_CATEGORY_BN_CTXβ traces BIGNUM context operations.OSSL_TRACE_CATEGORY_CMPβ traces CMP client and server activity.OSSL_TRACE_CATEGORY_STOREβ traces STORE operations.OSSL_TRACE_CATEGORY_DECODERβ traces decoder operations.OSSL_TRACE_CATEGORY_ENCODERβ traces encoder operations.OSSL_TRACE_CATEGORY_REF_COUNTβ traces decrementing certain ASN.1 structure references.OSSL_TRACE_CATEGORY_HTTPβ traces the HTTP client, such as message headers being sent and received.
There's also OSSL_TRACE_CATEGORY_ALL, which works as a fallback and can be used to get all trace output. π
π But wait β note that in this case all trace output will effectively be associated with the 'ALL' category, which is undesirable if the application intends to include the category name in the trace output. In this case it's better to register separate channels for each trace category instead. iykyk.
π RETURN VALUES π
OSSL_trace_set_channel(), OSSL_trace_set_prefix(), OSSL_trace_set_suffix(), and OSSL_trace_set_callback() return 1 on success, or 0 on failure. That's it, that's the whole vibe check. β¨
π EXAMPLES π
In all examples below, the trace producing code is assumed to be the following:
int foo = 42;
const char bar[] = { 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15 };
OSSL_TRACE_BEGIN(TLS) {
BIO_puts(trc_out, "foo: ");
BIO_printf(trc_out, "%d\n", foo);
BIO_dump(trc_out, bar, sizeof(bar));
} OSSL_TRACE_END(TLS);
π Simple example π
An example with just a channel and constant prefix / suffix.
int main(int argc, char *argv[])
{
BIO *err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
OSSL_trace_set_channel(OSSL_TRACE_CATEGORY_SSL, err);
OSSL_trace_set_prefix(OSSL_TRACE_CATEGORY_SSL, "BEGIN TRACE[TLS]");
OSSL_trace_set_suffix(OSSL_TRACE_CATEGORY_SSL, "END TRACE[TLS]");
/* ... work ... */
}
When the trace producing code above is performed, this will be output on standard error:
BEGIN TRACE[TLS]
foo: 42
0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................
END TRACE[TLS]
π§ Advanced example π§
This example uses the callback, and depends on pthreads functionality.
static size_t cb(const char *buf, size_t cnt,
int category, int cmd, void *vdata)
{
BIO *bio = vdata;
const char *label = NULL;
switch (cmd) {
case OSSL_TRACE_CTRL_BEGIN:
label = "BEGIN";
break;
case OSSL_TRACE_CTRL_END:
label = "END";
break;
}
if (label != NULL) {
union {
pthread_t tid;
unsigned long ltid;
} tid;
tid.tid = pthread_self();
BIO_printf(bio, "%s TRACE[%s]:%lx\n",
label, OSSL_trace_get_category_name(category), tid.ltid);
}
return (size_t)BIO_puts(bio, buf);
}
int main(int argc, char *argv[])
{
BIO *err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
OSSL_trace_set_callback(OSSL_TRACE_CATEGORY_SSL, cb, err);
/* ... work ... */
}
The output is almost the same as for the simple example above.
BEGIN TRACE[TLS]:7f9eb0193b80
foo: 42
0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................
END TRACE[TLS]:7f9eb0193b80
π NOTES π
π Configure Tracing π
By default, the OpenSSL library is built with tracing disabled. So if you actually wanna use the tracing functionality documented here, you gotta configure and build OpenSSL with the 'enable-trace' option. No shortcut, bestie. π
When the library is built with tracing disabled, the macro OPENSSL_NO_TRACE is defined in <openssl/opensslconf.h> and all functions described here are inoperational, i.e. will do nothing. Literally nothing. They're just vibing. π
π SEE ALSO π
OSSL_TRACE_ENABLED(3), OSSL_TRACE_BEGIN(3), OSSL_TRACE1(3), atexit(3) π«Ά
π HISTORY π
OSSL_trace_set_channel(), OSSL_trace_set_prefix(), OSSL_trace_set_suffix(), and OSSL_trace_set_callback() were all added in OpenSSL 3.0. Icons from day one. π
πΈ COPYRIGHT πΈ
Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay that's the whole page bestie, mwah π this was OpenSSL 3.5.9, dated 2026-09-29, and the manual page is OSSL_TRACE_SET_CHANNEL(3ossl) β go trace something iconic, ily πβ¨π¦
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms