Merge pull request 'Enabled Trace by default, added trace routines to libapps and added setup_trace to all configurable apps.' (#74) from enable_trace_support into master

Reviewed-on: http://13.234.246.121:3000/Neominds/ossl35vx69/pulls/74
This commit is contained in:
2026-07-30 20:46:02 +05:30
committed by neelimap
parent cc16d0b785
commit 1f8cf8b317
43 changed files with 426 additions and 4 deletions
@@ -17,6 +17,8 @@
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -77,6 +79,10 @@ int asn1parse_main(int argc, char **argv)
OPTION_CHOICE o; OPTION_CHOICE o;
const ASN1_ITEM *it = NULL; const ASN1_ITEM *it = NULL;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, asn1parse_options); prog = opt_init(argc, argv, asn1parse_options);
if ((osk = sk_OPENSSL_STRING_new_null()) == NULL) { if ((osk = sk_OPENSSL_STRING_new_null()) == NULL) {
@@ -24,6 +24,8 @@
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/ocsp.h> #include <openssl/ocsp.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
#ifndef W_OK #ifndef W_OK
# ifdef OPENSSL_SYS_VMS # ifdef OPENSSL_SYS_VMS
@@ -307,6 +309,10 @@ int ca_main(int argc, char **argv)
REVINFO_TYPE rev_type = REV_NONE; REVINFO_TYPE rev_type = REV_NONE;
X509_REVOKED *r = NULL; X509_REVOKED *r = NULL;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, ca_options); prog = opt_init(argc, argv, ca_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -17,6 +17,8 @@
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -98,6 +100,10 @@ int crl_main(int argc, char **argv)
int hash_old = 0; int hash_old = 0;
#endif #endif
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("digest"); opt_set_unknown_name("digest");
prog = opt_init(argc, argv, crl_options); prog = opt_init(argc, argv, crl_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -18,6 +18,8 @@
#include <openssl/pkcs7.h> #include <openssl/pkcs7.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/trace.h>
#include "app_trace.h"
static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile); static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile);
@@ -60,6 +62,10 @@ int crl2pkcs7_main(int argc, char **argv)
0; 0;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, crl2pkcs7_options); prog = opt_init(argc, argv, crl2pkcs7_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -20,6 +20,8 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/hmac.h> #include <openssl/hmac.h>
#include <ctype.h> #include <ctype.h>
#include <openssl/trace.h>
#include "app_trace.h"
#undef OSSL_DGST_BUFSIZE #undef OSSL_DGST_BUFSIZE
#define OSSL_DGST_BUFSIZE 1024*8 #define OSSL_DGST_BUFSIZE 1024*8
@@ -117,6 +119,10 @@ int dgst_main(int argc, char **argv)
EVP_MD_CTX *signctx = NULL; EVP_MD_CTX *signctx = NULL;
int oneshot_sign = 0; int oneshot_sign = 0;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
reset_unknown(); reset_unknown();
buf = app_malloc(OSSL_DGST_BUFSIZE, "I/O buffer"); buf = app_malloc(OSSL_DGST_BUFSIZE, "I/O buffer");
@@ -27,6 +27,8 @@
#include <openssl/param_build.h> #include <openssl/param_build.h>
#include <openssl/encoder.h> #include <openssl/encoder.h>
#include <openssl/decoder.h> #include <openssl/decoder.h>
#include <openssl/trace.h>
#include "app_trace.h"
#define DEFBITS 2048 #define DEFBITS 2048
@@ -91,6 +93,10 @@ int dhparam_main(int argc, char **argv)
int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0; int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, dhparam_options); prog = opt_init(argc, argv, dhparam_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -25,6 +25,8 @@
#include <openssl/encoder.h> #include <openssl/encoder.h>
#include <openssl/core_names.h> #include <openssl/core_names.h>
#include <openssl/core_dispatch.h> #include <openssl/core_dispatch.h>
#include <openssl/trace.h>
#include "app_trace.h"
#ifndef OPENSSL_NO_RC4 #ifndef OPENSSL_NO_RC4
# define DEFAULT_PVK_ENCR_STRENGTH 2 # define DEFAULT_PVK_ENCR_STRENGTH 2
@@ -92,6 +94,10 @@ int dsa_main(int argc, char **argv)
int selection = 0; int selection = 0;
OSSL_ENCODER_CTX *ectx = NULL; OSSL_ENCODER_CTX *ectx = NULL;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("cipher"); opt_set_unknown_name("cipher");
prog = opt_init(argc, argv, dsa_options); prog = opt_init(argc, argv, dsa_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -21,6 +21,8 @@
#include <openssl/dsa.h> #include <openssl/dsa.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
static int verbose = 0; static int verbose = 0;
@@ -74,6 +76,10 @@ int dsaparam_main(int argc, char **argv)
char *infile = NULL, *outfile = NULL, *prog; char *infile = NULL, *outfile = NULL, *prog;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, dsaparam_options); prog = opt_init(argc, argv, dsaparam_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -16,6 +16,8 @@
#include <openssl/core_dispatch.h> #include <openssl/core_dispatch.h>
#include <openssl/params.h> #include <openssl/params.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/trace.h>
#include "app_trace.h"
#include "apps.h" #include "apps.h"
#include "progs.h" #include "progs.h"
@@ -80,6 +82,10 @@ int ec_main(int argc, char **argv)
char *point_format = NULL; char *point_format = NULL;
int no_public = 0; int no_public = 0;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("cipher"); opt_set_unknown_name("cipher");
prog = opt_init(argc, argv, ec_options); prog = opt_init(argc, argv, ec_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -20,6 +20,8 @@
#include "apps.h" #include "apps.h"
#include "progs.h" #include "progs.h"
#include "ec_common.h" #include "ec_common.h"
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -107,6 +109,10 @@ int ecparam_main(int argc, char **argv)
int no_seed = 0, check = 0, check_named = 0, text = 0, genkey = 0; int no_seed = 0, check = 0, check_named = 0, text = 0, genkey = 0;
int list_curves = 0; int list_curves = 0;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, ecparam_options); prog = opt_init(argc, argv, ecparam_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -20,6 +20,8 @@
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
#ifndef OPENSSL_NO_COMP #ifndef OPENSSL_NO_COMP
# include <openssl/comp.h> # include <openssl/comp.h>
#endif #endif
@@ -158,7 +160,11 @@ int enc_main(int argc, char **argv)
const char *skeymgmt = NULL; const char *skeymgmt = NULL;
EVP_SKEY *skey = NULL; EVP_SKEY *skey = NULL;
EVP_SKEYMGMT *mgmt = NULL; EVP_SKEYMGMT *mgmt = NULL;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
reset_unknown(); reset_unknown();
/* first check the command name */ /* first check the command name */
@@ -21,6 +21,8 @@
#include <openssl/engine.h> #include <openssl/engine.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/store.h> #include <openssl/store.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -308,6 +310,10 @@ int engine_main(int argc, char **argv)
char *prog; char *prog;
char *argv1; char *argv1;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
out = dup_bio_out(FORMAT_TEXT); out = dup_bio_out(FORMAT_TEXT);
if (engines == NULL || pre_cmds == NULL || post_cmds == NULL) if (engines == NULL || pre_cmds == NULL || post_cmds == NULL)
goto end; goto end;
@@ -21,6 +21,8 @@
#include <openssl/dsa.h> #include <openssl/dsa.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -63,6 +65,10 @@ int gendsa_main(int argc, char **argv)
OPTION_CHOICE o; OPTION_CHOICE o;
int ret = 1, private = 0, verbose = 0, nbits; int ret = 1, private = 0, verbose = 0, nbits;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("cipher"); opt_set_unknown_name("cipher");
prog = opt_init(argc, argv, gendsa_options); prog = opt_init(argc, argv, gendsa_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -14,6 +14,8 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/trace.h>
#include "app_trace.h"
static int verbose = 1; static int verbose = 1;
@@ -120,6 +122,10 @@ int genpkey_main(int argc, char **argv)
OSSL_LIB_CTX *libctx = app_get0_libctx(); OSSL_LIB_CTX *libctx = app_get0_libctx();
STACK_OF(OPENSSL_STRING) *keyopt = NULL; STACK_OF(OPENSSL_STRING) *keyopt = NULL;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("cipher"); opt_set_unknown_name("cipher");
prog = opt_init(argc, argv, genpkey_options); prog = opt_init(argc, argv, genpkey_options);
keyopt = sk_OPENSSL_STRING_new_null(); keyopt = sk_OPENSSL_STRING_new_null();
@@ -23,6 +23,8 @@
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/trace.h>
#include "app_trace.h"
#define DEFBITS 2048 #define DEFBITS 2048
#define DEFPRIMES 2 #define DEFPRIMES 2
@@ -88,7 +90,10 @@ int genrsa_main(int argc, char **argv)
char *prog, *hexe, *dece, *ciphername = NULL; char *prog, *hexe, *dece, *ciphername = NULL;
OPTION_CHOICE o; OPTION_CHOICE o;
int traditional = 0; int traditional = 0;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
if (bn == NULL || cb == NULL) if (bn == NULL || cb == NULL)
goto end; goto end;
@@ -0,0 +1,40 @@
/*
* 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
*/
#ifndef OPENSSL_APPS_TRACE_H
# define OPENSSL_APPS_TRACE_H
# pragma once
# include <stdarg.h>
# include <openssl/bio.h>
# include <openssl/trace.h>
# ifdef __cplusplus
extern "C" {
# endif
#ifndef OPENSSL_NO_TRACE
typedef struct tracedata_st {
BIO *bio;
unsigned int ingroup:1;
} tracedata;
void setup_trace(const char *str);
#endif /* OPENSSL_NO_TRACE */
# ifdef __cplusplus
}
# endif
#endif
@@ -0,0 +1,146 @@
/*
* Copyright 1995-2021 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
*/
#include "app_trace.h"
#include "apps.h"
#include <openssl/trace.h>
#ifndef OPENSSL_NO_TRACE
BIO *trace_bio_err = NULL;
static size_t internal_trace_cb(const char *buf, size_t cnt,
int category, int cmd, void *vdata)
{
int ret = 0;
tracedata *trace_data = vdata;
char buffer[256], *hex;
CRYPTO_THREAD_ID tid;
switch (cmd) {
case OSSL_TRACE_CTRL_BEGIN:
if (trace_data->ingroup) {
BIO_printf(trace_bio_err, "ERROR: tracing already started\n");
return 0;
}
trace_data->ingroup = 1;
tid = CRYPTO_THREAD_get_current_id();
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ",
hex == NULL ? "<null>" : hex,
OSSL_trace_get_category_name(category));
OPENSSL_free(hex);
BIO_set_prefix(trace_data->bio, buffer);
break;
case OSSL_TRACE_CTRL_WRITE:
if (!trace_data->ingroup) {
BIO_printf(trace_bio_err, "ERROR: writing when tracing not started\n");
return 0;
}
ret = BIO_write(trace_data->bio, buf, cnt);
break;
case OSSL_TRACE_CTRL_END:
if (!trace_data->ingroup) {
BIO_printf(trace_bio_err, "ERROR: finishing when tracing not started\n");
return 0;
}
trace_data->ingroup = 0;
BIO_set_prefix(trace_data->bio, NULL);
break;
}
return ret < 0 ? 0 : ret;
}
DEFINE_STACK_OF(tracedata)
static STACK_OF(tracedata) *trace_data_stack;
void tracedata_free(tracedata *data)
{
BIO_free_all(data->bio);
OPENSSL_free(data);
}
static void cleanup_trace(void)
{
sk_tracedata_pop_free(trace_data_stack, tracedata_free);
}
static void setup_trace_category(int category)
{
BIO *channel;
tracedata *trace_data;
BIO *bio = NULL;
if (OSSL_trace_enabled(category))
return;
bio = BIO_new(BIO_f_prefix());
channel = BIO_push(bio, dup_bio_err(FORMAT_TEXT));
trace_data = OPENSSL_zalloc(sizeof(*trace_data));
if (trace_data == NULL
|| bio == NULL
|| (trace_data->bio = channel) == NULL
|| OSSL_trace_set_callback(category, internal_trace_cb,
trace_data) == 0
|| sk_tracedata_push(trace_data_stack, trace_data) == 0) {
fprintf(stderr,
"warning: unable to setup trace callback for category '%s'.\n",
OSSL_trace_get_category_name(category));
OSSL_trace_set_callback(category, NULL, NULL);
BIO_free_all(channel);
}
}
void setup_trace(const char *str)
{
char *val;
OSSL_trace_unset_all_callbacks();
/*
* We add this handler as early as possible to ensure it's executed
* as late as possible, i.e. after the TRACE code has done its cleanup
* (which happens last in OPENSSL_cleanup).
*/
atexit(cleanup_trace);
trace_data_stack = sk_tracedata_new_null();
val = OPENSSL_strdup(str);
if (val != NULL) {
char *valp = val;
char *item;
for (valp = val; (item = strtok(valp, ",")) != NULL; valp = NULL) {
int category = OSSL_trace_get_category_num(item);
if (category == OSSL_TRACE_CATEGORY_ALL) {
while (++category < OSSL_TRACE_CATEGORY_NUM)
setup_trace_category(category);
break;
} else if (category > 0) {
setup_trace_category(category);
} else {
fprintf(stderr,
"warning: unknown trace category: '%s'.\n", item);
}
}
}
OPENSSL_free(val);
}
#endif /* OPENSSL_NO_TRACE */
@@ -8,7 +8,7 @@ IF[{- $config{target} =~ /^vms-/ -}]
ENDIF ENDIF
# Source for libapps # Source for libapps
$LIBAPPSSRC=apps.c apps_ui.c log.c opt.c fmt.c s_cb.c s_socket.c app_rand.c \ $LIBAPPSSRC=apps.c app_trace.c apps_ui.c log.c opt.c fmt.c s_cb.c s_socket.c app_rand.c \
columns.c app_params.c names.c app_provider.c app_x509.c http_server.c \ columns.c app_params.c names.c app_provider.c app_x509.c http_server.c \
engine_lib.c engine_loader.c app_libctx.c apps_opt_printf.c engine_lib.c engine_loader.c app_libctx.c apps_opt_printf.c
@@ -13,6 +13,8 @@
#include "progs.h" #include "progs.h"
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -44,6 +46,10 @@ int nseq_main(int argc, char **argv)
int toseq = 0, ret = 1, i; int toseq = 0, ret = 1, i;
char *infile = NULL, *outfile = NULL, *prog; char *infile = NULL, *outfile = NULL, *prog;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, nseq_options); prog = opt_init(argc, argv, nseq_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -32,6 +32,8 @@
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#include <openssl/trace.h>
#include "app_trace.h"
#if defined(OPENSSL_SYS_VXWORKS) #if defined(OPENSSL_SYS_VXWORKS)
/* not supported */ /* not supported */
@@ -252,6 +254,10 @@ int ocsp_main(int argc, char **argv)
unsigned long sign_flags = 0, verify_flags = 0, rflags = 0; unsigned long sign_flags = 0, verify_flags = 0, rflags = 0;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
if ((reqnames = sk_OPENSSL_STRING_new_null()) == NULL if ((reqnames = sk_OPENSSL_STRING_new_null()) == NULL
|| (ids = sk_OCSP_CERTID_new_null()) == NULL || (ids = sk_OCSP_CERTID_new_null()) == NULL
|| (vpm = X509_VERIFY_PARAM_new()) == NULL) || (vpm = X509_VERIFY_PARAM_new()) == NULL)
@@ -21,6 +21,8 @@
#endif #endif
#include <openssl/md5.h> #include <openssl/md5.h>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <openssl/trace.h>
#include "app_trace.h"
static const unsigned char cov_2char[64] = { static const unsigned char cov_2char[64] = {
/* from crypto/des/fcrypt.c */ /* from crypto/des/fcrypt.c */
@@ -107,6 +109,10 @@ int passwd_main(int argc, char **argv)
size_t pw_maxlen = 256; /* arbitrary limit, should be enough for most size_t pw_maxlen = 256; /* arbitrary limit, should be enough for most
* passwords */ * passwords */
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, passwd_options); prog = opt_init(argc, argv, passwd_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -22,6 +22,8 @@
#include <openssl/provider.h> #include <openssl/provider.h>
#include <openssl/kdf.h> #include <openssl/kdf.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/trace.h>
#include "app_trace.h"
#define NOKEYS 0x1 #define NOKEYS 0x1
#define NOCERTS 0x2 #define NOCERTS 0x2
@@ -191,6 +193,10 @@ int pkcs12_main(int argc, char **argv)
EVP_CIPHER *enc = (EVP_CIPHER *)default_enc; EVP_CIPHER *enc = (EVP_CIPHER *)default_enc;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("cipher"); opt_set_unknown_name("cipher");
prog = opt_init(argc, argv, pkcs12_options); prog = opt_init(argc, argv, pkcs12_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -19,6 +19,8 @@
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pkcs7.h> #include <openssl/pkcs7.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -64,6 +66,10 @@ int pkcs7_main(int argc, char **argv)
OPTION_CHOICE o; OPTION_CHOICE o;
OSSL_LIB_CTX *libctx = app_get0_libctx(); OSSL_LIB_CTX *libctx = app_get0_libctx();
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, pkcs7_options); prog = opt_init(argc, argv, pkcs7_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -16,6 +16,8 @@
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/pkcs12.h> #include <openssl/pkcs12.h>
#include <openssl/trace.h>
#include "app_trace.h"
#define STR(a) XSTR(a) #define STR(a) XSTR(a)
#define XSTR(a) #a #define XSTR(a) #a
@@ -95,6 +97,10 @@ int pkcs8_main(int argc, char **argv)
#endif #endif
int saltlen = 0; /* A value of zero chooses the default */ int saltlen = 0; /* A value of zero chooses the default */
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, pkcs8_options); prog = opt_init(argc, argv, pkcs8_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -16,6 +16,8 @@
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/core_names.h> #include <openssl/core_names.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -83,6 +85,10 @@ int pkey_main(int argc, char **argv)
char *point_format = NULL; char *point_format = NULL;
#endif #endif
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("cipher"); opt_set_unknown_name("cipher");
prog = opt_init(argc, argv, pkey_options); prog = opt_init(argc, argv, pkey_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -15,6 +15,8 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -53,6 +55,10 @@ int pkeyparam_main(int argc, char **argv)
OPTION_CHOICE o; OPTION_CHOICE o;
char *infile = NULL, *outfile = NULL, *prog; char *infile = NULL, *outfile = NULL, *prog;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, pkeyparam_options); prog = opt_init(argc, argv, pkeyparam_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -14,6 +14,8 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <openssl/trace.h>
#include "app_trace.h"
#define KEY_NONE 0 #define KEY_NONE 0
#define KEY_PRIVKEY 1 #define KEY_PRIVKEY 1
@@ -149,6 +151,11 @@ int pkeyutl_main(int argc, char **argv)
EVP_MD_CTX *mctx = NULL; EVP_MD_CTX *mctx = NULL;
EVP_MD *md = NULL; EVP_MD *md = NULL;
int filesize = -1; int filesize = -1;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
OSSL_LIB_CTX *libctx = app_get0_libctx(); OSSL_LIB_CTX *libctx = app_get0_libctx();
prog = opt_init(argc, argv, pkeyutl_options); prog = opt_init(argc, argv, pkeyutl_options);
@@ -17,6 +17,8 @@
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -58,6 +60,10 @@ int rand_main(int argc, char **argv)
uint64_t scaled_num = 0; uint64_t scaled_num = 0;
uint8_t *buf = NULL; uint8_t *buf = NULL;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, rand_options); prog = opt_init(argc, argv, rand_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -27,6 +27,8 @@
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/lhash.h> #include <openssl/lhash.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/trace.h>
#include "app_trace.h"
#ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h> # include <openssl/dsa.h>
#endif #endif
@@ -275,6 +277,10 @@ int req_main(int argc, char **argv)
long newkey_len = -1; long newkey_len = -1;
unsigned long chtype = MBSTRING_ASC, reqflag = 0; unsigned long chtype = MBSTRING_ASC, reqflag = 0;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
cipher = (EVP_CIPHER *)EVP_aes_256_cbc(); cipher = (EVP_CIPHER *)EVP_aes_256_cbc();
opt_set_unknown_name("digest"); opt_set_unknown_name("digest");
@@ -26,6 +26,8 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/encoder.h> #include <openssl/encoder.h>
#include <openssl/trace.h>
#include "app_trace.h"
/* /*
* This include is to get OSSL_KEYMGMT_SELECT_*, which feels a bit * This include is to get OSSL_KEYMGMT_SELECT_*, which feels a bit
@@ -139,6 +141,10 @@ int rsa_main(int argc, char **argv)
int selection = 0; int selection = 0;
OSSL_ENCODER_CTX *ectx = NULL; OSSL_ENCODER_CTX *ectx = NULL;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("cipher"); opt_set_unknown_name("cipher");
prog = opt_init(argc, argv, rsa_options); prog = opt_init(argc, argv, rsa_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -15,6 +15,8 @@
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/trace.h>
#include "app_trace.h"
#define RSA_SIGN 1 #define RSA_SIGN 1
#define RSA_VERIFY 2 #define RSA_VERIFY 2
@@ -85,6 +87,10 @@ int rsautl_main(int argc, char **argv)
int hexdump = 0, asn1parse = 0, need_priv = 0, rev = 0; int hexdump = 0, asn1parse = 0, need_priv = 0, rev = 0;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, rsautl_options); prog = opt_init(argc, argv, rsautl_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -48,6 +48,8 @@ typedef unsigned int u_int;
#include "s_apps.h" #include "s_apps.h"
#include "timeouts.h" #include "timeouts.h"
#include "internal/sockets.h" #include "internal/sockets.h"
#include <openssl/trace.h>
#include "app_trace.h"
#if defined(__has_feature) #if defined(__has_feature)
# if __has_feature(memory_sanitizer) # if __has_feature(memory_sanitizer)
@@ -961,6 +963,10 @@ int s_client_main(int argc, char **argv)
BIO_ADDR *peer_addr = NULL; BIO_ADDR *peer_addr = NULL;
struct user_data_st user_data; struct user_data_st user_data;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
FD_ZERO(&readfds); FD_ZERO(&readfds);
FD_ZERO(&writefds); FD_ZERO(&writefds);
/* Known false-positive of MemorySanitizer. */ /* Known false-positive of MemorySanitizer. */
@@ -57,6 +57,8 @@ typedef unsigned int u_int;
#include <openssl/ebcdic.h> #include <openssl/ebcdic.h>
#endif #endif
#include "internal/sockets.h" #include "internal/sockets.h"
#include <openssl/trace.h>
#include "app_trace.h"
static int not_resumable_sess_cb(SSL *s, int is_forward_secure); static int not_resumable_sess_cb(SSL *s, int is_forward_secure);
static int sv_body(int s, int stype, int prot, unsigned char *context); static int sv_body(int s, int stype, int prot, unsigned char *context);
@@ -1114,6 +1116,10 @@ int s_server_main(int argc, char *argv[])
use_sendfile = 0; use_sendfile = 0;
use_zc_sendfile = 0; use_zc_sendfile = 0;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
#if defined(OPENSSL_SYS_VXWORKS_SUPPORT) #if defined(OPENSSL_SYS_VXWORKS_SUPPORT)
if (bio_err == NULL) if (bio_err == NULL)
bio_err = dup_bio_err(FORMAT_TEXT); bio_err = dup_bio_err(FORMAT_TEXT);
@@ -18,6 +18,8 @@
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/x509_vfy.h> #include <openssl/x509_vfy.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#include <openssl/trace.h>
#include "app_trace.h"
static int save_certs(char *signerfile, STACK_OF(X509) *signers); static int save_certs(char *signerfile, STACK_OF(X509) *signers);
static int smime_cb(int ok, X509_STORE_CTX *ctx); static int smime_cb(int ok, X509_STORE_CTX *ctx);
@@ -184,6 +186,11 @@ int smime_main(int argc, char **argv)
int vpmtouched = 0, rv = 0; int vpmtouched = 0, rv = 0;
ENGINE *e = NULL; ENGINE *e = NULL;
const char *mime_eol = "\n"; const char *mime_eol = "\n";
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
OSSL_LIB_CTX *libctx = app_get0_libctx(); OSSL_LIB_CTX *libctx = app_get0_libctx();
if ((vpm = X509_VERIFY_PARAM_new()) == NULL) if ((vpm = X509_VERIFY_PARAM_new()) == NULL)
@@ -44,6 +44,8 @@
#include <openssl/core_names.h> #include <openssl/core_names.h>
#include <openssl/async.h> #include <openssl/async.h>
#include <openssl/provider.h> #include <openssl/provider.h>
#include <openssl/trace.h>
#include "app_trace.h"
#if !defined(OPENSSL_SYS_MSDOS) #if !defined(OPENSSL_SYS_MSDOS)
# include <unistd.h> # include <unistd.h>
#endif #endif
@@ -1907,6 +1909,11 @@ int speed_main(int argc, char **argv)
#ifndef NO_FORK #ifndef NO_FORK
int multi = 0; int multi = 0;
#endif #endif
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
long op_count = 1; long op_count = 1;
openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS, openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
ECDSA_SECONDS, ECDH_SECONDS, ECDSA_SECONDS, ECDH_SECONDS,
@@ -19,6 +19,8 @@
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -73,6 +75,10 @@ int spkac_main(int argc, char **argv)
int keyformat = FORMAT_UNDEF; int keyformat = FORMAT_UNDEF;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, spkac_options); prog = opt_init(argc, argv, spkac_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -15,6 +15,8 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/store.h> #include <openssl/store.h>
#include <openssl/x509v3.h> /* s2i_ASN1_INTEGER */ #include <openssl/x509v3.h> /* s2i_ASN1_INTEGER */
#include <openssl/trace.h>
#include "app_trace.h"
static int process(const char *uri, const UI_METHOD *uimeth, PW_CB_DATA *uidata, static int process(const char *uri, const UI_METHOD *uimeth, PW_CB_DATA *uidata,
int expected, int criterion, OSSL_STORE_SEARCH *search, int expected, int criterion, OSSL_STORE_SEARCH *search,
@@ -88,6 +90,10 @@ int storeutl_main(int argc, char *argv[])
EVP_MD *digest = NULL; EVP_MD *digest = NULL;
OSSL_LIB_CTX *libctx = app_get0_libctx(); OSSL_LIB_CTX *libctx = app_get0_libctx();
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
opt_set_unknown_name("digest"); opt_set_unknown_name("digest");
prog = opt_init(argc, argv, storeutl_options); prog = opt_init(argc, argv, storeutl_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
@@ -17,6 +17,8 @@
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/trace.h>
#include "app_trace.h"
static int cb(int ok, X509_STORE_CTX *ctx); static int cb(int ok, X509_STORE_CTX *ctx);
static int check(X509_STORE *ctx, const char *file, static int check(X509_STORE *ctx, const char *file,
@@ -89,6 +91,10 @@ int verify_main(int argc, char **argv)
int vpmtouched = 0, crl_download = 0, show_chain = 0, i = 0, ret = 1; int vpmtouched = 0, crl_download = 0, show_chain = 0, i = 0, ret = 1;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
if ((vpm = X509_VERIFY_PARAM_new()) == NULL) if ((vpm = X509_VERIFY_PARAM_new()) == NULL)
goto end; goto end;
@@ -15,6 +15,8 @@
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/trace.h>
#include "app_trace.h"
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_COMMON, OPT_COMMON,
@@ -57,6 +59,10 @@ int version_main(int argc, char **argv)
char *prog; char *prog;
OPTION_CHOICE o; OPTION_CHOICE o;
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
prog = opt_init(argc, argv, version_options); prog = opt_init(argc, argv, version_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
@@ -22,6 +22,8 @@
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/trace.h>
#include "app_trace.h"
#ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h> # include <openssl/dsa.h>
#endif #endif
@@ -306,6 +308,10 @@ int x509_main(int argc, char **argv)
int subject_hash_old = 0, issuer_hash_old = 0; int subject_hash_old = 0, issuer_hash_old = 0;
#endif #endif
#ifndef OPENSSL_NO_TRACE
setup_trace(getenv("OPENSSL_TRACE"));
#endif
reset_unknown(); reset_unknown();
ctx = X509_STORE_new(); ctx = X509_STORE_new();
@@ -395,6 +395,14 @@ static int trace_attach_w_callback_cb(int category, int type, const void *data)
} }
#endif #endif
void OSSL_trace_unset_all_callbacks(void)
{
int i;
for (i = 0; i < OSSL_TRACE_CATEGORY_NUM; i++) {
OSSL_trace_set_callback(i, NULL, NULL);
}
}
int OSSL_trace_set_callback(int category, OSSL_trace_cb callback, void *data) int OSSL_trace_set_callback(int category, OSSL_trace_cb callback, void *data)
{ {
#ifndef OPENSSL_NO_TRACE #ifndef OPENSSL_NO_TRACE
@@ -64,6 +64,10 @@ extern "C" {
# define OSSL_TRACE_CATEGORY_NUM 24 # define OSSL_TRACE_CATEGORY_NUM 24
/* KEEP THIS LIST IN SYNC with trace_categories[] in crypto/trace.c */ /* KEEP THIS LIST IN SYNC with trace_categories[] in crypto/trace.c */
/* Unsets (clears) all previously registered trace callbacks for every trace category */
void OSSL_trace_unset_all_callbacks(void);
/* Returns the trace category number for the given |name| */ /* Returns the trace category number for the given |name| */
int OSSL_trace_get_category_num(const char *name); int OSSL_trace_get_category_num(const char *name);
@@ -32,7 +32,7 @@ endif
OPENSSL_CPPFLAGS = -DOPENSSL_SYS_VXWORKS_SUPPORT -DOPENSSL_NO_THREAD_POOL -DVX69_TIMESTAMP_ENTROPY_SUPPORT OPENSSL_CPPFLAGS = -DOPENSSL_SYS_VXWORKS_SUPPORT -DOPENSSL_NO_THREAD_POOL -DVX69_TIMESTAMP_ENTROPY_SUPPORT
OPENSSL_CONFIGURE_OPTIONS = no-shared OPENSSL_CONFIGURE_OPTIONS = no-shared enable-trace
ifneq (, $(findstring enable-fips, $(CONFIGURE_CMD))) ifneq (, $(findstring enable-fips, $(CONFIGURE_CMD)))
OPENSSL_FIPS_ENABLE = OPENSSL_FIPS_ENABLE =