Skip to content

Commit 2e125d1

Browse files
move long_sni regression test
1 parent 4a86143 commit 2e125d1

1 file changed

Lines changed: 30 additions & 54 deletions

File tree

tests/api.c

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7739,17 +7739,37 @@ static int test_wolfSSL_UseSNI_params(void)
77397739
ExpectNotNull(ssl);
77407740

77417741
/* invalid [ctx|ssl] */
7742-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
7743-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
7742+
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, WOLFSSL_SNI_HOST_NAME,
7743+
"ctx", 3));
7744+
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, WOLFSSL_SNI_HOST_NAME,
7745+
"ssl", 3));
77447746
/* invalid type */
77457747
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, (byte)-1, "ctx", 3));
77467748
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, (byte)-1, "ssl", 3));
77477749
/* invalid data */
7748-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
7749-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
7750+
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME,
7751+
NULL, 3));
7752+
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, WOLFSSL_SNI_HOST_NAME,
7753+
NULL, 3));
7754+
/* invalid length */
7755+
if (EXPECT_SUCCESS()) {
7756+
/* 300 chars > WOLFSSL_HOST_NAME_MAX (256) */
7757+
char longName[300];
7758+
7759+
XMEMSET(longName, 'a', sizeof(longName) - 1);
7760+
longName[sizeof(longName) - 1] = '\0';
7761+
7762+
/* host name >= WOLFSSL_HOST_NAME_MAX */
7763+
ExpectIntEQ(BAD_LENGTH_E, wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME,
7764+
longName, (word16)XSTRLEN(longName)));
7765+
ExpectIntEQ(BAD_LENGTH_E, wolfSSL_UseSNI( ssl, WOLFSSL_SNI_HOST_NAME,
7766+
longName, (word16)XSTRLEN(longName)));
7767+
}
77507768
/* success case */
7751-
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
7752-
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
7769+
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME,
7770+
"ctx", 3));
7771+
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, WOLFSSL_SNI_HOST_NAME,
7772+
"ssl", 3));
77537773

77547774
wolfSSL_free(ssl);
77557775
wolfSSL_CTX_free(ctx);
@@ -14115,7 +14135,10 @@ static int test_wolfSSL_Tls13_ECH_bad_configs_ex(int hrr, int sniCb)
1411514135
}
1411614136

1411714137
ExpectIntNE(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
14118-
ExpectIntEQ(test_ctx.c_ssl->options.echAccepted, 0);
14138+
ExpectIntEQ(wolfSSL_GetEchStatus(test_ctx.c_ssl),
14139+
WOLFSSL_ECH_STATUS_REJECTED);
14140+
ExpectIntEQ(wolfSSL_GetEchStatus(test_ctx.s_ssl),
14141+
WOLFSSL_ECH_STATUS_ACCEPTED);
1411914142

1412014143
test_ssl_memio_cleanup(&test_ctx);
1412114144

@@ -14809,52 +14832,6 @@ static int test_wolfSSL_Tls13_ECH_disable_conn(void)
1480914832
return EXPECT_RESULT();
1481014833
}
1481114834

14812-
/* Regression test: an inner SNI hostname >= MAX_PUBLIC_NAME_SZ (256) bytes
14813-
* must not cause a stack-buffer-overflow in TLSX_EchRestoreSNI. Before the
14814-
* fix, the truncated copy omitted the NUL terminator and XSTRLEN read past
14815-
* the buffer. */
14816-
static int test_wolfSSL_Tls13_ECH_long_SNI(void)
14817-
{
14818-
EXPECT_DECLS;
14819-
#if !defined(NO_WOLFSSL_CLIENT)
14820-
test_ssl_memio_ctx test_ctx;
14821-
/* 300 chars > MAX_PUBLIC_NAME_SZ (256) to exercise truncation */
14822-
char longName[300];
14823-
14824-
XMEMSET(longName, 'a', sizeof(longName) - 1);
14825-
longName[sizeof(longName) - 1] = '\0';
14826-
14827-
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
14828-
14829-
test_ctx.s_cb.method = wolfTLSv1_3_server_method;
14830-
test_ctx.c_cb.method = wolfTLSv1_3_client_method;
14831-
14832-
test_ctx.s_cb.ctx_ready = test_ech_server_ctx_ready;
14833-
test_ctx.s_cb.ssl_ready = test_ech_server_ssl_ready;
14834-
14835-
ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
14836-
14837-
/* Set ECH configs on the client */
14838-
ExpectIntEQ(wolfSSL_SetEchConfigs(test_ctx.c_ssl, echCbTestConfigs,
14839-
echCbTestConfigsLen), WOLFSSL_SUCCESS);
14840-
14841-
/* Try to set the over-long SNI as the inner hostname -- after the fix, this
14842-
* is expected to fail.
14843-
*/
14844-
ExpectIntEQ(wolfSSL_UseSNI(test_ctx.c_ssl, WOLFSSL_SNI_HOST_NAME,
14845-
longName, (word16)XSTRLEN(longName)), BAD_LENGTH_E);
14846-
14847-
/* Before the fix, the handshake would trigger TLSX_EchChangeSNI /
14848-
* TLSX_EchRestoreSNI, which would then stack-buffer-overflow in XSTRLEN.
14849-
*/
14850-
(void)test_ssl_memio_do_handshake(&test_ctx, 10, NULL);
14851-
14852-
test_ssl_memio_cleanup(&test_ctx);
14853-
#endif /* !NO_WOLFSSL_CLIENT */
14854-
14855-
return EXPECT_RESULT();
14856-
}
14857-
1485814835
static int ech_seek_extensions(byte* buf, word16* innerExtLen)
1485914836
{
1486014837
word16 idx;
@@ -34645,7 +34622,6 @@ TEST_CASE testCases[] = {
3464534622
TEST_DECL(test_wolfSSL_Tls13_ECH_GREASE),
3464634623
TEST_DECL(test_wolfSSL_Tls13_ECH_wire_sni),
3464734624
TEST_DECL(test_wolfSSL_Tls13_ECH_disable_conn),
34648-
TEST_DECL(test_wolfSSL_Tls13_ECH_long_SNI),
3464934625
TEST_DECL(test_wolfSSL_Tls13_ECH_HRR_rejection),
3465034626
TEST_DECL(test_wolfSSL_Tls13_ECH_ch2_no_ech),
3465134627
TEST_DECL(test_wolfSSL_Tls13_ECH_ch2_decrypt_error),

0 commit comments

Comments
 (0)