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
7 changes: 5 additions & 2 deletions include/wolfprovider/wp_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
* WOLFPROV_LOG_PRINTF Define to Use printf instead of fprintf (to stderr)
* for logs. Not applicable if using WOLFPROV_USER_LOG
* or custom logging callback.
* WOLFPROV_LOG_FILE Define to specify a file path for debug output instead
* of stderr. This is typically set via --debug-log=FILE
* build script argument.
*
* COMPILE-TIME MACRO CONFIGURATIONS:
* Define these macros in this header to control logging at compile time:
Expand Down Expand Up @@ -166,7 +169,7 @@ enum wolfProv_LogComponents {
WP_LOG_QUERY = 0x80000, /* wolfprov_query operations */
WP_LOG_TLS1_PRF = 0x100000, /* TLS1 PRF operations */

/* log all compoenents */
/* log all components */
WP_LOG_COMPONENTS_ALL = (WP_LOG_RNG
| WP_LOG_DIGEST
| WP_LOG_MAC
Expand Down Expand Up @@ -197,7 +200,7 @@ enum wolfProv_LogComponents {
| WP_LOG_QUERY
| WP_LOG_TLS1_PRF),

/* default compoenents logged */
/* default components logged */
WP_LOG_COMPONENTS_DEFAULT = WP_LOG_COMPONENTS_ALL
};

Expand Down
17 changes: 16 additions & 1 deletion scripts/build-wolfprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ show_help() {
echo " --help, -help, -h Display this help menu and exit"
echo " --clean Run make clean in OpenSSL, wolfSSL, and wolfProvider"
echo " --distclean Remove source and install directories of OpenSSL, wolfSSL, and wolfProvider"
echo " --debug Builds OpenSSL, wolfSSL, and WolfProvider with debugging enabled. This is the same as setting WOLFPROV_DEBUG=1"
echo " --debug Builds OpenSSL, wolfSSL, and WolfProvider in debug mode with logging enabled. This is the same as setting WOLFPROV_DEBUG=1"
echo " --debug-log=FILE Force all wolfProvider runtime output to specified log file instead of stderr/stdout (FILE = path to log file you want to use). Logs are appended to existing file."
echo " --debug-asn-template Enable debug information for asn within wolfSSL"
echo " --disable-err-trace No debug trace messages from library errors in wolfSSL"
echo " --openssl-ver=VER Which version of OpenSSL to clone"
Expand All @@ -33,6 +34,7 @@ show_help() {
echo " WOLFPROV_CLEAN If set to 1, run make clean in OpenSSL, wolfSSL, and wolfProvider"
echo " WOLFPROV_DISTCLEAN If set to 1, remove the source and install directories of OpenSSL, wolfSSL, and wolfProvider"
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
echo " WOLFPROV_LOG_FILE Path to log file for wolfProvider debug output (alternative to stderr)"
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."
Expand All @@ -57,6 +59,14 @@ for arg in "$@"; do
--debug)
WOLFPROV_DEBUG=1
;;
--debug-log=*)
IFS='=' read -r trash log_file <<< "$arg"
if [ -z "$log_file" ]; then
echo "No file path given for --debug-log"
args_wrong+="$arg, "
fi
WOLFPROV_LOG_FILE="$log_file"
;;
--debug-asn-template)
WOLFSSL_DEBUG_ASN_TEMPLATE=1
;;
Expand Down Expand Up @@ -130,6 +140,11 @@ if [ "${WOLFPROV_LEAVE_SILENT}" = "1" ] && [ -z "$WOLFPROV_DEBUG" ] && [ -z "$de
exit 1
fi

if [ -n "$WOLFPROV_LOG_FILE" ] && [ -z "$WOLFPROV_DEBUG" ]; then
echo "Error: --debug-log requires --debug to be set."
exit 1
fi

if [ -n "$build_debian" ]; then
echo "Building Debian package..."
WOLFSSL_ISFIPS=${WOLFSSL_ISFIPS:-0} WOLFPROV_DEBUG=${WOLFPROV_DEBUG:-0} ./scripts/build-debian.sh
Expand Down
2 changes: 2 additions & 0 deletions scripts/utils-openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ install_openssl() {
}

init_openssl() {
WOLFPROV_BUILD_DEBIAN=${WOLFPROV_BUILD_DEBIAN:-0}

if [ $WOLFPROV_BUILD_DEBIAN -eq 1 ]; then
install_openssl_deb
else
Expand Down
4 changes: 4 additions & 0 deletions scripts/utils-wolfprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ install_wolfprov() {
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LEAVE_SILENT_MODE"
fi

if [ -n "${WOLFPROV_LOG_FILE}" ]; then
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LOG_FILE=\\\"${WOLFPROV_LOG_FILE}\\\""
fi

./configure ${WOLFPROV_CONFIG_OPTS} CFLAGS="${WOLFPROV_CONFIG_CFLAGS}" >>$LOG_FILE 2>&1
RET=$?
if [ $RET != 0 ]; then
Expand Down
33 changes: 31 additions & 2 deletions src/wp_logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ static int providerLogComponents = WP_LOG_COMPONENTS_ALL;

#endif /* WOLFPROV_DEBUG */


/**
* Registers wolfProv logging callback.
* Callback will be used by wolfProv for debug/log messages.
Expand Down Expand Up @@ -173,8 +172,38 @@ static void wolfprovider_log(const int logLevel, const int component,
WOLFPROV_USER_LOG(logMessage);
#elif defined(WOLFPROV_LOG_PRINTF)
printf("%s\n", logMessage);
#elif defined(WOLFPROV_LOG_FILE)
{
/* Persistent file handle for logging to file */
static XFILE* logFileHandle = NULL;
/* Flag to track if we've already reported file open failure to avoid spam */
static int logFileErrorReported = 0;

if (logFileHandle == NULL) {
logFileHandle = XFOPEN(WOLFPROV_LOG_FILE, "a");
if (logFileHandle) {
XFPRINTF(stderr, "wolfProvider: Using log file %s\n", WOLFPROV_LOG_FILE);
fflush(stderr);
}
else {
/* Fall back to stderr when file open fails */
logFileHandle = stderr;
/* Only report file error once to avoid spam */
if (!logFileErrorReported) {
logFileErrorReported = 1;
XFPRINTF(stderr, "wolfProvider: Log file not open: %s, "
"falling back to stderr\n",
WOLFPROV_LOG_FILE);
}
}
}

XFWRITE(logMessage, strlen(logMessage), 1, logFileHandle);
XFWRITE("\n", 1, 1, logFileHandle);
XFFLUSH(logFileHandle);
}
#else
fprintf(stderr, "%s\n", logMessage);
XFPRINTF(stderr, "%s\n", logMessage);
#endif
}
}
Expand Down
Loading