Skip to content

Commit 5b90320

Browse files
authored
Merge pull request #261 from aidangarske/wp-leave-silent
Support for WOLFPROV_LEAVE_SILENT return 0 suppression
2 parents 1e1769b + 689f78c commit 5b90320

File tree

8 files changed

+181
-72
lines changed

8 files changed

+181
-72
lines changed

include/wolfprovider/wp_logging.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@
4242
#define WOLFPROV_MAX_LOG_WIDTH 120
4343
#endif
4444

45+
46+
/* Helper macro to select function name for logging */
47+
#if defined(_WIN32)
48+
#define WOLFPROV_FUNC_NAME __FUNCTION__
49+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
50+
#define WOLFPROV_FUNC_NAME __func__
51+
#else
52+
#define WOLFPROV_FUNC_NAME ""
53+
#endif
54+
55+
4556
/* wolfProv debug logging support can be compiled in by defining
4657
* WOLFPROV_DEBUG or by using the --enable-debug configure option.
4758
*
@@ -234,20 +245,15 @@ int wolfProv_SetLogComponents(int componentMask);
234245
WOLFPROV_ERROR_FUNC_LINE(type, funcName, ret, __FILE__, __LINE__)
235246
#define WOLFPROV_ERROR_FUNC_NULL(type, funcName, ret) \
236247
WOLFPROV_ERROR_FUNC_NULL_LINE(type, funcName, ret, __FILE__, __LINE__)
237-
238248
void WOLFPROV_ENTER(int type, const char* msg);
239-
/* Call the extended version of the API with the function name of the caller. */
240-
#ifdef _WIN32
241-
#define WOLFPROV_LEAVE(type, msg, ret) \
242-
WOLFPROV_LEAVE_EX(type, __FUNCTION__, msg, ret)
243-
#elif __STDC__ && __STDC_VERSION__ >= 199901L
244-
#define WOLFPROV_LEAVE(type, msg, ret) \
245-
WOLFPROV_LEAVE_EX(type, __func__, msg, ret)
246-
#else
247-
#define WOLFPROV_LEAVE(type, msg, ret) \
248-
WOLFPROV_LEAVE_EX(type, "", msg, ret)
249-
#endif
249+
void WOLFPROV_ENTER_SILENT(int type, const char* msg);
250+
#define WOLFPROV_LEAVE(type, msg, ret) \
251+
WOLFPROV_LEAVE_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
250252
void WOLFPROV_LEAVE_EX(int type, const char* func, const char* msg, int ret);
253+
#define WOLFPROV_LEAVE_SILENT(type, msg, ret) \
254+
WOLFPROV_LEAVE_SILENT_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
255+
void WOLFPROV_LEAVE_SILENT_EX(int type, const char* func, const char* msg,
256+
int ret);
251257
void WOLFPROV_MSG(int type, const char* fmt, ...);
252258
void WOLFPROV_MSG_VERBOSE(int type, const char* fmt, ...);
253259
void WOLFPROV_MSG_DEBUG(int type, const char* fmt, ...);
@@ -265,7 +271,9 @@ void WOLFPROV_BUFFER(int type, const unsigned char* buffer,
265271
#else /* WOLFPROV_DEBUG */
266272

267273
#define WOLFPROV_ENTER(t, m)
274+
#define WOLFPROV_ENTER_SILENT(t, m)
268275
#define WOLFPROV_LEAVE(t, m, r)
276+
#define WOLFPROV_LEAVE_SILENT(t, m, r)
269277
#define WOLFPROV_MSG(t, m, ...)
270278
#define WOLFPROV_MSG_VERBOSE(t, m, ...)
271279
#define WOLFPROV_MSG_DEBUG(t, m, ...)

scripts/build-wolfprovider.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ show_help() {
2222
echo " --debian --enable-fips Build a Debian package with FIPS support"
2323
echo " --quicktest Disable some tests for a faster testing suite"
2424
echo " --replace-default Patch OpenSSL and build it so that wolfProvider is the default provider"
25+
echo " --leave-silent Enable leave silent mode to suppress logging of return 0 in probing functions where expected failures may occur."
26+
echo " Note: This only affects logging; the calling function is still responsible for handling all return values appropriately."
2527
echo ""
2628
echo "Environment Variables:"
2729
echo " OPENSSL_TAG OpenSSL tag to use (e.g., openssl-3.5.0)"
@@ -35,6 +37,7 @@ show_help() {
3537
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
3638
echo " WOLFPROV_QUICKTEST If set to 1, disables some tests in the test suite to increase test speed"
3739
echo " WOLFPROV_DISABLE_ERR_TRACE If set to 1, wolfSSL will not be configured with --enable-debug-trace-errcodes=backtrace"
40+
echo " WOLFPROV_LEAVE_SILENT If set to 1, suppress logging of return 0 in functions where return 0 is expected behavior sometimes."
3841
echo ""
3942
}
4043

@@ -117,6 +120,9 @@ for arg in "$@"; do
117120
--replace-default)
118121
WOLFPROV_REPLACE_DEFAULT=1
119122
;;
123+
--leave-silent)
124+
WOLFPROV_LEAVE_SILENT=1
125+
;;
120126
*)
121127
args_wrong+="$arg, "
122128
;;
@@ -130,6 +136,12 @@ if [ -n "$args_wrong" ]; then
130136
exit 1
131137
fi
132138

