diff --git a/src/ssl.c b/src/ssl.c index b9cfca03c..b8501b434 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -17686,6 +17686,7 @@ cleanup: { WOLFSSL_ENTER("wolfSSL_ERR_get_error"); +#ifdef WOLFSSL_HAVE_ERROR_QUEUE #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) { unsigned long ret = wolfSSL_ERR_peek_error_line_data(NULL, NULL, @@ -17693,7 +17694,7 @@ cleanup: wc_RemoveErrorNode(-1); return ret; } -#elif (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) +#else { int ret = wc_PullErrorNode(NULL, NULL, NULL); @@ -17709,12 +17710,13 @@ cleanup: return (unsigned long)ret; } +#endif #else return (unsigned long)(0 - NOT_COMPILED_IN); #endif } -#if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) +#ifdef WOLFSSL_HAVE_ERROR_QUEUE #ifndef NO_BIO /* print out and clear all errors */ void wolfSSL_ERR_print_errors(WOLFSSL_BIO* bio) @@ -17747,7 +17749,7 @@ cleanup: } } #endif /* !NO_BIO */ -#endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */ +#endif /* WOLFSSL_HAVE_ERROR_QUEUE */ #endif /* OPENSSL_EXTRA || HAVE_WEBSERVER */ @@ -19475,9 +19477,7 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, void wolfSSL_ERR_clear_error(void) { WOLFSSL_ENTER("wolfSSL_ERR_clear_error"); - -#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_NGINX) || \ - defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) +#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) wc_ClearErrorNodes(); #endif } @@ -19951,7 +19951,7 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, */ unsigned long wolfSSL_ERR_get_error_line(const char** file, int* line) { - #ifdef DEBUG_WOLFSSL + #ifdef WOLFSSL_HAVE_ERROR_QUEUE int ret = wc_PullErrorNode(file, NULL, line); if (ret < 0) { if (ret == BAD_STATE_E) return 0; /* no errors in queue */ @@ -20057,9 +20057,10 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, unsigned long wolfSSL_ERR_get_error_line_data(const char** file, int* line, const char** data, int *flags) { +#ifdef WOLFSSL_HAVE_ERROR_QUEUE int ret; - WOLFSSL_STUB("wolfSSL_ERR_get_error_line_data"); + WOLFSSL_ENTER("wolfSSL_ERR_get_error_line_data"); if (flags != NULL) { if ((*flags & ERR_TXT_STRING) == ERR_TXT_STRING) { @@ -20090,6 +20091,15 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, } return (unsigned long)ret; +#else + WOLFSSL_ENTER("wolfSSL_ERR_get_error_line_data"); + WOLFSSL_MSG("Error queue turned off, can not get error line"); + (void)file; + (void)line; + (void)data; + (void)flags; + return 0; +#endif } #endif /* OPENSSL_EXTRA */ @@ -44382,10 +44392,8 @@ err: } if ((l = wolfSSL_BIO_get_len(bio)) <= 0) { - #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) /* No certificate in buffer */ WOLFSSL_ERROR(ASN_NO_PEM_HEADER); - #endif return WOLFSSL_FAILURE; } @@ -44632,6 +44640,7 @@ err: } } else { +#ifdef WOLFSSL_HAVE_ERROR_QUEUE int err = (int)wolfSSL_ERR_peek_last_error(); if (ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { @@ -44644,6 +44653,13 @@ err: */ wc_RemoveErrorNode(-1); } +#else + if (wolfSSL_sk_X509_INFO_num(localSk) > 0) { + WOLFSSL_MSG("At least one X509_INFO object on stack." + "Assuming error means EOF or no more PEM" + "headers found."); + } +#endif else { ret = WOLFSSL_FAILURE; } @@ -45921,8 +45937,7 @@ unsigned long wolfSSL_ERR_peek_last_error_line(const char **file, int *line) (void)line; (void)file; -#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(DEBUG_WOLFSSL) || \ - defined(WOLFSSL_HAPROXY) +#ifdef WOLFSSL_HAVE_ERROR_QUEUE { int ret; @@ -48283,7 +48298,7 @@ unsigned long wolfSSL_ERR_peek_last_error(void) { WOLFSSL_ENTER("wolfSSL_ERR_peek_last_error"); -#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_NGINX) +#ifdef WOLFSSL_HAVE_ERROR_QUEUE { int ret; @@ -49361,9 +49376,7 @@ unsigned long wolfSSL_ERR_peek_error_line_data(const char **file, int *line, *flags = 0; } -#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \ - defined(WOLFSSL_OPENSSH) || defined(WOLFSSL_HAPROXY) || \ - defined(WOLFSSL_MYSQL_COMPATIBLE) +#ifdef WOLFSSL_HAVE_ERROR_QUEUE { int ret = 0; diff --git a/wolfcrypt/src/logging.c b/wolfcrypt/src/logging.c index 31b321256..260c40e10 100644 --- a/wolfcrypt/src/logging.c +++ b/wolfcrypt/src/logging.c @@ -456,8 +456,7 @@ WOLFSSL_API int WOLFSSL_IS_DEBUG_ON(void) defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ defined(OPENSSL_EXTRA) -#if (defined(OPENSSL_EXTRA) && !defined(_WIN32) && !defined(NO_ERROR_QUEUE)) \ - || defined(DEBUG_WOLFSSL_VERBOSE) +#ifdef WOLFSSL_HAVE_ERROR_QUEUE void WOLFSSL_ERROR_LINE(int error, const char* func, unsigned int line, const char* file, void* usrCtx) #else @@ -470,8 +469,7 @@ void WOLFSSL_ERROR(int error) { char buffer[WOLFSSL_MAX_ERROR_SZ]; - #if (defined(OPENSSL_EXTRA) && !defined(_WIN32) && \ - !defined(NO_ERROR_QUEUE)) || defined(DEBUG_WOLFSSL_VERBOSE) + #ifdef WOLFSSL_HAVE_ERROR_QUEUE (void)usrCtx; /* a user ctx for future flexibility */ (void)func; @@ -577,6 +575,7 @@ int wc_LoggingCleanup(void) int wc_PeekErrorNode(int idx, const char **file, const char **reason, int *line) { +#ifdef WOLFSSL_HAVE_ERROR_QUEUE struct wc_error_queue* err; if (wc_LockMutex(&debug_mutex) != 0) { @@ -622,6 +621,14 @@ int wc_PeekErrorNode(int idx, const char **file, const char **reason, wc_UnLockMutex(&debug_mutex); return err->value; +#else + (void)idx; + (void)file; + (void)reason; + (void)line; + WOLFSSL_MSG("Error queue turned off, can not peak nodes"); + return NOT_COMPILED_IN; +#endif } @@ -637,6 +644,7 @@ int wc_PeekErrorNode(int idx, const char **file, const char **reason, */ int wc_PullErrorNode(const char **file, const char **reason, int *line) { +#ifdef WOLFSSL_HAVE_ERROR_QUEUE struct wc_error_queue* err; int value; @@ -669,6 +677,13 @@ int wc_PullErrorNode(const char **file, const char **reason, int *line) wc_UnLockMutex(&debug_mutex); return value; +#else + (void)file; + (void)reason; + (void)line; + WOLFSSL_MSG("Error queue turned off, can not pull nodes"); + return NOT_COMPILED_IN; +#endif } @@ -677,13 +692,7 @@ int wc_PullErrorNode(const char **file, const char **reason, int *line) * function. debug_mutex should be locked before a call to this function. */ int wc_AddErrorNode(int error, int line, char* buf, char* file) { -#if defined(NO_ERROR_QUEUE) - (void)error; - (void)line; - (void)buf; - (void)file; - WOLFSSL_MSG("Error queue turned off, can not add nodes"); -#else +#ifdef WOLFSSL_HAVE_ERROR_QUEUE struct wc_error_queue* err; if (wc_error_queue_count >= ERROR_QUEUE_MAX) { @@ -757,8 +766,15 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file) } wc_error_queue_count++; } -#endif return 0; +#else + (void)error; + (void)line; + (void)buf; + (void)file; + WOLFSSL_MSG("Error queue turned off, can not add nodes"); + return NOT_COMPILED_IN; +#endif } /* Removes the error node at the specified index. @@ -767,6 +783,7 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file) */ void wc_RemoveErrorNode(int idx) { +#ifdef WOLFSSL_HAVE_ERROR_QUEUE struct wc_error_queue* current; if (wc_LockMutex(&debug_mutex) != 0) { @@ -797,6 +814,10 @@ void wc_RemoveErrorNode(int idx) } wc_UnLockMutex(&debug_mutex); +#else + (void)idx; + WOLFSSL_MSG("Error queue turned off, can not remove nodes"); +#endif } @@ -804,9 +825,7 @@ void wc_RemoveErrorNode(int idx) */ void wc_ClearErrorNodes(void) { -#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_NGINX) || \ - defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) - +#ifdef WOLFSSL_HAVE_ERROR_QUEUE if (wc_LockMutex(&debug_mutex) != 0) { WOLFSSL_MSG("Lock debug mutex failed"); return; @@ -830,7 +849,9 @@ void wc_ClearErrorNodes(void) wc_last_node = NULL; wc_current_node = NULL; wc_UnLockMutex(&debug_mutex); -#endif /* DEBUG_WOLFSSL || WOLFSSL_NGINX */ +#else + WOLFSSL_MSG("Error queue turned off, can not clear nodes"); +#endif } int wc_SetLoggingHeap(void* h) diff --git a/wolfssl/wolfcrypt/logging.h b/wolfssl/wolfcrypt/logging.h index 092186429..16fcb4c71 100644 --- a/wolfssl/wolfcrypt/logging.h +++ b/wolfssl/wolfcrypt/logging.h @@ -105,6 +105,12 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void); WOLFSSL_API const char *wolfSSL_global_cflags(void); #endif + +#if (defined(OPENSSL_EXTRA) && !defined(_WIN32) && \ + !defined(NO_ERROR_QUEUE)) || defined(DEBUG_WOLFSSL_VERBOSE) +#define WOLFSSL_HAVE_ERROR_QUEUE +#endif + #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) WOLFSSL_LOCAL int wc_LoggingInit(void); WOLFSSL_LOCAL int wc_LoggingCleanup(void); @@ -175,8 +181,7 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void); #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\ defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) - #if (!defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && !defined(_WIN32))\ - || defined(DEBUG_WOLFSSL_VERBOSE) + #ifdef WOLFSSL_HAVE_ERROR_QUEUE WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line, const char* file, void* ctx); #define WOLFSSL_ERROR(x) \