@@ -7895,17 +7895,37 @@ static int test_wolfSSL_UseSNI_params(void)
78957895 ExpectNotNull(ssl);
78967896
78977897 /* invalid [ctx|ssl] */
7898- ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
7899- ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
7898+ ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, WOLFSSL_SNI_HOST_NAME,
7899+ "ctx", 3));
7900+ ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, WOLFSSL_SNI_HOST_NAME,
7901+ "ssl", 3));
79007902 /* invalid type */
79017903 ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, (byte)-1, "ctx", 3));
79027904 ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, (byte)-1, "ssl", 3));
79037905 /* invalid data */
7904- ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
7905- ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
7906+ ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME,
7907+ NULL, 3));
7908+ ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, WOLFSSL_SNI_HOST_NAME,
7909+ NULL, 3));
7910+ /* invalid length */
7911+ if (EXPECT_SUCCESS()) {
7912+ /* 300 chars > WOLFSSL_HOST_NAME_MAX (256) */
7913+ char longName[300];
7914+
7915+ XMEMSET(longName, 'a', sizeof(longName) - 1);
7916+ longName[sizeof(longName) - 1] = '\0';
7917+
7918+ /* host name >= WOLFSSL_HOST_NAME_MAX */
7919+ ExpectIntEQ(BAD_LENGTH_E, wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME,
7920+ longName, (word16)XSTRLEN(longName)));
7921+ ExpectIntEQ(BAD_LENGTH_E, wolfSSL_UseSNI( ssl, WOLFSSL_SNI_HOST_NAME,
7922+ longName, (word16)XSTRLEN(longName)));
7923+ }
79067924 /* success case */
7907- ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
7908- ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
7925+ ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME,
7926+ "ctx", 3));
7927+ ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, WOLFSSL_SNI_HOST_NAME,
7928+ "ssl", 3));
79097929
79107930 wolfSSL_free(ssl);
79117931 wolfSSL_CTX_free(ctx);
@@ -14455,7 +14475,10 @@ static int test_wolfSSL_Tls13_ECH_bad_configs_ex(int hrr, int sniCb)
1445514475 }
1445614476
1445714477 ExpectIntNE(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
14458- ExpectIntEQ(test_ctx.c_ssl->options.echAccepted, 0);
14478+ ExpectIntEQ(wolfSSL_GetEchStatus(test_ctx.c_ssl),
14479+ WOLFSSL_ECH_STATUS_REJECTED);
14480+ ExpectIntEQ(wolfSSL_GetEchStatus(test_ctx.s_ssl),
14481+ WOLFSSL_ECH_STATUS_ACCEPTED);
1445914482
1446014483 test_ssl_memio_cleanup(&test_ctx);
1446114484
@@ -15149,52 +15172,6 @@ static int test_wolfSSL_Tls13_ECH_disable_conn(void)
1514915172 return EXPECT_RESULT();
1515015173}
1515115174
15152- /* Regression test: an inner SNI hostname >= MAX_PUBLIC_NAME_SZ (256) bytes
15153- * must not cause a stack-buffer-overflow in TLSX_EchRestoreSNI. Before the
15154- * fix, the truncated copy omitted the NUL terminator and XSTRLEN read past
15155- * the buffer. */
15156- static int test_wolfSSL_Tls13_ECH_long_SNI(void)
15157- {
15158- EXPECT_DECLS;
15159- #if !defined(NO_WOLFSSL_CLIENT)
15160- test_ssl_memio_ctx test_ctx;
15161- /* 300 chars > MAX_PUBLIC_NAME_SZ (256) to exercise truncation */
15162- char longName[300];
15163-
15164- XMEMSET(longName, 'a', sizeof(longName) - 1);
15165- longName[sizeof(longName) - 1] = '\0';
15166-
15167- XMEMSET(&test_ctx, 0, sizeof(test_ctx));
15168-
15169- test_ctx.s_cb.method = wolfTLSv1_3_server_method;
15170- test_ctx.c_cb.method = wolfTLSv1_3_client_method;
15171-
15172- test_ctx.s_cb.ctx_ready = test_ech_server_ctx_ready;
15173- test_ctx.s_cb.ssl_ready = test_ech_server_ssl_ready;
15174-
15175- ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
15176-
15177- /* Set ECH configs on the client */
15178- ExpectIntEQ(wolfSSL_SetEchConfigs(test_ctx.c_ssl, echCbTestConfigs,
15179- echCbTestConfigsLen), WOLFSSL_SUCCESS);
15180-
15181- /* Try to set the over-long SNI as the inner hostname -- after the fix, this
15182- * is expected to fail.
15183- */
15184- ExpectIntEQ(wolfSSL_UseSNI(test_ctx.c_ssl, WOLFSSL_SNI_HOST_NAME,
15185- longName, (word16)XSTRLEN(longName)), BAD_LENGTH_E);
15186-
15187- /* Before the fix, the handshake would trigger TLSX_EchChangeSNI /
15188- * TLSX_EchRestoreSNI, which would then stack-buffer-overflow in XSTRLEN.
15189- */
15190- (void)test_ssl_memio_do_handshake(&test_ctx, 10, NULL);
15191-
15192- test_ssl_memio_cleanup(&test_ctx);
15193- #endif /* !NO_WOLFSSL_CLIENT */
15194-
15195- return EXPECT_RESULT();
15196- }
15197-
1519815175static int ech_seek_extensions(byte* buf, word16* innerExtLen)
1519915176{
1520015177 word16 idx;
@@ -35300,7 +35277,6 @@ TEST_CASE testCases[] = {
3530035277 TEST_DECL(test_wolfSSL_Tls13_ECH_GREASE),
3530135278 TEST_DECL(test_wolfSSL_Tls13_ECH_wire_sni),
3530235279 TEST_DECL(test_wolfSSL_Tls13_ECH_disable_conn),
35303- TEST_DECL(test_wolfSSL_Tls13_ECH_long_SNI),
3530435280 TEST_DECL(test_wolfSSL_Tls13_ECH_HRR_rejection),
3530535281 TEST_DECL(test_wolfSSL_Tls13_ECH_ch2_no_ech),
3530635282 TEST_DECL(test_wolfSSL_Tls13_ECH_ch2_decrypt_error),
0 commit comments