139+
# Check if --leave-silent was used without debug mode
140+
if [ "${WOLFPROV_LEAVE_SILENT}" = "1" ] && [ -z "$WOLFPROV_DEBUG" ] && [ -z "$debug" ]; then
141+
echo "Error: --leave-silent requires --debug to be set."
142+
exit 1
143+
fi
144+
133145
if [ -n "$build_debian" ]; then
134146
echo "Building Debian package..."
135147
WOLFSSL_ISFIPS=${WOLFSSL_ISFIPS:-0} ./scripts/build-debian.sh

scripts/utils-wolfprovider.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ install_wolfprov() {
165165
WOLFPROV_CONFIG_OPTS+=" --enable-replace-default"
166166
fi
167167

168+
if [ "${WOLFPROV_LEAVE_SILENT}" = "1" ]; then
169+
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LEAVE_SILENT_MODE"
170+
fi
171+
168172
./configure ${WOLFPROV_CONFIG_OPTS} CFLAGS="${WOLFPROV_CONFIG_CFLAGS}" >>$LOG_FILE 2>&1
169173
RET=$?
170174

src/wp_dh_kmgmt.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ static int wp_dh_decode_spki(wp_Dh* dh, unsigned char* data, word32 len)
20302030
int rc;
20312031
word32 idx = 0;
20322032

2033-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_spki");
2033+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
20342034

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

2056-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2056+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2057+
ok);
20572058
return ok;
20582059
}
20592060
#else
@@ -2092,7 +2093,7 @@ static int wp_dh_decode_pki(wp_Dh* dh, unsigned char* data, word32 len)
20922093
word32 idx = 0;
20932094
unsigned char* base = NULL;
20942095

2095-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_pki");
2096+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
20962097

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

21452146
OPENSSL_free(base);
2146-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2147+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2148+
ok);
21472149
return ok;
21482150
}
21492151
#else
@@ -2180,7 +2182,7 @@ static int wp_dh_decode_params(wp_Dh* dh, unsigned char* data, word32 len)
21802182
int rc;
21812183
word32 idx = 0;
21822184

2183-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_decode_params");
2185+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
21842186

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

2193-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2195+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2196+
ok);
21942197
return ok;
21952198
}
21962199

@@ -2821,7 +2824,7 @@ static int wp_dh_type_specific_does_selection(WOLFPROV_CTX* provCtx,
28212824
{
28222825
int ok;
28232826

2824-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_type_specific_does_selection");
2827+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
28252828

28262829
(void)provCtx;
28272830

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

2835-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2838+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2839+
ok);
28362840
return ok;
28372841
}
28382842

