Skip to content

Commit 0d06061

Browse files
committed
test: tls13_early_data: refactor splitEarlyData test option
1 parent c0c29a6 commit 0d06061

File tree

1 file changed

+130
-126
lines changed

1 file changed

+130
-126
lines changed

tests/api/test_tls13.c

Lines changed: 130 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,164 +2011,168 @@ int test_tls13_early_data(void)
20112011
method_provider server_meth;
20122012
const char* tls_version;
20132013
int isUdp;
2014+
int splitEarlyData;
20142015
} params[] = {
20152016
#ifdef WOLFSSL_TLS13
20162017
{ wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
2017-
"TLS 1.3", 0 },
2018+
"TLS 1.3", 0, 0 },
2019+
{ wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
2020+
"TLS 1.3", 0, 1 },
20182021
#endif
20192022
#ifdef WOLFSSL_DTLS13
20202023
{ wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
2021-
"DTLS 1.3", 1 },
2024+
"DTLS 1.3", 1, 0 },
2025+
{ wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
2026+
"DTLS 1.3", 1, 1 },
20222027
#endif
20232028
};
20242029

20252030
for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
2026-
for (splitEarlyData = 0; splitEarlyData < 2; splitEarlyData++) {
2027-
struct test_memio_ctx test_ctx;
2028-
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
2029-
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
2030-
WOLFSSL_SESSION *sess = NULL;
2031-
2032-
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
2033-
2034-
fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
2035-
2036-
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
2037-
&ssl_s, params[i].client_meth, params[i].server_meth), 0);
2038-
2039-
/* Get a ticket so that we can do 0-RTT on the next connection */
2040-
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
2041-
/* Make sure we read the ticket */
2042-
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
2043-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
2044-
ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
2045-
2046-
wolfSSL_free(ssl_c);
2047-
ssl_c = NULL;
2048-
wolfSSL_free(ssl_s);
2049-
ssl_s = NULL;
2050-
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
2051-
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
2031+
struct test_memio_ctx test_ctx;
2032+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
2033+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
2034+
WOLFSSL_SESSION *sess = NULL;
2035+
int splitEarlyData = params[i].splitEarlyData;
2036+
2037+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
2038+
2039+
fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
2040+
2041+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
20522042
&ssl_s, params[i].client_meth, params[i].server_meth), 0);
2053-
wolfSSL_SetLoggingPrefix("client");
2054-
ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
2043+
2044+
/* Get a ticket so that we can do 0-RTT on the next connection */
2045+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
2046+
/* Make sure we read the ticket */
2047+
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
2048+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
2049+
ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
2050+
2051+
wolfSSL_free(ssl_c);
2052+
ssl_c = NULL;
2053+
wolfSSL_free(ssl_s);
2054+
ssl_s = NULL;
2055+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
2056+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
2057+
&ssl_s, params[i].client_meth, params[i].server_meth), 0);
2058+
wolfSSL_SetLoggingPrefix("client");
2059+
ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
20552060
#ifdef WOLFSSL_DTLS13
2056-
if (params[i].isUdp) {
2057-
wolfSSL_SetLoggingPrefix("server");
2061+
if (params[i].isUdp) {
2062+
wolfSSL_SetLoggingPrefix("server");
20582063
#ifdef WOLFSSL_DTLS13_NO_HRR_ON_RESUME
2059-
ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1),
2060-
WOLFSSL_SUCCESS);
2064+
ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1),
2065+
WOLFSSL_SUCCESS);
20612066
#else
2062-
/* Let's test this but we generally don't recommend turning off
2063-
* the cookie exchange */
2064-
ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
2067+
/* Let's test this but we generally don't recommend turning off
2068+
* the cookie exchange */
2069+
ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
20652070
#endif
2066-
}
2071+
}
20672072
#endif
20682073

