Skip to content

Commit 5db6414

Browse files
committed
Update logging logic
1 parent 935e104 commit 5db6414

File tree

3 files changed

+176
-310
lines changed

3 files changed

+176
-310
lines changed

include/wolfprovider/wp_logging.h

Lines changed: 154 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -114,98 +114,108 @@
114114
* When modifying the enum values, ensure the corresponding strings in the
115115
* wp_logging.c file are updated to match.
116116
*/
117-
enum wolfProv_LogLevels {
118-
WP_LOG_LEVEL_ERROR = 0x0001, /* logs errors */
119-
WP_LOG_LEVEL_ENTER = 0x0002, /* logs function enter*/
120-
WP_LOG_LEVEL_LEAVE = 0x0004, /* logs function leave */
121-
WP_LOG_LEVEL_INFO = 0x0008, /* logs informative messages */
122-
WP_LOG_LEVEL_VERBOSE = 0x0010, /* logs encrypted/decrypted/digested data */
123-
/* To see the return code from wolfssl, you must add WP_LOG_LEVEL_DEBUG to the
124-
* WOLFPROV_LOG_LEVEL_FILTER */
125-
WP_LOG_LEVEL_DEBUG = 0x0020, /* logs debug-level detailed information */
126-
WP_LOG_LEVEL_TRACE = 0x0040, /* logs trace-level ultra-detailed information */
127-
128-
/* default log level when logging is turned on */
129-
WP_LOG_LEVEL_DEFAULT = (WP_LOG_LEVEL_ERROR | WP_LOG_LEVEL_LEAVE | WP_LOG_LEVEL_INFO),
130-
131-
/* log all, including verbose */
132-
WP_LOG_LEVEL_ALL = (WP_LOG_LEVEL_ERROR
133-
| WP_LOG_LEVEL_ENTER
134-
| WP_LOG_LEVEL_LEAVE
135-
| WP_LOG_LEVEL_INFO
136-
| WP_LOG_LEVEL_VERBOSE
137-
| WP_LOG_LEVEL_DEBUG
138-
| WP_LOG_LEVEL_TRACE)
139-
};
140-
141-
enum wolfProv_LogComponents {
142-
/* Legacy component categories */
143-
WP_LOG_COMP_RNG = 0x0001, /* random number generation */
144-
WP_LOG_COMP_DIGEST = 0x0002, /* digest (SHA-1/2/3) */
145-
WP_LOG_COMP_MAC = 0x0004, /* mac functions: HMAC, CMAC */
146-
WP_LOG_COMP_CIPHER = 0x0008, /* cipher (AES, 3DES) */
147-
WP_LOG_COMP_PK = 0x0010, /* public key algorithms (RSA, ECC) */
148-
WP_LOG_COMP_KE = 0x0020, /* key agreement (DH, ECDH) */
149-
WP_LOG_COMP_KDF = 0x0040, /* password base key derivation algorithms */
150-
WP_LOG_COMP_PROVIDER = 0x0080, /* all provider specific logs */
151-
152-
/* Granular algorithm family categories */
153-
WP_LOG_COMP_RSA = 0x0100, /* RSA operations */
154-
WP_LOG_COMP_ECC = 0x0200, /* ECC operations */
155-
WP_LOG_COMP_DH = 0x0400, /* Diffie-Hellman operations */
156-
WP_LOG_COMP_AES = 0x0800, /* AES cipher operations */
157-
WP_LOG_COMP_DES = 0x1000, /* 3DES cipher operations */
158-
WP_LOG_COMP_SHA = 0x2000, /* SHA digest operations */
159-
WP_LOG_COMP_MD5 = 0x4000, /* MD5 digest operations */
160-
WP_LOG_COMP_HMAC = 0x8000, /* HMAC operations */
161-
WP_LOG_COMP_CMAC = 0x10000, /* CMAC operations */
162-
WP_LOG_COMP_HKDF = 0x20000, /* HKDF operations */
163-
WP_LOG_COMP_PBKDF2 = 0x40000, /* PBKDF2 operations */
164-
WP_LOG_COMP_KRB5KDF = 0x80000, /* KRB5KDF operations */
165-
WP_LOG_COMP_DRBG = 0x100000, /* DRBG operations */
166-
WP_LOG_COMP_ECDSA = 0x200000, /* ECDSA signature operations */
167-
WP_LOG_COMP_ECDH = 0x400000, /* ECDH key exchange operations */
168-
WP_LOG_COMP_ED25519 = 0x800000, /* Ed25519 operations */
169-
WP_LOG_COMP_ED448 = 0x1000000, /* Ed448 operations */
170-
WP_LOG_COMP_X25519 = 0x2000000, /* X25519 operations */
171-
WP_LOG_COMP_X448 = 0x4000000, /* X448 operations */
172-
WP_LOG_COMP_QUERY = 0x8000000, /* wolfprov_query operations */
173-
WP_LOG_COMP_TLS1_PRF = 0x10000000, /* TLS1 PRF operations */
174-
175-
/* log all components */
176-
WP_LOG_COMP_ALL = (WP_LOG_COMP_RNG
177-
| WP_LOG_COMP_DIGEST
178-
| WP_LOG_COMP_MAC
179-
| WP_LOG_COMP_CIPHER
180-
| WP_LOG_COMP_PK
181-
| WP_LOG_COMP_KE
182-
| WP_LOG_COMP_KDF
183-
| WP_LOG_COMP_PROVIDER
184-
| WP_LOG_COMP_RSA
185-
| WP_LOG_COMP_ECC
186-
| WP_LOG_COMP_DH
187-
| WP_LOG_COMP_AES
188-
| WP_LOG_COMP_DES
189-
| WP_LOG_COMP_SHA
190-
| WP_LOG_COMP_MD5
191-
| WP_LOG_COMP_HMAC
192-
| WP_LOG_COMP_CMAC
193-
| WP_LOG_COMP_HKDF
194-
| WP_LOG_COMP_PBKDF2
195-
| WP_LOG_COMP_KRB5KDF
196-
| WP_LOG_COMP_DRBG
197-
| WP_LOG_COMP_ECDSA
198-
| WP_LOG_COMP_ECDH
199-
| WP_LOG_COMP_ED25519
200-
| WP_LOG_COMP_ED448
201-
| WP_LOG_COMP_X25519
202-
| WP_LOG_COMP_X448
203-
| WP_LOG_COMP_QUERY
204-
| WP_LOG_COMP_TLS1_PRF),
205-
206-
/* default components logged */
207-
WP_LOG_COMP_DEFAULT = WP_LOG_COMP_ALL
208-
};
117+
/*-------------------------------------------------------------*
118+
* wolfProv_LogLevels
119+
*-------------------------------------------------------------*/
120+
121+
#define WP_LOG_LEVEL_ERROR 0x0001 /* logs errors */
122+
#define WP_LOG_LEVEL_ENTER 0x0002 /* logs function enter */
123+
#define WP_LOG_LEVEL_LEAVE 0x0004 /* logs function leave */
124+
#define WP_LOG_LEVEL_INFO 0x0008 /* logs informative messages */
125+
#define WP_LOG_LEVEL_VERBOSE 0x0010 /* logs encrypted/decrypted/digested data */
126+
/* To see the return code from wolfssl, you must add WP_LOG_LEVEL_DEBUG to the
127+
* WOLFPROV_LOG_LEVEL_FILTER */
128+
#define WP_LOG_LEVEL_DEBUG 0x0020 /* logs debug-level detailed information */
129+
#define WP_LOG_LEVEL_TRACE 0x0040 /* logs trace-level ultra-detailed information */
130+
131+
/* default log level when logging is turned on */
132+
#define WP_LOG_LEVEL_DEFAULT ( \
133+
WP_LOG_LEVEL_ERROR | \
134+
WP_LOG_LEVEL_LEAVE | \
135+
WP_LOG_LEVEL_INFO)
136+
137+
/* log all, including verbose */
138+
#define WP_LOG_LEVEL_ALL ( \
139+
WP_LOG_LEVEL_ERROR | \
140+
WP_LOG_LEVEL_ENTER | \
141+
WP_LOG_LEVEL_LEAVE | \
142+
WP_LOG_LEVEL_INFO | \
143+
WP_LOG_LEVEL_VERBOSE | \
144+
WP_LOG_LEVEL_DEBUG | \
145+
WP_LOG_LEVEL_TRACE )
146+
147+
148+
/*-------------------------------------------------------------*
149+
* wolfProv_LogComponents
150+
*-------------------------------------------------------------*/
151+
152+
/* Legacy component categories */
153+
#define WP_LOG_COMP_RNG 0x0001 /* random number generation */
154+
#define WP_LOG_COMP_DIGEST 0x0002 /* digest (SHA-1/2/3) */
155+
#define WP_LOG_COMP_MAC 0x0004 /* mac functions: HMAC, CMAC */
156+
#define WP_LOG_COMP_CIPHER 0x0008 /* cipher (AES, 3DES) */
157+
#define WP_LOG_COMP_PK 0x0010 /* public key algorithms (RSA, ECC) */
158+
#define WP_LOG_COMP_KE 0x0020 /* key agreement (DH, ECDH) */
159+
#define WP_LOG_COMP_KDF 0x0040 /* password base key derivation algorithms */
160+
#define WP_LOG_COMP_PROVIDER 0x0080 /* all provider specific logs */
161+
162+
/* Granular algorithm family categories */
163+
#define WP_LOG_COMP_RSA 0x0100 /* RSA operations */
164+
#define WP_LOG_COMP_ECC 0x0200 /* ECC operations */
165+
#define WP_LOG_COMP_DH 0x0400 /* Diffie-Hellman operations */
166+
#define WP_LOG_COMP_AES 0x0800 /* AES cipher operations */
167+
#define WP_LOG_COMP_DES 0x1000 /* 3DES cipher operations */
168+
#define WP_LOG_COMP_SHA 0x2000 /* SHA digest operations */
169+
#define WP_LOG_COMP_MD5 0x4000 /* MD5 digest operations */
170+
#define WP_LOG_COMP_HMAC 0x8000 /* HMAC operations */
171+
#define WP_LOG_COMP_CMAC 0x10000 /* CMAC operations */
172+
#define WP_LOG_COMP_HKDF 0x20000 /* HKDF operations */
173+
#define WP_LOG_COMP_PBKDF2 0x40000 /* PBKDF2 operations */
174+
#define WP_LOG_COMP_KRB5KDF 0x80000 /* KRB5KDF operations */
175+
#define WP_LOG_COMP_DRBG 0x100000 /* DRBG operations */
176+
#define WP_LOG_COMP_ECDSA 0x200000 /* ECDSA signature operations */
177+
#define WP_LOG_COMP_ECDH 0x400000 /* ECDH key exchange operations */
178+
#define WP_LOG_COMP_ED25519 0x800000 /* Ed25519 operations */
179+
#define WP_LOG_COMP_ED448 0x1000000 /* Ed448 operations */
180+
#define WP_LOG_COMP_X25519 0x2000000 /* X25519 operations */
181+
#define WP_LOG_COMP_X448 0x4000000 /* X448 operations */
182+
#define WP_LOG_COMP_QUERY 0x8000000 /* wolfprov_query operations */
183+
#define WP_LOG_COMP_TLS1_PRF 0x10000000 /* TLS1 PRF operations */
184+
185+
/* log all components */
186+
#define WP_LOG_COMP_ALL ( \
187+
WP_LOG_COMP_RNG | \
188+
WP_LOG_COMP_DIGEST | \
189+
WP_LOG_COMP_MAC | \
190+
WP_LOG_COMP_CIPHER | \
191+
WP_LOG_COMP_PK | \
192+
WP_LOG_COMP_KE | \
193+
WP_LOG_COMP_KDF | \
194+
WP_LOG_COMP_PROVIDER | \
195+
WP_LOG_COMP_RSA | \
196+
WP_LOG_COMP_ECC | \
197+
WP_LOG_COMP_DH | \
198+
WP_LOG_COMP_AES | \
199+
WP_LOG_COMP_DES | \
200+
WP_LOG_COMP_SHA | \
201+
WP_LOG_COMP_MD5 | \
202+
WP_LOG_COMP_HMAC | \
203+
WP_LOG_COMP_CMAC | \
204+
WP_LOG_COMP_HKDF | \
205+
WP_LOG_COMP_PBKDF2 | \
206+
WP_LOG_COMP_KRB5KDF | \
207+
WP_LOG_COMP_DRBG | \
208+
WP_LOG_COMP_ECDSA | \
209+
WP_LOG_COMP_ECDH | \
210+
WP_LOG_COMP_ED25519 | \
211+
WP_LOG_COMP_ED448 | \
212+
WP_LOG_COMP_X25519 | \
213+
WP_LOG_COMP_X448 | \
214+
WP_LOG_COMP_QUERY | \
215+
WP_LOG_COMP_TLS1_PRF )
216+
217+
/* default components logged */
218+
#define WP_LOG_COMP_DEFAULT WP_LOG_COMP_ALL
209219