@@ -2937,7 +2941,7 @@ static int wp_dh_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
29372941
{
29382942
int ok;
29392943

2940-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_spki_does_selection");
2944+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
29412945

29422946
(void)provCtx;
29432947

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

2951-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2955+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2956+
ok);
29522957
return ok;
29532958
}
29542959

@@ -3048,7 +3053,7 @@ static int wp_dh_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
30483053
{
30493054
int ok;
30503055

3051-
WOLFPROV_ENTER(WP_LOG_DH, "wp_dh_pki_does_selection");
3056+
WOLFPROV_ENTER_SILENT(WP_LOG_DH, WOLFPROV_FUNC_NAME);
30523057

30533058
(void)provCtx;
30543059

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

3062-
WOLFPROV_LEAVE(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3067+
WOLFPROV_LEAVE_SILENT(WP_LOG_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3068+
ok);
30633069
return ok;
30643070
}
30653071

src/wp_ecc_kmgmt.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len)
20062006
int rc;
20072007
word32 oidLen;
20082008

2009-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_params");
2009+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
20102010

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

2050-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2050+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2051+
ok);
20512052
return ok;
20522053
}
20532054

2055+
/**
2056+
* Decode the DER encoded ECC parameters (OID) into the ECC key object.
2057+
*
2058+
* @param [in, out] ecc ECC key object.
2059+
* @param [in] data DER encoding of the parameters (OID).
2060+
* @param [in] len Length, in bytes, of DER encoding.
2061+
* @return 1 on success.
2062+
* @return 0 on failure.
2063+
*/
20542064
static int wp_ecc_decode_x963_pub(wp_Ecc* ecc, unsigned char* data, word32 len)
20552065
{
20562066
int ok = 1;
20572067
int rc;
20582068

2059-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_x963_pub");
2069+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
20602070

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

2074-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2084+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2085+
ok);
20752086
return ok;
20762087
}
20772088

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

2093-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_spki");
2104+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
20942105

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

2113-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2124+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2125+
ok);
21142126
return ok;
21152127
}
21162128

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

2132-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode_pki");
2144+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
21332145

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

2174-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2186+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2187+
ok);
21752188
return ok;
21762189
}
21772190

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

2239-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_decode");
2252+
WOLFPROV_ENTER(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
22402253

22412254
(void)pwCb;
22422255
(void)pwCbArg;
@@ -2921,7 +2934,7 @@ static int wp_ecc_type_specific_does_selection(WOLFPROV_CTX* provCtx,
29212934
{
29222935
int ok;
29232936

2924-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_type_specific_does_selection");
2937+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
29252938

29262939
(void)provCtx;
29272940

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

2935-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2948+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
2949+
ok);
29362950
return ok;
29372951
}
29382952

@@ -3038,7 +3052,7 @@ static int wp_ecc_spki_does_selection(WOLFPROV_CTX* provCtx, int selection)
30383052
{
30393053
int ok;
30403054

3041-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_spki_does_selection");
3055+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
30423056

30433057
(void)provCtx;
30443058

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

3052-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3066+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3067+
ok);
30533068
return ok;
30543069
}
30553070

@@ -3149,7 +3164,7 @@ static int wp_ecc_pki_does_selection(WOLFPROV_CTX* provCtx, int selection)
31493164
{
31503165
int ok;
31513166

3152-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_pki_does_selection");
3167+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
31533168

31543169
(void)provCtx;
31553170

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

3163-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3178+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3179+
ok);
31643180
return ok;
31653181
}
31663182

@@ -3321,7 +3337,7 @@ static int wp_ecc_x9_62_does_selection(WOLFPROV_CTX* provCtx,
33213337
{
33223338
int ok;
33233339

3324-
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_x9_62_does_selection");
3340+
WOLFPROV_ENTER_SILENT(WP_LOG_ECC, WOLFPROV_FUNC_NAME);
33253341

33263342
(void)provCtx;
33273343

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

3336-
WOLFPROV_LEAVE(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
3352+
WOLFPROV_LEAVE_SILENT(WP_LOG_ECC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
3353+
ok);
33373354
return ok;
33383355
}
33393356

0 commit comments

Comments
 (0)