2069-
/* Test 0-RTT data */
2070-
wolfSSL_SetLoggingPrefix("client");
2074+
/* Test 0-RTT data */
2075+
wolfSSL_SetLoggingPrefix("client");
2076+
ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
2077+
&written), sizeof(msg));
2078+
ExpectIntEQ(written, sizeof(msg));
2079+
2080+
if (splitEarlyData) {
20712081
ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
20722082
&written), sizeof(msg));
20732083
ExpectIntEQ(written, sizeof(msg));
2084+
}
20742085

2075-
if (splitEarlyData) {
2076-
ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
2077-
&written), sizeof(msg));
2078-
ExpectIntEQ(written, sizeof(msg));
2079-
}
2086+
/* Read first 0-RTT data (if split otherwise entire data) */
2087+
wolfSSL_SetLoggingPrefix("server");
2088+
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
2089+
&read), sizeof(msg));
2090+
ExpectIntEQ(read, sizeof(msg));
2091+
ExpectStrEQ(msg, msgBuf);
20802092

2081-
/* Read first 0-RTT data (if split otherwise entire data) */
2082-
wolfSSL_SetLoggingPrefix("server");
2083-
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
2084-
&read), sizeof(msg));
2093+
/* Test 0.5-RTT data */
2094+
ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
2095+
2096+
if (splitEarlyData) {
2097+
/* Read second 0-RTT data */
2098+
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf,
2099+
sizeof(msgBuf), &read), sizeof(msg));
20852100
ExpectIntEQ(read, sizeof(msg));
20862101
ExpectStrEQ(msg, msgBuf);
2102+
}
20872103

2088-
/* Test 0.5-RTT data */
2089-
ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
2090-
2091-
if (splitEarlyData) {
2092-
/* Read second 0-RTT data */
2093-
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf,
2094-
sizeof(msgBuf), &read), sizeof(msg));
2095-
ExpectIntEQ(read, sizeof(msg));
2096-
ExpectStrEQ(msg, msgBuf);
2097-
}
2104+
if (params[i].isUdp) {
2105+
wolfSSL_SetLoggingPrefix("client");
2106+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
2107+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
2108+
WC_NO_ERR_TRACE(APP_DATA_READY));
20982109

2099-
if (params[i].isUdp) {
2100-
wolfSSL_SetLoggingPrefix("client");
2101-
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
2102-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
2103-
WC_NO_ERR_TRACE(APP_DATA_READY));
2104-
2105-
/* Read server 0.5-RTT data */
2106-
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)),
2107-
sizeof(msg4));
2108-
ExpectStrEQ(msg4, msgBuf);
2109-
2110-
/* Complete handshake */
2111-
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
2112-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
2113-
WOLFSSL_ERROR_WANT_READ);
2114-
/* Use wolfSSL_is_init_finished to check if handshake is
2115-
* complete. Normally a user would loop until it is true but
2116-
* here we control both sides so we just assert the expected
2117-
* value. wolfSSL_read_early_data does not provide handshake
2118-
* status to us with non-blocking IO and we can't use
2119-
* wolfSSL_accept as TLS layer may return ZERO_RETURN due to
2120-
* early data parsing logic. */
2121-
wolfSSL_SetLoggingPrefix("server");
2122-
ExpectFalse(wolfSSL_is_init_finished(ssl_s));
2123-
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf,
2124-
sizeof(msgBuf), &read), 0);
2125-
ExpectIntEQ(read, 0);
2126-
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
2127-
2128-
wolfSSL_SetLoggingPrefix("client");
2129-
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
2130-
}
2131-
else {
2132-
wolfSSL_SetLoggingPrefix("client");
2133-
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
2134-
2135-
wolfSSL_SetLoggingPrefix("server");
2136-
ExpectFalse(wolfSSL_is_init_finished(ssl_s));
2137-
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf,
2138-
sizeof(msgBuf), &read), 0);
2139-
ExpectIntEQ(read, 0);
2140-
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
2141-
2142-
/* Read server 0.5-RTT data */
2143-
wolfSSL_SetLoggingPrefix("client");
2144-
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)),
2145-
sizeof(msg4));
2146-
ExpectStrEQ(msg4, msgBuf);
2147-
}
2110+
/* Read server 0.5-RTT data */
2111+
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)),
2112+
sizeof(msg4));
2113+
ExpectStrEQ(msg4, msgBuf);
2114+
2115+
/* Complete handshake */
2116+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
2117+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
2118+
WOLFSSL_ERROR_WANT_READ);
2119+
/* Use wolfSSL_is_init_finished to check if handshake is
2120+
* complete. Normally a user would loop until it is true but
2121+
* here we control both sides so we just assert the expected
2122+
* value. wolfSSL_read_early_data does not provide handshake
2123+
* status to us with non-blocking IO and we can't use
2124+
* wolfSSL_accept as TLS layer may return ZERO_RETURN due to
2125+
* early data parsing logic. */
2126+
wolfSSL_SetLoggingPrefix("server");
2127+
ExpectFalse(wolfSSL_is_init_finished(ssl_s));
2128+
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf,
2129+
sizeof(msgBuf), &read), 0);
2130+
ExpectIntEQ(read, 0);
2131+
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
21482132

