examples: support DTLS version downgrading

This commit is contained in:
Marco Oliverio
2022-07-04 17:00:15 +02:00
parent df7e81d187
commit fd4836772b
2 changed files with 40 additions and 7 deletions

View File

@ -2802,7 +2802,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
err_sys("Bad DTLS version"); err_sys("Bad DTLS version");
#endif /* WOLFSSL_DTLS13 */ #endif /* WOLFSSL_DTLS13 */
} }
else else if (version == 2)
version = -1; version = -1;
} }
} }
@ -2859,7 +2859,16 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#endif #endif
case CLIENT_DOWNGRADE_VERSION: case CLIENT_DOWNGRADE_VERSION:
method = wolfSSLv23_client_method_ex; if (!doDTLS) {
method = wolfSSLv23_client_method_ex;
}
else {
#ifdef WOLFSSL_DTLS
method = wolfDTLS_client_method_ex;
#else
err_sys("version not supported");
#endif /* WOLFSSL_DTLS */
}
break; break;
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
case EITHER_DOWNGRADE_VERSION: case EITHER_DOWNGRADE_VERSION:
@ -2934,7 +2943,28 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
} }
#endif #endif
if (minVersion != CLIENT_INVALID_VERSION) { if (minVersion != CLIENT_INVALID_VERSION) {
wolfSSL_CTX_SetMinVersion(ctx, minVersion); #ifdef WOLFSSL_DTLS
if (doDTLS) {
switch (minVersion) {
case 4:
#ifdef WOLFSSL_DTLS13
minVersion = WOLFSSL_DTLSV1_3;
break;
#else
err_sys("invalid minimum downgrade version");
break;
#endif /* WOLFSSL_DTLS13 */
case 3:
minVersion = WOLFSSL_DTLSV1_2;
break;
case 2:
minVersion = WOLFSSL_DTLSV1;
break;
}
}
#endif /* WOLFSSL_DTLS */
if (wolfSSL_CTX_SetMinVersion(ctx, minVersion) != WOLFSSL_SUCCESS)
err_sys("can't set minimum downgrade version");
} }
if (simulateWantWrite) { if (simulateWantWrite) {
#ifdef USE_WOLFSSL_IO #ifdef USE_WOLFSSL_IO

View File

@ -2265,11 +2265,11 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
method = wolfSSLv23_server_method_ex; method = wolfSSLv23_server_method_ex;
} }
else { else {
#ifdef WOLFSSL_DTLS13 #ifdef WOLFSSL_DTLS
method = wolfDTLS_server_method_ex; method = wolfDTLS_server_method_ex;
#else #else
err_sys_ex(runWithErrors, "version not supported"); err_sys_ex(runWithErrors, "version not supported");
#endif /* WOLFSSL_DTLS13 */ #endif /* WOLFSSL_DTLS */
} }
break; break;
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
@ -2341,12 +2341,14 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
err_sys_ex(catastrophic, "unable to get ctx"); err_sys_ex(catastrophic, "unable to get ctx");
if (minVersion != SERVER_INVALID_VERSION) { if (minVersion != SERVER_INVALID_VERSION) {
#ifdef WOLFSSL_DTLS13 #ifdef WOLFSSL_DTLS
if (doDTLS) { if (doDTLS) {
switch (minVersion) { switch (minVersion) {
#ifdef WOLFSSL_DTLS13
case 4: case 4:
minVersion = WOLFSSL_DTLSV1_3; minVersion = WOLFSSL_DTLSV1_3;
break; break;
#endif /* WOLFSSL_DTLS13 */
case 3: case 3:
minVersion = WOLFSSL_DTLSV1_2; minVersion = WOLFSSL_DTLSV1_2;
break; break;
@ -2356,7 +2358,8 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
} }
} }
#endif /* WOLFSSL_DTLS13 */ #endif /* WOLFSSL_DTLS13 */
wolfSSL_CTX_SetMinVersion(ctx, minVersion); if (wolfSSL_CTX_SetMinVersion(ctx, minVersion) != WOLFSSL_SUCCESS)
err_sys_ex(catastrophic, "can't set minimum downgrade version");
} }
#ifdef OPENSSL_COMPATIBLE_DEFAULTS #ifdef OPENSSL_COMPATIBLE_DEFAULTS