Skip to content

Commit ecbb576

Browse files
committed
Restore CTX version settings after any failed setter
wolfSSL_CTX_set_max_proto_version() clears the NO_TLSv1* options and re-applies the minimum before Set_CTX_max_proto_version() can fail, and wolfSSL_CTX_set_min_proto_version() clears them when the maximum is below the requested minimum. CtxVersionRestore() undid this only for DTLS and for methods that cannot downgrade, so on a wolfSSLv23_*() CTX a failed call, such as a DTLS, unknown or unsupported SSLv3 version, left the user's version options cleared, or every version masked off. This predates the restore code. Restore the mask, minimum and method version on every failure. A failed maximum now leaves the earlier version range in place instead of disabling the CTX, as OpenSSL does. test_tls_ctx_proto_failed_keeps_options covers each failing maximum and an unknown minimum on a v23 CTX capped at TLS 1.2, in any build with OPENSSL_EXTRA and TLS 1.2.
1 parent 326779e commit ecbb576

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎src/ssl.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5245,8 +5245,7 @@ static void CtxVersionSave(const WOLFSSL_CTX* ctx, CtxVersionState* st)
52455245
static int CtxVersionRestore(WOLFSSL_CTX* ctx, const CtxVersionState* st,
52465246
int ret)
52475247
{
5248-
if (ret != WOLFSSL_SUCCESS && (ctx->method->version.major == DTLS_MAJOR ||
5249-
!ctx->method->downgrade)) {
5248+
if (ret != WOLFSSL_SUCCESS) {
52505249
ctx->mask = st->mask;
52515250
ctx->method->version = st->version;
52525251
ctx->minDowngrade = st->minDowngrade;

‎tests/api/test_tls.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,6 +3102,50 @@ static int test_tls_max_proto_pinned(void)
31023102
}
31033103
#endif
31043104

3105+
#if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_TLS12)
3106+
/* A failed minimum or maximum on a v23 CTX keeps its version settings. */
3107+
static int test_tls_ctx_proto_failed_keeps_options(void)
3108+
{
3109+
EXPECT_DECLS;
3110+
WOLFSSL_CTX *ctx = NULL;
3111+
long mask = 0;
3112+
int minProto = 0;
3113+
int i;
3114+
static const int badMax[] = {
3115+
TLS1_3_VERSION + 1,
3116+
#ifdef WOLFSSL_DTLS
3117+
DTLS1_2_VERSION,
3118+
#endif
3119+
#ifndef WOLFSSL_ALLOW_SSLV3
3120+
SSL3_VERSION,
3121+
#endif
3122+
};
3123+
3124+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
3125+
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
3126+
WOLFSSL_SUCCESS);
3127+
if (ctx != NULL) {
3128+
mask = wolfSSL_CTX_get_options(ctx);
3129+
minProto = wolfSSL_CTX_get_min_proto_version(ctx);
3130+
}
3131+
for (i = 0; i < (int)(sizeof(badMax) / sizeof(badMax[0])); i++) {
3132+
ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, badMax[i]),
3133+
WOLFSSL_FAILURE);
3134+
ExpectIntEQ(wolfSSL_CTX_get_options(ctx), mask);
3135+
ExpectIntEQ(ctx != NULL ? ctx->method->version.minor : 0,
3136+
TLSv1_2_MINOR);
3137+
ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
3138+
}
3139+
ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION + 1),
3140+
WOLFSSL_FAILURE);
3141+
ExpectIntEQ(wolfSSL_CTX_get_options(ctx), mask);
3142+
ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), minProto);
3143+
ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
3144+
wolfSSL_CTX_free(ctx);
3145+
return EXPECT_RESULT();
3146+
}
3147+
#endif
3148+
31053149
int test_tls_max_proto_fixed(void)
31063150
{
31073151
EXPECT_DECLS;
@@ -3118,6 +3162,9 @@ int test_tls_max_proto_fixed(void)
31183162
#if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && \
31193163
!defined(NO_WOLFSSL_CLIENT)
31203164
ExpectIntEQ(test_tls_max_proto_pinned(), TEST_SUCCESS);
3165+
#endif
3166+
#if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_TLS12)
3167+
ExpectIntEQ(test_tls_ctx_proto_failed_keeps_options(), TEST_SUCCESS);
31213168
#endif
31223169
return EXPECT_RESULT();
31233170
}

0 commit comments

Comments
 (0)