Skip to content

Commit dc34ae2

Browse files
authored
Merge pull request #259 from aidangarske/revamp-debug
Revamp Debug Selection and Output in wolfProvider
2 parents 0de5133 + d5710e6 commit dc34ae2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1480
-391
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ It will retrieve the dependencies and compile them as necessary. To use other th
6262
OPENSSL_TAG=openssl-3.5.0 WOLFSSL_TAG=v5.8.0-stable WOLFPROV_DEBUG=1 scripts/build-wolfprovider.sh
6363
```
6464

65+
Or you can set them with variables like so:
66+
67+
```
68+
./scripts/build-wolfprovider.sh --debug --openssl-ver=openssl-3.5.0 --wolfssl-ver=v5.8.0-stable
69+
```
70+
6571
To clean the build, use the following:
6672
```
6773
./scripts/build-wolfprovider.sh --clean
@@ -153,3 +159,8 @@ To run the command tests:
153159
To run the cipher suite testing:
154160
* `./scripts/test-wp-cs.sh`
155161

162+
163+
## Debugging
164+
165+
To enable wolfProvider debug logging, build with `--debug` which enables exit messages, error messages, and informational messages. If you want to filter logging a certain way or increase detail level, set `WOLFPROV_LOG_LEVEL_FILTER` and `WOLFPROV_LOG_COMPONENTS_FILTER` in `include/wolfprovider/wp_logging.h` as needed. See comments in that file for examples.
166+

include/wolfprovider/wp_logging.h

Lines changed: 120 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,37 +67,91 @@
6767
* WOLFPROV_LOG_PRINTF Define to Use printf instead of fprintf (to stderr)
6868
* for logs. Not applicable if using WOLFPROV_USER_LOG
6969
* or custom logging callback.
70+
*
71+
* COMPILE-TIME MACRO CONFIGURATIONS:
72+
* Define these macros in this header to control logging at compile time:
73+
* NOTE: wolfProvider needs to be built with --debug to enable the logging first
74+
* before we can set the log level and components.
75+
*
76+
* WOLFPROV_LOG_LEVEL_FILTER Sets the log level. Use WP_LOG_* constants from enum below.
77+
* Examples:
78+
* - WP_LOG_ERROR (only errors)
79+
* - (WP_LOG_ERROR | WP_LOG_ENTER) (errors and function enter)
80+
* - (WP_LOG_ERROR | WP_LOG_LEAVE) (errors and function leave)
81+
* - (WP_LOG_LEVEL_ALL) (all levels)
82+
*
83+
* WOLFPROV_LOG_COMPONENTS_FILTER Set component bitmask to filter specific
84+
* algorithms. Use WP_LOG_* constants from enum below.
85+
* Examples:
86+
* - WP_LOG_HKDF (HKDF only)
87+
* - (WP_LOG_AES | WP_LOG_DES) (ciphers only)
88+
* - (WP_LOG_ECC | WP_LOG_RSA | WP_LOG_HKDF) (multiple algorithms)
89+
* - WP_LOG_CIPHER (all cipher operations)
90+
*
91+
* EXAMPLES:
92+
* #define WOLFPROV_LOG_LEVEL_FILTER (WP_LOG_ERROR | WP_LOG_ENTER | WP_LOG_LEAVE | WP_LOG_INFO)
93+
* #define WOLFPROV_LOG_COMPONENTS_FILTER WP_LOG_HKDF
94+
* // Shows level (ERROR + ENTER/LEAVE + INFO) for HKDF operations only
95+
*
96+
* #define WOLFPROV_LOG_LEVEL_FILTER (WP_LOG_LEVEL_ALL)
97+
* #define WOLFPROV_LOG_COMPONENTS_FILTER (WP_LOG_ECC | WP_LOG_RSA | WP_LOG_HKDF)
98+
* // Shows level (ERROR + ENTER/LEAVE + INFO + VERBOSE + DEBUG + TRACE) for ECC, RSA, and HKDF only
7099
*/
71100
enum wolfProv_LogType {
72-
WP_LOG_ERROR = 0x0001, /* logs errors */
73-
WP_LOG_ENTER = 0x0002, /* logs function enter*/
74-
WP_LOG_LEAVE = 0x0004, /* logs function leave */
75-
WP_LOG_INFO = 0x0008, /* logs informative messages */
76-
WP_LOG_VERBOSE = 0x0010, /* logs encrypted/decrypted/digested data */
77-
78-
/* default log level when logging is turned on, all but verbose */
79-
WP_LOG_LEVEL_DEFAULT = (WP_LOG_ERROR
80-
| WP_LOG_ENTER
81-
| WP_LOG_LEAVE
82-
| WP_LOG_INFO),
101+
WP_LOG_ERROR = 0x0001, /* logs errors */
102+
WP_LOG_ENTER = 0x0002, /* logs function enter*/
103+
WP_LOG_LEAVE = 0x0004, /* logs function leave */
104+
WP_LOG_INFO = 0x0008, /* logs informative messages */
105+
WP_LOG_VERBOSE = 0x0010, /* logs encrypted/decrypted/digested data */
106+
WP_LOG_DEBUG = 0x0020, /* logs debug-level detailed information */
107+
WP_LOG_TRACE = 0x0040, /* logs trace-level ultra-detailed information */
108+
109+
/* default log level when logging is turned on */
110+
WP_LOG_LEVEL_DEFAULT = (WP_LOG_ERROR | WP_LOG_LEAVE | WP_LOG_INFO),
83111

84112
/* log all, including verbose */
85113
WP_LOG_LEVEL_ALL = (WP_LOG_ERROR
86114
| WP_LOG_ENTER
87115
| WP_LOG_LEAVE
88116
| WP_LOG_INFO
89-
| WP_LOG_VERBOSE)
117+
| WP_LOG_VERBOSE
118+
| WP_LOG_DEBUG
119+
| WP_LOG_TRACE)
90120
};
91121

