Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions include/wolfprovider/wp_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
#define WOLFPROV_MAX_LOG_WIDTH 120
#endif


/* Helper macro to select function name for logging */
#if defined(_WIN32)
#define WOLFPROV_FUNC_NAME __FUNCTION__
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define WOLFPROV_FUNC_NAME __func__
#else
#define WOLFPROV_FUNC_NAME ""
#endif


/* wolfProv debug logging support can be compiled in by defining
* WOLFPROV_DEBUG or by using the --enable-debug configure option.
*
Expand Down Expand Up @@ -234,20 +245,15 @@ int wolfProv_SetLogComponents(int componentMask);
WOLFPROV_ERROR_FUNC_LINE(type, funcName, ret, __FILE__, __LINE__)
#define WOLFPROV_ERROR_FUNC_NULL(type, funcName, ret) \
WOLFPROV_ERROR_FUNC_NULL_LINE(type, funcName, ret, __FILE__, __LINE__)

void WOLFPROV_ENTER(int type, const char* msg);
/* Call the extended version of the API with the function name of the caller. */
#ifdef _WIN32
#define WOLFPROV_LEAVE(type, msg, ret) \
WOLFPROV_LEAVE_EX(type, __FUNCTION__, msg, ret)
#elif __STDC__ && __STDC_VERSION__ >= 199901L
#define WOLFPROV_LEAVE(type, msg, ret) \
WOLFPROV_LEAVE_EX(type, __func__, msg, ret)
#else
#define WOLFPROV_LEAVE(type, msg, ret) \
WOLFPROV_LEAVE_EX(type, "", msg, ret)
#endif
void WOLFPROV_ENTER_SILENT(int type, const char* msg);
#define WOLFPROV_LEAVE(type, msg, ret) \
WOLFPROV_LEAVE_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
void WOLFPROV_LEAVE_EX(int type, const char* func, const char* msg, int ret);
#define WOLFPROV_LEAVE_SILENT(type, msg, ret) \
WOLFPROV_LEAVE_SILENT_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
void WOLFPROV_LEAVE_SILENT_EX(int type, const char* func, const char* msg,
int ret);
void WOLFPROV_MSG(int type, const char* fmt, ...);
void WOLFPROV_MSG_VERBOSE(int type, const char* fmt, ...);
void WOLFPROV_MSG_DEBUG(int type, const char* fmt, ...);
Expand All @@ -265,7 +271,9 @@ void WOLFPROV_BUFFER(int type, const unsigned char* buffer,
#else /* WOLFPROV_DEBUG */

#define WOLFPROV_ENTER(t, m)
#define WOLFPROV_ENTER_SILENT(t, m)
#define WOLFPROV_LEAVE(t, m, r)
#define WOLFPROV_LEAVE_SILENT(t, m, r)
#define WOLFPROV_MSG(t, m, ...)
#define WOLFPROV_MSG_VERBOSE(t, m, ...)
#define WOLFPROV_MSG_DEBUG(t, m, ...)
Expand Down
12 changes: 12 additions & 0 deletions scripts/build-wolfprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ show_help() {
echo " --debian --enable-fips Build a Debian package with FIPS support"
echo " --quicktest Disable some tests for a faster testing suite"
echo " --replace-default Patch OpenSSL and build it so that wolfProvider is the default provider"
echo " --leave-silent Enable leave silent mode to suppress logging of return 0 in probing functions where expected failures may occur."
echo " Note: This only affects logging; the calling function is still responsible for handling all return values appropriately."
echo ""
echo "Environment Variables:"
echo " OPENSSL_TAG OpenSSL tag to use (e.g., openssl-3.5.0)"
Expand All @@ -35,6 +37,7 @@ show_help() {
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
echo " WOLFPROV_QUICKTEST If set to 1, disables some tests in the test suite to increase test speed"
echo " WOLFPROV_DISABLE_ERR_TRACE If set to 1, wolfSSL will not be configured with --enable-debug-trace-errcodes=backtrace"
echo " WOLFPROV_LEAVE_SILENT If set to 1, suppress logging of return 0 in functions where return 0 is expected behavior sometimes."
echo ""
}

Expand Down Expand Up @@ -117,6 +120,9 @@ for arg in "$@"; do
--replace-default)
WOLFPROV_REPLACE_DEFAULT=1
;;
--leave-silent)
WOLFPROV_LEAVE_SILENT=1
;;
*)
args_wrong+="$arg, "
;;
Expand All @@ -130,6 +136,12 @@ if [ -n "$args_wrong" ]; then
exit 1
fi

