diff --git a/include/wolfprovider/wp_logging.h b/include/wolfprovider/wp_logging.h index 9dd102e9..0da07c92 100644 --- a/include/wolfprovider/wp_logging.h +++ b/include/wolfprovider/wp_logging.h @@ -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. * @@ -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, ...); @@ -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, ...) diff --git a/scripts/build-wolfprovider.sh b/scripts/build-wolfprovider.sh index 16f2584d..79c8c274 100755 --- a/scripts/build-wolfprovider.sh +++ b/scripts/build-wolfprovider.sh @@ -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)" @@ -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 "" } @@ -117,6 +120,9 @@ for arg in "$@"; do --replace-default) WOLFPROV_REPLACE_DEFAULT=1 ;; + --leave-silent) + WOLFPROV_LEAVE_SILENT=1 + ;; *) args_wrong+="$arg, " ;; @@ -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 diff --git a/scripts/utils-wolfprovider.sh b/scripts/utils-wolfprovider.sh index f3d11481..e3dc5696 100644 --- a/scripts/utils-wolfprovider.sh +++ b/scripts/utils-wolfprovider.sh @@ -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=$? diff --git a/src/wp_dh_kmgmt.c b/src/wp_dh_kmgmt.c index 0e5e24db..e9e32717 100644 --- a/src/wp_dh_kmgmt.c +++ b/src/wp_dh_kmgmt.c @@ -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) { @@ -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 @@ -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) { @@ -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 @@ -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) { @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; } diff --git a/src/wp_ecc_kmgmt.c b/src/wp_ecc_kmgmt.c index 8aad74e5..174003c5 100644 --- a/src/wp_ecc_kmgmt.c +++ b/src/wp_ecc_kmgmt.c @@ -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) { @@ -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) { @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; } diff --git a/src/wp_ecx_kmgmt.c b/src/wp_ecx_kmgmt.c index c8c17f65..8bf3d056 100644 --- a/src/wp_ecx_kmgmt.c +++ b/src/wp_ecx_kmgmt.c @@ -2196,7 +2196,7 @@ static int wp_ecx_spki_does_selection(WOLFPROV_CTX* provCtx, int selection) { int ok = 0; - WOLFPROV_ENTER(WP_LOG_KE, "wp_ecx_spki_does_selection"); + WOLFPROV_ENTER_SILENT(WP_LOG_KE, WOLFPROV_FUNC_NAME); (void)provCtx; @@ -2207,7 +2207,8 @@ static int wp_ecx_spki_does_selection(WOLFPROV_CTX* provCtx, int selection) ok = (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0; } - WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -2227,7 +2228,7 @@ static int wp_ecx_pki_does_selection(WOLFPROV_CTX* provCtx, int selection) { int ok; - WOLFPROV_ENTER(WP_LOG_KE, "wp_ecx_pki_does_selection"); + WOLFPROV_ENTER_SILENT(WP_LOG_KE, WOLFPROV_FUNC_NAME); (void)provCtx; @@ -2238,7 +2239,8 @@ static int wp_ecx_pki_does_selection(WOLFPROV_CTX* provCtx, int selection) ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0; } - WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } diff --git a/src/wp_logging.c b/src/wp_logging.c index 61400134..01648cdf 100644 --- a/src/wp_logging.c +++ b/src/wp_logging.c @@ -274,11 +274,34 @@ void WOLFPROV_ENTER(int component, const char* msg) { if (loggingEnabled) { char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), "wolfProv Entering %s", msg); + XSNPRINTF(buffer, sizeof(buffer), + "wolfProv Entering %s", msg); wolfprovider_log(WP_LOG_ENTER, component, buffer); } } +/** + * Log function used to record function entry for check functions. + * These functions use WOLFPROV_LEAVE_SILENT and may not show up in logs. + * The "[leaving silently]" prefix indicates that exit logging may be suppressed. + * + * @param component [IN] Component type, from wolfProv_LogComponents enum. + * @param msg [IN] Log message. + */ +void WOLFPROV_ENTER_SILENT(int component, const char* msg) +{ +#ifdef WOLFPROV_LEAVE_SILENT_MODE + if (loggingEnabled) { + char buffer[WOLFPROV_MAX_LOG_WIDTH]; + XSNPRINTF(buffer, sizeof(buffer), + "wolfProv Entering [leaving silently] %s", msg); + wolfprovider_log(WP_LOG_ENTER, component, buffer); + } +#else + WOLFPROV_ENTER(component, msg); +#endif +} + /** * Log function used to record function exit. Extended for function name. * @@ -288,16 +311,43 @@ void WOLFPROV_ENTER(int component, const char* msg) * @param ret [IN] Value that function will be returning. */ void WOLFPROV_LEAVE_EX(int component, const char* func, const char* msg, - int ret) + int ret) { if (loggingEnabled) { char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), "wolfProv Leaving %s, return %d (%s)", - msg, ret, func); + XSNPRINTF(buffer, sizeof(buffer), + "wolfProv Leaving %s, return %d (%s)", msg, ret, func); wolfprovider_log(WP_LOG_LEAVE, component, buffer); } } +/** + * Log function to suppress LEAVE messages. This function only prints if + * ret == 1. All other cases are suppressed by default to reduce noise from + * probe failures. Define WOLFPROV_LEAVE_SILENT to enable this logic. + * + * @param component [IN] Component type, from wolfProv_LogComponents enum. + * @param func [IN] Name of function that is exiting. + * @param msg [IN] Log message (typically file:line). + * @param ret [IN] Value that function will be returning. + */ +void WOLFPROV_LEAVE_SILENT_EX(int component, const char* func, + const char* msg, int ret) +{ +#ifdef WOLFPROV_LEAVE_SILENT_MODE + /* Success - always print */ + if (ret == 1) { + WOLFPROV_LEAVE_EX(component, func, msg, ret); + } + else { + /* Anything else is suppressed */ + } +#else + /* Legacy behavior: log all returns including return 0 */ + WOLFPROV_LEAVE_EX(component, func, msg, ret); +#endif +} + /** * Log function for error code, general error message. * @@ -330,8 +380,8 @@ void WOLFPROV_ERROR_MSG_LINE(int component, const char* msg, { if (loggingEnabled) { char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), "%s:%d - wolfProv Error %s", - file, line, msg); + XSNPRINTF(buffer, sizeof(buffer), + "%s:%d - wolfProv Error %s", file, line, msg); wolfprovider_log(WP_LOG_ERROR, component, buffer); } } diff --git a/src/wp_rsa_kmgmt.c b/src/wp_rsa_kmgmt.c index a4c3d41f..af300e70 100644 --- a/src/wp_rsa_kmgmt.c +++ b/src/wp_rsa_kmgmt.c @@ -1992,7 +1992,7 @@ static int wp_rsa_find_oid(unsigned char* data, word32 len, unsigned char* oid, int ok = 0; word32 i; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_find_oid"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); for (i = 0; i < len - RSA_PKCS1_OID_SZ - 1; i++) { /* Find the base OID. */ @@ -2003,7 +2003,8 @@ static int wp_rsa_find_oid(unsigned char* data, word32 len, unsigned char* oid, } } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -2195,7 +2196,7 @@ static int wp_rsa_decode_spki(wp_Rsa* rsa, unsigned char* data, word32 len) int rc; word32 idx = 0; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_decode_spki"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); if (!wolfssl_prov_is_running()) { ok = 0; @@ -2222,7 +2223,8 @@ static int wp_rsa_decode_spki(wp_Rsa* rsa, unsigned char* data, word32 len) rsa->hasPub = 1; } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -2241,7 +2243,7 @@ static int wp_rsa_decode_pki(wp_Rsa* rsa, unsigned char* data, word32 len) int rc; word32 idx = 0; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_decode_pki"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); if (!wolfssl_prov_is_running()) { ok = 0; @@ -2277,7 +2279,8 @@ static int wp_rsa_decode_pki(wp_Rsa* rsa, unsigned char* data, word32 len) rsa->hasPriv = 1; } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -2303,7 +2306,7 @@ static int wp_rsa_find_pbkdf2_oid(unsigned char* data, word32 len) int ok = 0; word32 i; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_find_pbkdf2_oid"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); for (i = 0; i < 40 && i + PBKDF2_OID_SZ < len; i++) { /* Find the base OID. */ @@ -2313,7 +2316,8 @@ static int wp_rsa_find_pbkdf2_oid(unsigned char* data, word32 len) } } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -2335,7 +2339,7 @@ static int wp_rsa_decode_enc_pki(wp_Rsa* rsa, unsigned char* data, word32 len, char password[1024]; size_t passwordSz = sizeof(password); - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_decode_enc_pki"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); if (!wolfssl_prov_is_running()) { ok = 0; @@ -2365,7 +2369,8 @@ static int wp_rsa_decode_enc_pki(wp_Rsa* rsa, unsigned char* data, word32 len, ok = wp_rsa_decode_pki(rsa, data, len); } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -2435,7 +2440,7 @@ static int wp_rsa_decode(wp_RsaEncDecCtx* ctx, OSSL_CORE_BIO* cBio, (void)pwCb; (void)pwCbArg; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_decode"); + WOLFPROV_ENTER(WP_LOG_RSA, WOLFPROV_FUNC_NAME); ctx->selection = selection; @@ -3410,7 +3415,7 @@ static int wp_rsa_spki_does_selection(WOLFPROV_CTX* provCtx, int selection) { int ok; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_spki_does_selection"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); (void)provCtx; @@ -3421,7 +3426,8 @@ static int wp_rsa_spki_does_selection(WOLFPROV_CTX* provCtx, int selection) ok = (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0; } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -3524,7 +3530,7 @@ static int wp_rsa_pki_does_selection(WOLFPROV_CTX* provCtx, int selection) { int ok; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_pki_does_selection"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); (void)provCtx; @@ -3535,7 +3541,8 @@ static int wp_rsa_pki_does_selection(WOLFPROV_CTX* provCtx, int selection) ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0; } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -3700,7 +3707,7 @@ static int wp_rsa_legacy_does_selection(WOLFPROV_CTX* provCtx, int selection) { int ok; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_legacy_does_selection"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); (void)provCtx; @@ -3711,7 +3718,8 @@ static int wp_rsa_legacy_does_selection(WOLFPROV_CTX* provCtx, int selection) ok = (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0; } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -3754,7 +3762,7 @@ static int wp_rsa_kp_does_selection(WOLFPROV_CTX* provCtx, int selection) { int ok; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_kp_does_selection"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); (void)provCtx; @@ -3765,7 +3773,8 @@ static int wp_rsa_kp_does_selection(WOLFPROV_CTX* provCtx, int selection) ok = (selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0; } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; } @@ -4026,7 +4035,7 @@ static int wp_rsa_text_enc_does_selection(WOLFPROV_CTX* provCtx, int selection) { int ok; - WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_text_enc_does_selection"); + WOLFPROV_ENTER_SILENT(WP_LOG_RSA, WOLFPROV_FUNC_NAME); (void)provCtx; @@ -4039,7 +4048,8 @@ static int wp_rsa_text_enc_does_selection(WOLFPROV_CTX* provCtx, int selection) ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0); } - WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + WOLFPROV_LEAVE_SILENT(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), + ok); return ok; }