2149-
/* Test bi-directional write */
21502133
wolfSSL_SetLoggingPrefix("client");
2151-
ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
2134+
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
2135+
}
2136+
else {
2137+
wolfSSL_SetLoggingPrefix("client");
2138+
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
2139+
21522140
wolfSSL_SetLoggingPrefix("server");
2153-
ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)),
2154-
sizeof(msg2));
2155-
ExpectStrEQ(msg2, msgBuf);
2156-
ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
2141+
ExpectFalse(wolfSSL_is_init_finished(ssl_s));
2142+
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf,
2143+
sizeof(msgBuf), &read), 0);
2144+
ExpectIntEQ(read, 0);
2145+
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
2146+
2147+
/* Read server 0.5-RTT data */
21572148
wolfSSL_SetLoggingPrefix("client");
21582149
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)),
2159-
sizeof(msg3));
2160-
ExpectStrEQ(msg3, msgBuf);
2161-
2162-
wolfSSL_SetLoggingPrefix(NULL);
2163-
ExpectTrue(wolfSSL_session_reused(ssl_c));
2164-
ExpectTrue(wolfSSL_session_reused(ssl_s));
2165-
2166-
wolfSSL_SESSION_free(sess);
2167-
wolfSSL_free(ssl_c);
2168-
wolfSSL_free(ssl_s);
2169-
wolfSSL_CTX_free(ctx_c);
2170-
wolfSSL_CTX_free(ctx_s);
2150+
sizeof(msg4));
2151+
ExpectStrEQ(msg4, msgBuf);
21712152
}
2153+
2154+
/* Test bi-directional write */
2155+
wolfSSL_SetLoggingPrefix("client");
2156+
ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
2157+
wolfSSL_SetLoggingPrefix("server");
2158+
ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)),
2159+
sizeof(msg2));
2160+
ExpectStrEQ(msg2, msgBuf);
2161+
ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
2162+
wolfSSL_SetLoggingPrefix("client");
2163+
ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)),
2164+
sizeof(msg3));
2165+
ExpectStrEQ(msg3, msgBuf);
2166+
2167+
wolfSSL_SetLoggingPrefix(NULL);
2168+
ExpectTrue(wolfSSL_session_reused(ssl_c));
2169+
ExpectTrue(wolfSSL_session_reused(ssl_s));
2170+
2171+
wolfSSL_SESSION_free(sess);
2172+
wolfSSL_free(ssl_c);
2173+
wolfSSL_free(ssl_s);
2174+
wolfSSL_CTX_free(ctx_c);
2175+
wolfSSL_CTX_free(ctx_s);
21722176
}
21732177
#endif
21742178
return EXPECT_RESULT();

0 commit comments

Comments
 (0)