# Check if --leave-silent was used without debug mode
if [ "${WOLFPROV_LEAVE_SILENT}" = "1" ] && [ -z "$WOLFPROV_DEBUG" ] && [ -z "$debug" ]; then
echo "Error: --leave-silent requires --debug to be set."
exit 1
fi

if [ -n "$build_debian" ]; then
echo "Building Debian package..."
WOLFSSL_ISFIPS=${WOLFSSL_ISFIPS:-0} ./scripts/build-debian.sh
Expand Down
4 changes: 4 additions & 0 deletions scripts/utils-wolfprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ install_wolfprov() {
WOLFPROV_CONFIG_OPTS+=" --enable-replace-default"
fi

if [ "${WOLFPROV_LEAVE_SILENT}" = "1" ]; then
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LEAVE_SILENT_MODE"
fi

./configure ${WOLFPROV_CONFIG_OPTS} CFLAGS="${WOLFPROV_CONFIG_CFLAGS}" >>$LOG_FILE 2>&1
RET=$?

Expand Down
30 changes: 18 additions & 12 deletions src/wp_dh_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ static int wp_dh_decode_spki(wp_Dh* dh, unsigned char* data, word32 len)
int rc;
word32 idx = 0;

WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_spki");
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);

rc = wc_DhPublicKeyDecode(data, &idx, &dh->key, len);
if (rc != 0) {
Expand All @@ -2053,7 +2053,8 @@ static int wp_dh_decode_spki(wp_Dh* dh, unsigned char* data, word32 len)
dh->bits = mp_count_bits(&dh->key.p);
}

WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}
#else
Expand Down Expand Up @@ -2092,7 +2093,7 @@ static int wp_dh_decode_pki(wp_Dh* dh, unsigned char* data, word32 len)
word32 idx = 0;
unsigned char* base = NULL;

WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_pki");
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);

rc = wc_DhKeyDecode(data, &idx, &dh->key, len);
if (rc != 0) {
Expand Down Expand Up @@ -2143,7 +2144,8 @@ static int wp_dh_decode_pki(wp_Dh* dh, unsigned char* data, word32 len)
}

OPENSSL_free(base);
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}
#else
Expand Down Expand Up @@ -2180,7 +2182,7 @@ static int wp_dh_decode_params(wp_Dh* dh, unsigned char* data, word32 len)
int rc;
word32 idx = 0;

WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_params");
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);

rc = wc_DhKeyDecode(data, &idx, &dh->key, len);
if (rc != 0) {
Expand All @@ -2190,7 +2192,8 @@ static int wp_dh_decode_params(wp_Dh* dh, unsigned char* data, word32 len)
dh->bits = mp_count_bits(&dh->key.p);
}

WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down Expand Up @@ -2821,7 +2824,7 @@ static int wp_dh_type_specific_does_selection(WOLFPROV_CTX* provCtx,
{
int ok;

WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_type_specific_does_selection");
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);

(void)provCtx;

Expand All @@ -2832,7 +2835,8 @@ static int wp_dh_type_specific_does_selection(WOLFPROV_CTX* provCtx,
ok = (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0;
}

WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down Expand Up @@ -2937,7 +2941,7 @@ static int wp_dh_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
{
int ok;

WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_spki_does_selection");
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);

(void)provCtx;

Expand All @@ -2948,7 +2952,8 @@ static int wp_dh_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
ok = (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0;
}

WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down Expand Up @@ -3048,7 +3053,7 @@ static int wp_dh_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
{
int ok;

WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_pki_does_selection");
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);

(void)provCtx;

Expand All @@ -3059,7 +3064,8 @@ static int wp_dh_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0;
}

WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down
51 changes: 34 additions & 17 deletions src/wp_ecc_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len)
int rc;
word32 oidLen;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_params");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

