DECODER: Add tracing
authorRichard Levitte <levitte@openssl.org>
Wed, 28 Oct 2020 09:13:24 +0000 (10:13 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 11 Nov 2020 10:42:06 +0000 (11:42 +0100)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13248)

crypto/encode_decode/decoder_lib.c
crypto/encode_decode/decoder_pkey.c
crypto/trace.c
include/openssl/trace.h

index 64e6bcc1855983b2f32a7482960fc1b89f480689..8e9af13bbbfadbe9ca006146b9ae276281efad30 100644 (file)
@@ -14,6 +14,7 @@
 #include <openssl/evperr.h>
 #include <openssl/ecerr.h>
 #include <openssl/x509err.h>
 #include <openssl/evperr.h>
 #include <openssl/ecerr.h>
 #include <openssl/x509err.h>
+#include <openssl/trace.h>
 #include "internal/passphrase.h"
 #include "crypto/decoder.h"
 #include "encoder_local.h"
 #include "internal/passphrase.h"
 #include "crypto/decoder.h"
 #include "encoder_local.h"
@@ -210,6 +211,8 @@ void ossl_decoder_instance_free(OSSL_DECODER_INSTANCE *decoder_inst)
 int ossl_decoder_ctx_add_decoder_inst(OSSL_DECODER_CTX *ctx,
                                       OSSL_DECODER_INSTANCE *di)
 {
 int ossl_decoder_ctx_add_decoder_inst(OSSL_DECODER_CTX *ctx,
                                       OSSL_DECODER_INSTANCE *di)
 {
+    int ok;
+
     if (ctx->decoder_insts == NULL
         && (ctx->decoder_insts =
             sk_OSSL_DECODER_INSTANCE_new_null()) == NULL) {
     if (ctx->decoder_insts == NULL
         && (ctx->decoder_insts =
             sk_OSSL_DECODER_INSTANCE_new_null()) == NULL) {
@@ -217,7 +220,18 @@ int ossl_decoder_ctx_add_decoder_inst(OSSL_DECODER_CTX *ctx,
         return 0;
     }
 
         return 0;
     }
 
-    return (sk_OSSL_DECODER_INSTANCE_push(ctx->decoder_insts, di) > 0);
+    ok = (sk_OSSL_DECODER_INSTANCE_push(ctx->decoder_insts, di) > 0);
+    if (ok) {
+        OSSL_TRACE_BEGIN(DECODER) {
+            BIO_printf(trc_out,
+                       "(ctx %p) Added decoder instance %p (decoder %p) with:\n",
+                       (void *)ctx, (void *)di, (void *)di->decoder);
+            BIO_printf(trc_out,
+                       "    input type: %s, input structure: %s\n",
+                       di->input_type, di->input_structure);
+        } OSSL_TRACE_END(DECODER);
+    }
+    return ok;
 }
 
 int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder)
 }
 
 int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder)
@@ -615,6 +629,13 @@ static int decoder_process(const OSSL_PARAM params[], void *arg)
                                  decoder_process, &new_data,
                                  ossl_pw_passphrase_callback_dec,
                                  &new_data.ctx->pwdata);
                                  decoder_process, &new_data,
                                  ossl_pw_passphrase_callback_dec,
                                  &new_data.ctx->pwdata);
+
+        OSSL_TRACE_BEGIN(DECODER) {
+            BIO_printf(trc_out,
+                       "(ctx %p) Running decoder instance %p => %d\n",
+                       (void *)new_data.ctx, (void *)new_decoder_inst, ok);
+        } OSSL_TRACE_END(DECODER);
+
         if (ok)
             break;
         err = ERR_peek_last_error();
         if (ok)
             break;
         err = ERR_peek_last_error();
index 1835106b951b0ad254c9128669c76901ff77f974..3a765c59863f09093de691e2c6b5654e29954999 100644 (file)
@@ -14,6 +14,7 @@
 #include <openssl/ui.h>
 #include <openssl/decoder.h>
 #include <openssl/safestack.h>
 #include <openssl/ui.h>
 #include <openssl/decoder.h>
 #include <openssl/safestack.h>