92122
enum wolfProv_LogComponents {
93-
WP_LOG_RNG = 0x0001, /* random number generation */
94-
WP_LOG_DIGEST = 0x0002, /* digest (SHA-1/2/3) */
95-
WP_LOG_MAC = 0x0004, /* mac functions: HMAC, CMAC */
96-
WP_LOG_CIPHER = 0x0008, /* cipher (AES, 3DES) */
97-
WP_LOG_PK = 0x0010, /* public key algorithms (RSA, ECC) */
98-
WP_LOG_KE = 0x0020, /* key agreement (DH, ECDH) */
99-
WP_LOG_KDF = 0x0040, /* password base key derivation algorithms */
100-
WP_LOG_PROVIDER = 0x0080, /* all provider specific logs */
123+
/* Legacy component categories */
124+
WP_LOG_RNG = 0x0001, /* random number generation */
125+
WP_LOG_DIGEST = 0x0002, /* digest (SHA-1/2/3) */
126+
WP_LOG_MAC = 0x0004, /* mac functions: HMAC, CMAC */
127+
WP_LOG_CIPHER = 0x0008, /* cipher (AES, 3DES) */
128+
WP_LOG_PK = 0x0010, /* public key algorithms (RSA, ECC) */
129+
WP_LOG_KE = 0x0020, /* key agreement (DH, ECDH) */
130+
WP_LOG_KDF = 0x0040, /* password base key derivation algorithms */
131+
WP_LOG_PROVIDER = 0x0080, /* all provider specific logs */
132+
133+
/* Granular algorithm family categories */
134+
WP_LOG_RSA = 0x0001, /* RSA operations */
135+
WP_LOG_ECC = 0x0002, /* ECC operations */
136+
WP_LOG_DH = 0x0004, /* Diffie-Hellman operations */
137+
WP_LOG_AES = 0x0008, /* AES cipher operations */
138+
WP_LOG_DES = 0x0010, /* 3DES cipher operations */
139+
WP_LOG_SHA = 0x0020, /* SHA digest operations */
140+
WP_LOG_MD5 = 0x0040, /* MD5 digest operations */
141+
WP_LOG_HMAC = 0x0080, /* HMAC operations */
142+
WP_LOG_CMAC = 0x0100, /* CMAC operations */
143+
WP_LOG_HKDF = 0x0200, /* HKDF operations */
144+
WP_LOG_PBKDF2 = 0x0400, /* PBKDF2 operations */
145+
WP_LOG_KRB5KDF = 0x0800, /* KRB5KDF operations */
146+
WP_LOG_DRBG = 0x1000, /* DRBG operations */
147+
WP_LOG_ECDSA = 0x2000, /* ECDSA signature operations */
148+
WP_LOG_ECDH = 0x4000, /* ECDH key exchange operations */
149+
WP_LOG_ED25519 = 0x8000, /* Ed25519 operations */
150+
WP_LOG_ED448 = 0x10000, /* Ed448 operations */
151+
WP_LOG_X25519 = 0x20000, /* X25519 operations */
152+
WP_LOG_X448 = 0x40000, /* X448 operations */
153+
WP_LOG_QUERY = 0x80000, /* wolfprov_query operations */
154+
WP_LOG_TLS1_PRF = 0x100000, /* TLS1 PRF operations */
101155

102156
/* log all compoenents */
103157
WP_LOG_COMPONENTS_ALL = (WP_LOG_RNG
@@ -107,12 +161,52 @@ enum wolfProv_LogComponents {
107161
| WP_LOG_PK
108162
| WP_LOG_KE
109163
| WP_LOG_KDF
110-
| WP_LOG_PROVIDER),
164+
| WP_LOG_PROVIDER
165+
| WP_LOG_RSA
166+
| WP_LOG_ECC
167+
| WP_LOG_DH
168+
| WP_LOG_AES
169+
| WP_LOG_DES
170+
| WP_LOG_SHA
171+
| WP_LOG_MD5
172+
| WP_LOG_HMAC
173+
| WP_LOG_CMAC
174+
| WP_LOG_HKDF
175+
| WP_LOG_PBKDF2
176+
| WP_LOG_KRB5KDF
177+
| WP_LOG_DRBG
178+
| WP_LOG_ECDSA
179+
| WP_LOG_ECDH
180+
| WP_LOG_ED25519
181+
| WP_LOG_ED448
182+
| WP_LOG_X25519
183+
| WP_LOG_X448
184+
| WP_LOG_QUERY
185+
| WP_LOG_TLS1_PRF),
111186

112187
/* default compoenents logged */
113188
WP_LOG_COMPONENTS_DEFAULT = WP_LOG_COMPONENTS_ALL
114189
};
115190