/* TODO: manually decoding as wolfSSL doesn't offer API to do this. */
if (len < 3) {
Expand Down Expand Up @@ -2047,16 +2047,26 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len)
ok = 0;
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

/**
* Decode the DER encoded ECC parameters (OID) into the ECC key object.
*
* @param [in, out] ecc ECC key object.
* @param [in] data DER encoding of the parameters (OID).
* @param [in] len Length, in bytes, of DER encoding.
* @return 1 on success.
* @return 0 on failure.
*/
static int wp_ecc_decode_x963_pub(wp_Ecc* ecc, unsigned char* data, word32 len)
{
int ok = 1;
int rc;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_x963_pub");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

rc = wc_ecc_import_x963((const byte *)data, len, &ecc->key);
if (rc != 0) {
Expand All @@ -2071,7 +2081,8 @@ static int wp_ecc_decode_x963_pub(wp_Ecc* ecc, unsigned char* data, word32 len)
}
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand All @@ -2090,7 +2101,7 @@ static int wp_ecc_decode_spki(wp_Ecc* ecc, unsigned char* data, word32 len)
int rc;
word32 idx = 0;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_spki");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

if (!wolfssl_prov_is_running()) {
ok = 0;
Expand All @@ -2110,7 +2121,8 @@ static int wp_ecc_decode_spki(wp_Ecc* ecc, unsigned char* data, word32 len)
}
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand All @@ -2129,7 +2141,7 @@ static int wp_ecc_decode_pki(wp_Ecc* ecc, unsigned char* data, word32 len)
int rc;
word32 idx = 0;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_pki");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

if (!wolfssl_prov_is_running()) {
ok = 0;
Expand Down Expand Up @@ -2171,7 +2183,8 @@ static int wp_ecc_decode_pki(wp_Ecc* ecc, unsigned char* data, word32 len)
ecc->hasPub = 1;
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down Expand Up @@ -2236,7 +2249,7 @@ static int wp_ecc_decode(wp_EccEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
unsigned char* data = NULL;
word32 len = 0;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode");
WOLFPROV_ENTER(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

(void)pwCb;
(void)pwCbArg;
Expand Down Expand Up @@ -2921,7 +2934,7 @@ static int wp_ecc_type_specific_does_selection(WOLFPROV_CTX* provCtx,
{
int ok;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_type_specific_does_selection");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

(void)provCtx;

Expand All @@ -2932,7 +2945,8 @@ static int wp_ecc_type_specific_does_selection(WOLFPROV_CTX* provCtx,
ok = (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0;
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down Expand Up @@ -3038,7 +3052,7 @@ static int wp_ecc_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
{
int ok;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_spki_does_selection");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

(void)provCtx;

Expand All @@ -3049,7 +3063,8 @@ static int wp_ecc_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
ok = (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0;
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down Expand Up @@ -3149,7 +3164,7 @@ static int wp_ecc_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
{
int ok;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_pki_does_selection");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

(void)provCtx;

Expand All @@ -3160,7 +3175,8 @@ static int wp_ecc_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0;
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down Expand Up @@ -3321,7 +3337,7 @@ static int wp_ecc_x9_62_does_selection(WOLFPROV_CTX* provCtx,
{
int ok;

WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_x9_62_does_selection");
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);

(void)provCtx;

Expand All @@ -3333,7 +3349,8 @@ static int wp_ecc_x9_62_does_selection(WOLFPROV_CTX* provCtx,
OSSL_KEYMGMT_SELECT_PRIVATE_KEY)) != 0;
}

WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
return ok;
}

Expand Down
Loading
Loading