+#include <openssl/trace.h>
 #include "crypto/evp.h"
 #include "crypto/decoder.h"
 #include "encoder_local.h"
 #include "crypto/evp.h"
 #include "crypto/decoder.h"
 #include "encoder_local.h"
@@ -388,13 +389,27 @@ OSSL_DECODER_CTX_new_by_EVP_PKEY(EVP_PKEY **pkey,
         ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
         ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
+
+    OSSL_TRACE_BEGIN(DECODER) {
+        BIO_printf(trc_out,
+                   "(ctx %p) Looking for %s decoders with selection %d\n",
+                   (void *)ctx, keytype, selection);
+        BIO_printf(trc_out, "    input type: %s, input structure: %s\n",
+                   input_type, input_structure);
+    } OSSL_TRACE_END(DECODER);
+
     if (OSSL_DECODER_CTX_set_input_type(ctx, input_type)
         && OSSL_DECODER_CTX_set_input_structure(ctx, input_structure)
         && OSSL_DECODER_CTX_set_selection(ctx, selection)
         && ossl_decoder_ctx_setup_for_EVP_PKEY(ctx, pkey, keytype,
                                                libctx, propquery)
     if (OSSL_DECODER_CTX_set_input_type(ctx, input_type)
         && OSSL_DECODER_CTX_set_input_structure(ctx, input_structure)
         && OSSL_DECODER_CTX_set_selection(ctx, selection)
         && ossl_decoder_ctx_setup_for_EVP_PKEY(ctx, pkey, keytype,
                                                libctx, propquery)
-        && OSSL_DECODER_CTX_add_extra(ctx, libctx, propquery))
+        && OSSL_DECODER_CTX_add_extra(ctx, libctx, propquery)) {
+        OSSL_TRACE_BEGIN(DECODER) {
+            BIO_printf(trc_out, "(ctx %p) Got %d decoders\n",
+                       (void *)ctx, OSSL_DECODER_CTX_get_num_decoders(ctx));
+        } OSSL_TRACE_END(DECODER);
         return ctx;
         return ctx;
+    }
 
     OSSL_DECODER_CTX_free(ctx);
     return NULL;
 
     OSSL_DECODER_CTX_free(ctx);
     return NULL;
index a8316c12b1b3ac42fa4d6355ae4537be21395162..46a18007533ccda2929ec7810f81273405b6011d 100644 (file)
@@ -136,6 +136,7 @@ static const struct trace_category_st trace_categories[] = {
     TRACE_CATEGORY_(X509V3_POLICY),
     TRACE_CATEGORY_(BN_CTX),
     TRACE_CATEGORY_(STORE),
     TRACE_CATEGORY_(X509V3_POLICY),
     TRACE_CATEGORY_(BN_CTX),
     TRACE_CATEGORY_(STORE),
+    TRACE_CATEGORY_(DECODER),
 };
 
 const char *OSSL_trace_get_category_name(int num)
 };
 
 const char *OSSL_trace_get_category_name(int num)
index e1c66e00f8a4ba195bbd0eac6d9d75efd636400c..d3e1e95df2afb366177b80bdbd01e82e88d0202b 100644 (file)
@@ -53,7 +53,8 @@ extern "C" {
 # define OSSL_TRACE_CATEGORY_BN_CTX             12
 # define OSSL_TRACE_CATEGORY_CMP                13
 # define OSSL_TRACE_CATEGORY_STORE              14
 # define OSSL_TRACE_CATEGORY_BN_CTX             12
 # define OSSL_TRACE_CATEGORY_CMP                13
 # define OSSL_TRACE_CATEGORY_STORE              14
-# define OSSL_TRACE_CATEGORY_NUM                15
+# define OSSL_TRACE_CATEGORY_DECODER            15
+# define OSSL_TRACE_CATEGORY_NUM                16
 
 /* Returns the trace category number for the given |name| */
 int OSSL_trace_get_category_num(const char *name);
 
 /* Returns the trace category number for the given |name| */
 int OSSL_trace_get_category_num(const char *name);