Skip to content

Commit 16dbd09

Browse files
committed
Keep a fixed DTLS method's version under a CTX maximum
protoVerTbl now lists DTLS1_3_VERSION, so wolfSSL_CTX_set_max_proto_version() with 0 or DTLS1_3_VERSION turned a wolfDTLSv1_2_*_method() CTX into DTLS 1.3, and the fixed method could not downgrade back to 1.2. A maximum of DTLS1_VERSION already turned it into DTLS 1.0. OpenSSL stores no maximum for a fixed method, and wolfSSL_set_max_proto_version() already keeps the fixed version of an SSL. Set_CTX_max_proto_version() now moves the method version of a DTLS CTX only when the method may downgrade. A maximum at or above a fixed version leaves it, and one below it fails through CtxDtlsVersionLeft() and restores the CTX, as the SSL setter does.
1 parent c4a5a4e commit 16dbd09

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎src/ssl.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5608,14 +5608,17 @@ static int Set_CTX_max_proto_version(WOLFSSL_CTX* ctx, int ver)
56085608
#endif
56095609
#ifdef WOLFSSL_DTLS
56105610
case DTLS1_VERSION:
5611-
ctx->method->version.minor = DTLS_MINOR;
5611+
if (ctx->method->downgrade)
5612+
ctx->method->version.minor = DTLS_MINOR;
56125613
break;
56135614
case DTLS1_2_VERSION:
5614-
ctx->method->version.minor = DTLSv1_2_MINOR;
5615+
if (ctx->method->downgrade)
5616+
ctx->method->version.minor = DTLSv1_2_MINOR;
56155617
break;
56165618
#ifdef WOLFSSL_DTLS13
56175619
case DTLS1_3_VERSION:
5618-
ctx->method->version.minor = DTLSv1_3_MINOR;
5620+
if (ctx->method->downgrade)
5621+
ctx->method->version.minor = DTLSv1_3_MINOR;
56195622
break;
56205623
#endif
56215624
#endif

‎tests/api/test_dtls.c‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16947,9 +16947,8 @@ static int test_dtls13_ctx_max_proto_reset(void)
1694716947
return EXPECT_RESULT();
1694816948
}
1694916949

16950-
/* A CTX maximum moves a fixed DTLS method down and back up, as it does a fixed
16951-
* TLS method. */
16952-
static int test_dtls13_ctx_max_proto_fixed(method_provider method)
16950+
/* A CTX maximum never moves a fixed DTLS method, and one below it fails. */
16951+
static int test_dtls13_ctx_max_proto_fixed(method_provider method, int ver)
1695316952
{
1695416953
EXPECT_DECLS;
1695516954
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
@@ -16960,17 +16959,19 @@ static int test_dtls13_ctx_max_proto_fixed(method_provider method)
1696016959
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, NULL, NULL,
1696116960
method, wolfDTLS_server_method), 0);
1696216961
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx_c, DTLS1_2_VERSION),
16963-
WOLFSSL_SUCCESS);
16962+
ver == DTLS1_2_VERSION ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE);
16963+
#ifndef NO_OLD_TLS
16964+
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx_c, DTLS1_VERSION),
16965+
WOLFSSL_FAILURE);
16966+
#endif
16967+
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx_c, 0), WOLFSSL_SUCCESS);
1696416968
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx_c, DTLS1_3_VERSION),
1696516969
WOLFSSL_SUCCESS);
16966-
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx_c, DTLS1_2_VERSION),
16967-
WOLFSSL_SUCCESS);
16968-
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx_c, 0), WOLFSSL_SUCCESS);
1696916970
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
1697016971
method, wolfDTLS_server_method), 0);
16971-
ExpectIntEQ(wolfSSL_version(ssl_c), DTLS1_3_VERSION);
16972+
ExpectIntEQ(wolfSSL_version(ssl_c), ver);
1697216973
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
16973-
ExpectIntEQ(wolfSSL_version(ssl_s), DTLS1_3_VERSION);
16974+
ExpectIntEQ(wolfSSL_version(ssl_s), ver);
1697416975

1697516976
wolfSSL_free(ssl_c);
1697616977
wolfSSL_free(ssl_s);
@@ -18263,10 +18264,10 @@ int test_dtls13_no_tls13_option(void)
1826318264
ExpectIntEQ(test_dtls13_mask_client_check(), TEST_SUCCESS);
1826418265
ExpectIntEQ(test_dtls13_mask_negotiate(), TEST_SUCCESS);
1826518266
ExpectIntEQ(test_dtls13_ctx_max_proto_reset(), TEST_SUCCESS);
18266-
ExpectIntEQ(test_dtls13_ctx_max_proto_fixed(wolfDTLSv1_3_client_method),
18267-
TEST_SUCCESS);
18268-
ExpectIntEQ(test_dtls13_ctx_max_proto_fixed(wolfDTLSv1_2_client_method),
18269-
TEST_SUCCESS);
18267+
ExpectIntEQ(test_dtls13_ctx_max_proto_fixed(wolfDTLSv1_3_client_method,
18268+
DTLS1_3_VERSION), TEST_SUCCESS);
18269+
ExpectIntEQ(test_dtls13_ctx_max_proto_fixed(wolfDTLSv1_2_client_method,
18270+
DTLS1_2_VERSION), TEST_SUCCESS);
1827018271
ExpectIntEQ(test_dtls13_min_max_tls_version(0), TEST_SUCCESS);
1827118272
ExpectIntEQ(test_dtls13_min_max_tls_version(1), TEST_SUCCESS);
1827218273
ExpectIntEQ(test_dtls13_min_max_tls_version(2), TEST_SUCCESS);

0 commit comments

Comments
 (0)