diff --git a/src/internal.c b/src/internal.c index 5d6a8fe3a..d4c9b69e8 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6309,6 +6309,12 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup) XMEMCPY(ssl->sessionCtx, ctx->sessionCtx, ctx->sessionCtxSz); ssl->cbioFlag = ctx->cbioFlag; + ssl->protoMsgCb = ctx->protoMsgCb; + ssl->protoMsgCtx = ctx->protoMsgCtx; + + if (ctx->protoMsgCb != NULL) { + ssl->toInfoOn = 1; + } #endif InitCiphers(ssl); diff --git a/src/ssl.c b/src/ssl.c index 5cb2ff162..ac775c14e 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -47894,15 +47894,25 @@ int wolfSSL_set1_curves_list(WOLFSSL* ssl, const char* names) #endif /* OPENSSL_EXTRA && HAVE_ECC */ #ifdef OPENSSL_EXTRA -#ifndef NO_WOLFSSL_STUB +/* Sets a callback for when sending and receiving protocol messages. + * This callback is copied to all WOLFSSL objects created from the ctx. + * + * ctx WOLFSSL_CTX structure to set callback in + * cb callback to use + * + * return WOLFSSL_SUCCESS on success and SSL_FAILURE with error case + */ int wolfSSL_CTX_set_msg_callback(WOLFSSL_CTX *ctx, SSL_Msg_Cb cb) { - WOLFSSL_STUB("SSL_CTX_set_msg_callback"); - (void)ctx; - (void)cb; - return WOLFSSL_FAILURE; + WOLFSSL_ENTER("wolfSSL_CTX_set_msg_callback"); + if (ctx == NULL) { + WOLFSSL_MSG("Null ctx passed in"); + return WOLFSSL_FAILURE; + } + + ctx->protoMsgCb = cb; + return WOLFSSL_SUCCESS; } -#endif /* Sets a callback for when sending and receiving protocol messages. @@ -47927,15 +47937,22 @@ int wolfSSL_set_msg_callback(WOLFSSL *ssl, SSL_Msg_Cb cb) ssl->protoMsgCb = cb; return WOLFSSL_SUCCESS; } -#ifndef NO_WOLFSSL_STUB + + +/* set the user argument to pass to the msg callback when called + * return WOLFSSL_SUCCESS on success */ int wolfSSL_CTX_set_msg_callback_arg(WOLFSSL_CTX *ctx, void* arg) { - WOLFSSL_STUB("SSL_CTX_set_msg_callback_arg"); - (void)ctx; - (void)arg; - return WOLFSSL_FAILURE; + WOLFSSL_ENTER("wolfSSL_CTX_set_msg_callback_arg"); + if (ctx == NULL) { + WOLFSSL_MSG("Null WOLFSSL_CTX passed in"); + return WOLFSSL_FAILURE; + } + + ctx->protoMsgCtx = arg; + return WOLFSSL_SUCCESS; } -#endif + int wolfSSL_set_msg_callback_arg(WOLFSSL *ssl, void* arg) { diff --git a/tests/api.c b/tests/api.c index a1fb0165b..aaf8f848c 100644 --- a/tests/api.c +++ b/tests/api.c @@ -31959,6 +31959,7 @@ static void test_wolfSSL_set_options(void) #endif AssertTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM)); AssertTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM)); + AssertTrue(SSL_CTX_set_msg_callback(ctx, msg_cb) == SSL_SUCCESS); AssertNotNull(ssl = SSL_new(ctx)); #if defined(HAVE_EX_DATA) || defined(FORTRESS) diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 60ff15ab2..e7dcfdf3c 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -2916,6 +2916,10 @@ struct WOLFSSL_CTX { CertVerifyCallback verifyCertCb; void* verifyCertCbArg; #endif /* OPENSSL_ALL */ +#ifdef OPENSSL_EXTRA + SSL_Msg_Cb protoMsgCb; /* inspect protocol message callback */ + void* protoMsgCtx; /* user set context with msg callback */ +#endif word32 timeout; /* session timeout */ #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_ED448) word32 ecdhCurveOID; /* curve Ecc_Sum */