Skip to content

Commit 907a020

Browse files
committed
Require HAVE_SECURE_RENEGOTIATION for API that perform SCR (not just indication)
1 parent 5a94dc9 commit 907a020

3 files changed

Lines changed: 76 additions & 6 deletions

File tree

src/ssl.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,7 +4004,7 @@ int wolfSSL_CTX_UseSecureRenegotiation(WOLFSSL_CTX* ctx)
40044004
return WOLFSSL_SUCCESS;
40054005
}
40064006

4007-
4007+
#ifdef HAVE_SECURE_RENEGOTIATION
40084008
/* do a secure renegotiation handshake, user forced, we discourage */
40094009
static int _Rehandshake(WOLFSSL* ssl)
40104010
{
@@ -4069,15 +4069,15 @@ static int _Rehandshake(WOLFSSL* ssl)
40694069

40704070
ssl->secure_renegotiation->cache_status = SCR_CACHE_NEEDED;
40714071

4072-
#if !defined(NO_WOLFSSL_SERVER) && defined(HAVE_SECURE_RENEGOTIATION)
4072+
#if !defined(NO_WOLFSSL_SERVER)
40734073
if (ssl->options.side == WOLFSSL_SERVER_END) {
40744074
ret = SendHelloRequest(ssl);
40754075
if (ret != 0) {
40764076
ssl->error = ret;
40774077
return WOLFSSL_FATAL_ERROR;
40784078
}
40794079
}
4080-
#endif /* !NO_WOLFSSL_SERVER && HAVE_SECURE_RENEGOTIATION */
4080+
#endif /* !NO_WOLFSSL_SERVER */
40814081

40824082
ret = InitHandshakeHashes(ssl);
40834083
if (ret != 0) {
@@ -4151,6 +4151,8 @@ int wolfSSL_SecureResume(WOLFSSL* ssl)
41514151

41524152
#endif /* NO_WOLFSSL_CLIENT */
41534153

4154+
#endif /* HAVE_SECURE_RENEGOTIATION */
4155+
41544156
long wolfSSL_SSL_get_secure_renegotiation_support(WOLFSSL* ssl)
41554157
{
41564158
WOLFSSL_ENTER("wolfSSL_SSL_get_secure_renegotiation_support");

tests/api.c

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6367,7 +6367,7 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
63676367
if (ret < 0) { break; } else if (ret == 0) { continue; }
63686368
}
63696369
#endif
6370-
ret = wolfSSL_accept(ssl);
6370+
ret = wolfSSL_negotiate(ssl);
63716371
err = wolfSSL_get_error(ssl, 0);
63726372
} while (err == WC_PENDING_E);
63736373
if (ret != WOLFSSL_SUCCESS) {
@@ -63162,8 +63162,8 @@ static int test_dtls_1_0_hvr_downgrade(void)
6316263162
XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
6316363163

6316463164
func_cb_client.doUdp = func_cb_server.doUdp = 1;
63165-
func_cb_server.method = wolfDTLSv1_2_server_method;
6316663165
func_cb_client.method = wolfDTLS_client_method;
63166+
func_cb_server.method = wolfDTLSv1_2_server_method;
6316763167
func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready;
6316863168

6316963169
test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
@@ -63251,6 +63251,71 @@ static int test_session_ticket_no_id(void)
6325163251
}
6325263252
#endif
6325363253

63254+
#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
63255+
defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
63256+
static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
63257+
{
63258+
AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
63259+
WOLFSSL_SUCCESS);
63260+
AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
63261+
}
63262+
63263+
static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx)
63264+
{
63265+
AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
63266+
}
63267+
63268+
static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl)
63269+
{
63270+
char testMsg[] = "Message after SCR";
63271+
char msgBuf[sizeof(testMsg)];
63272+
if (wolfSSL_is_server(ssl)) {
63273+
AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_FATAL_ERROR);
63274+
AssertIntEQ(wolfSSL_get_error(ssl, -1), APP_DATA_READY);
63275+
AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
63276+
AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
63277+
AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
63278+
sizeof(testMsg));
63279+
}
63280+
else {
63281+
AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
63282+
sizeof(testMsg));
63283+
AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
63284+
}
63285+
}
63286+
63287+
static int test_dtls_downgrade_scr_server(void)
63288+
{
63289+
EXPECT_DECLS;
63290+
callback_functions func_cb_client;
63291+
callback_functions func_cb_server;
63292+
63293+
XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
63294+
XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
63295+
63296+
func_cb_client.doUdp = func_cb_server.doUdp = 1;
63297+
func_cb_client.method = wolfDTLSv1_2_client_method;
63298+
func_cb_server.method = wolfDTLS_server_method;
63299+
func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready;
63300+
func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server;
63301+
func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result;
63302+
func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result;
63303+
63304+
test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
63305+
63306+
ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
63307+
ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
63308+
63309+
return EXPECT_RESULT();
63310+
}
63311+
#else
63312+
static int test_dtls_downgrade_scr_server(void)
63313+
{
63314+
EXPECT_DECLS;
63315+
return EXPECT_RESULT();
63316+
}
63317+
#endif
63318+
6325463319
#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
6325563320
defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
6325663321
static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx)
@@ -63289,8 +63354,8 @@ static int test_dtls_downgrade_scr(void)
6328963354
XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
6329063355

6329163356
func_cb_client.doUdp = func_cb_server.doUdp = 1;
63292-
func_cb_server.method = wolfDTLSv1_2_server_method;
6329363357
func_cb_client.method = wolfDTLS_client_method;
63358+
func_cb_server.method = wolfDTLSv1_2_server_method;
6329463359
func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready;
6329563360
func_cb_client.on_result = test_dtls_downgrade_scr_on_result;
6329663361
func_cb_server.on_result = test_dtls_downgrade_scr_on_result;
@@ -64564,6 +64629,7 @@ TEST_CASE testCases[] = {
6456464629
TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
6456564630
TEST_DECL(test_dtls_1_0_hvr_downgrade),
6456664631
TEST_DECL(test_session_ticket_no_id),
64632+
TEST_DECL(test_dtls_downgrade_scr_server),
6456764633
TEST_DECL(test_dtls_downgrade_scr),
6456864634
/* This test needs to stay at the end to clean up any caches allocated. */
6456964635
TEST_DECL(test_wolfSSL_Cleanup)

wolfssl/ssl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3984,8 +3984,10 @@ WOLFSSL_API int wolfSSL_NoKeyShares(WOLFSSL* ssl);
39843984

39853985
WOLFSSL_API int wolfSSL_UseSecureRenegotiation(WOLFSSL* ssl);
39863986
WOLFSSL_API int wolfSSL_CTX_UseSecureRenegotiation(WOLFSSL_CTX* ctx);
3987+
#ifdef HAVE_SECURE_RENEGOTIATION
39873988
WOLFSSL_API int wolfSSL_Rehandshake(WOLFSSL* ssl);
39883989
WOLFSSL_API int wolfSSL_SecureResume(WOLFSSL* ssl);
3990+
#endif
39893991
WOLFSSL_API long wolfSSL_SSL_get_secure_renegotiation_support(WOLFSSL* ssl);
39903992

39913993
#endif

0 commit comments

Comments
 (0)