191+
/* Manually set the log level */
192+
#ifndef WOLFPROV_LOG_LEVEL_FILTER
193+
#define WOLFPROV_LOG_LEVEL_FILTER WP_LOG_LEVEL_DEFAULT
194+
#endif
195+
196+
/* Manually set the components */
197+
#ifndef WOLFPROV_LOG_COMPONENTS_FILTER
198+
#define WOLFPROV_LOG_COMPONENTS_FILTER WP_LOG_COMPONENTS_DEFAULT
199+
#endif
200+
201+
/* Conditional logging macro that checks compile-time configuration */
202+
#ifdef WOLFPROV_DEBUG
203+
#define WOLFPROV_COMPILE_TIME_CHECK(component, level) \
204+
((WOLFPROV_LOG_LEVEL_FILTER & (level)) && \
205+
(WOLFPROV_LOG_COMPONENTS_FILTER & (component)))
206+
#else
207+
#define WOLFPROV_COMPILE_TIME_CHECK(component, level) 0
208+
#endif
209+
116210
typedef void (*wolfProv_Logging_cb)(const int logLevel, const int component,
117211
const char *const logMessage);
118212
int wolfProv_SetLoggingCb(wolfProv_Logging_cb logF);
@@ -156,6 +250,8 @@ void WOLFPROV_ENTER(int type, const char* msg);
156250
void WOLFPROV_LEAVE_EX(int type, const char* func, const char* msg, int ret);
157251
void WOLFPROV_MSG(int type, const char* fmt, ...);
158252
void WOLFPROV_MSG_VERBOSE(int type, const char* fmt, ...);
253+
void WOLFPROV_MSG_DEBUG(int type, const char* fmt, ...);
254+
void WOLFPROV_MSG_TRACE(int type, const char* fmt, ...);
159255
void WOLFPROV_ERROR_LINE(int type, int err, const char* file, int line);
160256
void WOLFPROV_ERROR_MSG_LINE(int type, const char* msg, const char* file,
161257
int line);
@@ -166,12 +262,14 @@ void WOLFPROV_ERROR_FUNC_NULL_LINE(int type, const char* funcName,
166262
void WOLFPROV_BUFFER(int type, const unsigned char* buffer,
167263
unsigned int length);
168264

169-
#else
265+
#else /* WOLFPROV_DEBUG */
170266

171267
#define WOLFPROV_ENTER(t, m)
172268
#define WOLFPROV_LEAVE(t, m, r)
173269
#define WOLFPROV_MSG(t, m, ...)
174270
#define WOLFPROV_MSG_VERBOSE(t, m, ...)
271+
#define WOLFPROV_MSG_DEBUG(t, m, ...)
272+
#define WOLFPROV_MSG_TRACE(t, m, ...)
175273
#define WOLFPROV_ERROR(t, e)
176274
#define WOLFPROV_ERROR_MSG(t, e)
177275
#define WOLFPROV_ERROR_FUNC(t, f, r)

0 commit comments

Comments
 (0)