210220
/* Manually set the log level */
211221
#ifndef WOLFPROV_LOG_LEVEL_FILTER
@@ -247,36 +257,62 @@ int wolfProv_LogInit(void);
247257
#define WOLFPROV_STRINGIZE_HELPER(x) #x
248258
#define WOLFPROV_STRINGIZE(x) WOLFPROV_STRINGIZE_HELPER(x)
249259

250-
#define WOLFPROV_ERROR(type, err) \
251-
WOLFPROV_ERROR_LINE(type, err, __FILE__, __LINE__)
252-
#define WOLFPROV_ERROR_MSG(type, msg) \
253-
WOLFPROV_ERROR_MSG_LINE(type, msg, __FILE__, __LINE__)
254-
#define WOLFPROV_ERROR_FUNC(type, funcName, ret) \
255-
WOLFPROV_ERROR_FUNC_LINE(type, funcName, ret, __FILE__, __LINE__)
256-
#define WOLFPROV_ERROR_FUNC_NULL(type, funcName, ret) \
257-
WOLFPROV_ERROR_FUNC_NULL_LINE(type, funcName, ret, __FILE__, __LINE__)
258-
void WOLFPROV_ENTER(int type, const char* msg);
259-
void WOLFPROV_ENTER_SILENT(int type, const char* msg);
260-
#define WOLFPROV_LEAVE(type, msg, ret) \
261-
WOLFPROV_LEAVE_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
262-
void WOLFPROV_LEAVE_EX(int type, const char* func, const char* msg, int ret);
263-
#define WOLFPROV_LEAVE_SILENT(type, msg, ret) \
264-
WOLFPROV_LEAVE_SILENT_EX(type, WOLFPROV_FUNC_NAME, msg, ret)
265-
void WOLFPROV_LEAVE_SILENT_EX(int type, const char* func, const char* msg,
260+
void wolfprovider_msg(int component, int logLevel, const char *fmt, ...);
261+
262+
#define WOLFPROV_MSG_EX(component, level, fmt, ...) \
263+
do { if (WOLFPROV_COMPILE_TIME_CHECK(component, level)) \
264+
wolfprovider_msg(component, level, fmt, ##__VA_ARGS__); \
265+
} while(0)
266+
267+
#define WOLFPROV_MSG(component, fmt, ...) \
268+
WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
269+
270+
#define WOLFPROV_ERROR(component, err) \
271+
WOLFPROV_ERROR_LINE(component, err, __FILE__, __LINE__)
272+
#define WOLFPROV_ERROR_MSG(component, msg) \
273+
WOLFPROV_ERROR_MSG_LINE(component, msg, __FILE__, __LINE__)
274+
#define WOLFPROV_ERROR_FUNC(component, funcName, ret) \
275+
WOLFPROV_ERROR_FUNC_LINE(component, funcName, ret, __FILE__, __LINE__)
276+
#define WOLFPROV_ERROR_FUNC_NULL(component, funcName, ret) \
277+
WOLFPROV_ERROR_FUNC_NULL_LINE(component, funcName, ret, __FILE__, __LINE__)
278+
279+
#define WOLFPROV_LEAVE(component, msg, ret) \
280+
WOLFPROV_LEAVE_EX(component, WOLFPROV_FUNC_NAME, msg, ret)
281+
void WOLFPROV_LEAVE_EX(int component, const char* func, const char* msg, int ret);
282+
#define WOLFPROV_LEAVE_SILENT(component, msg, ret) \
283+
WOLFPROV_LEAVE_SILENT_EX(component, WOLFPROV_FUNC_NAME, msg, ret)
284+
void WOLFPROV_LEAVE_SILENT_EX(int component, const char* func, const char* msg,
266285
int ret);
267-
void WOLFPROV_MSG(int type, const char* fmt, ...);
268-
void WOLFPROV_MSG_VERBOSE(int type, const char* fmt, ...);
269-
void WOLFPROV_MSG_DEBUG(int type, const char* fmt, ...);
270-
void WOLFPROV_MSG_DEBUG_RETCODE(int type, const char* func_name, int rc);
271-
void WOLFPROV_MSG_TRACE(int type, const char* fmt, ...);
272-
void WOLFPROV_ERROR_LINE(int type, int err, const char* file, int line);
273-
void WOLFPROV_ERROR_MSG_LINE(int type, const char* msg, const char* file,
286+
287+
288+
#define WOLFPROV_ENTER(component, msg) \
289+
WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_ENTER, "wolfProv Entering %s", msg)
290+
#ifdef WOLFPROV_LEAVE_SILENT_MODE
291+
#define WOLFPROV_ENTER_SILENT(component, msg) \
292+
WOLFPROV_ENTER_SILENT(component, msg)
293+
#else
294+
#define WOLFPROV_ENTER_SILENT(component, msg) \
295+
WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_ENTER, "wolfProv Entering [leaving silently] %s", msg)
296+
#endif
297+
298+
#define WOLFPROV_MSG_VERBOSE(component, fmt, ...) \
299+
WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__)
300+
#define WOLFPROV_MSG_DEBUG(component, fmt, ...) \
301+
WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
302+
#define WOLFPROV_MSG_DEBUG_RETCODE(component, func_name, rc) \
303+
WOLFPROV_MSG_DEBUG(component, "%s failed with rc=%d", func_name, rc)
304+
#define WOLFPROV_MSG_TRACE(component, fmt, ...) \
305+
WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_TRACE, fmt, ##__VA_ARGS__)
306+
307+
308+
void WOLFPROV_ERROR_LINE(int component, int err, const char* file, int line);
309+
void WOLFPROV_ERROR_MSG_LINE(int component, const char* msg, const char* file,
274310
int line);
275-
void WOLFPROV_ERROR_FUNC_LINE(int type, const char* funcName, int ret,
311+
void WOLFPROV_ERROR_FUNC_LINE(int component, const char* funcName, int ret,
276312
const char* file, int line);
277-
void WOLFPROV_ERROR_FUNC_NULL_LINE(int type, const char* funcName,
313+
void WOLFPROV_ERROR_FUNC_NULL_LINE(int component, const char* funcName,
278314
const void *ret, const char* file, int line);
279-
void WOLFPROV_BUFFER(int type, const unsigned char* buffer,
315+
void WOLFPROV_BUFFER(int component, const unsigned char* buffer,
280316
unsigned int length);
281317

282318
#else /* WOLFPROV_DEBUG */
@@ -299,4 +335,3 @@ void WOLFPROV_BUFFER(int type, const unsigned char* buffer,
299335
#endif /* WOLFPROV_DEBUG */
300336

301337
#endif /* WP_LOGGING_H */
302-

scripts/cmd_test/do-cmd-tests.sh

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,9 @@ REPO_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
2525
UTILS_DIR="${REPO_ROOT}/scripts"
2626

2727
source "${SCRIPT_DIR}/cmd-test-common.sh"
28-
29-
# If OPENSSL_BIN is not set, assume we are using a local build
30-
if [ -z "${OPENSSL_BIN:-}" ]; then
31-
# Check if the install directories exist
32-
if [ ! -d "${REPO_ROOT}/openssl-install" ] ||
33-
[ ! -d "${REPO_ROOT}/wolfssl-install" ]; then
34-
echo "[FAIL] OpenSSL or wolfSSL install directories not found"
35-
echo "Please set OPENSSL_BIN or run build-wolfprovider.sh first"
36-
exit 1
37-
fi
38-
39-
# Setup the environment for a local build
40-
source "${REPO_ROOT}/scripts/env-setup"
41-
else
42-
# We are using a user-provided OpenSSL binary, manually set the test
43-
# environment variables rather than using env-setup.
44-
# Find the location of the wolfProvider modules
45-
if [ -z "${WOLFPROV_PATH:-}" ]; then
46-
export WOLFPROV_PATH=$(find /usr/lib /usr/local/lib -type d -name ossl-modules 2>/dev/null | head -n 1)
47-
fi
48-
# Set the path to the wolfProvider config file
49-
if [ -z "${WOLFPROV_CONFIG:-}" ]; then
50-
if [ "${WOLFSSL_ISFIPS:-0}" = "1" ]; then
51-
export WOLFPROV_CONFIG="${REPO_ROOT}/provider-fips.conf"
52-
else
53-
export WOLFPROV_CONFIG="${REPO_ROOT}/provider.conf"
54-
fi
55-
fi
56-
fi
28+
cmd_test_env_setup
5729

5830
echo "=== Running wolfProvider Command-Line Tests ==="
59-
echo "Using OPENSSL_BIN: ${OPENSSL_BIN}"
60-
echo "Using WOLFPROV_PATH: ${WOLFPROV_PATH}"
61-
echo "Using WOLFPROV_CONFIG: ${WOLFPROV_CONFIG}"
6231

6332
# Ensure we can switch providers before proceeding
6433
use_default_provider

0 commit comments

Comments
 (0)