Only clear session when we didn't complete a handshake

- Allow overriding buffer size with `WOLFSSL_MSG_EX_BUF_SZ`
- Allow disabling `WOLFSSL_MSG_EX` by defining `NO_WOLFSSL_MSG_EX`
This commit is contained in:
Juliusz Sosinowicz
2022-04-27 22:04:32 +02:00
parent 4013f83e4f
commit 7e9896d162
2 changed files with 16 additions and 9 deletions

View File

@@ -17976,6 +17976,15 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
return WOLFSSL_FAILURE; return WOLFSSL_FAILURE;
} }
if (!ssl->options.handShakeDone) {
/* Only reset the session if we didn't complete a handshake */
wolfSSL_SESSION_free(ssl->session);
ssl->session = wolfSSL_NewSession(ssl->heap);
if (ssl->session == NULL) {
return WOLFSSL_FAILURE;
}
}
ssl->options.isClosed = 0; ssl->options.isClosed = 0;
ssl->options.connReset = 0; ssl->options.connReset = 0;
ssl->options.sentNotify = 0; ssl->options.sentNotify = 0;
@@ -18000,12 +18009,6 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
InitX509(&ssl->peerCert, 0, ssl->heap); InitX509(&ssl->peerCert, 0, ssl->heap);
#endif #endif
wolfSSL_SESSION_free(ssl->session);
ssl->session = wolfSSL_NewSession(ssl->heap);
if (ssl->session == NULL) {
return WOLFSSL_FAILURE;
}
return WOLFSSL_SUCCESS; return WOLFSSL_SUCCESS;
} }

View File

@@ -364,16 +364,20 @@ static void wolfssl_log(const int logLevel, const char *const logMessage)
} }
#ifndef WOLFSSL_DEBUG_ERRORS_ONLY #ifndef WOLFSSL_DEBUG_ERRORS_ONLY
#if !defined(_WIN32) && defined(XVSNPRINTF) && !defined(NO_WOLFSSL_MSG_EX)
#include <stdarg.h> /* for var args */
#ifndef WOLFSSL_MSG_EX_BUF_SZ
#define WOLFSSL_MSG_EX_BUF_SZ 100
#endif
#ifdef __clang__ #ifdef __clang__
/* tell clang argument 1 is format */ /* tell clang argument 1 is format */
__attribute__((__format__ (__printf__, 1, 0))) __attribute__((__format__ (__printf__, 1, 0)))
#endif #endif
#if !defined(_WIN32) && defined(XVSNPRINTF)
#include <stdarg.h> /* for var args */
void WOLFSSL_MSG_EX(const char* fmt, ...) void WOLFSSL_MSG_EX(const char* fmt, ...)
{ {
if (loggingEnabled) { if (loggingEnabled) {
char msg[100]; char msg[WOLFSSL_MSG_EX_BUF_SZ];
int written; int written;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);