Newer
Older
unsigned char buf[20];
size_t readbytes, written;
/*
* Test that a server that doesn't try to read early data can handle a
* client sending some.
*/
if (!setupearly_data_test(&cctx, &sctx, &clientssl, &serverssl, &sess, idx))
if (!SSL_write_early_data(clientssl, MSG1, strlen(MSG1), &written)) {
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
printf("Unexpected failure writing message 1\n");
goto end;
}
/*
* Server should skip over early data and then block waiting for client to
* continue handshake
*/
if (SSL_accept(serverssl) > 0) {
printf("Unexpected success setting up server connection\n");
goto end;
}
if (SSL_connect(clientssl) <= 0) {
printf("Failed setting up client connection\n");
goto end;
}
if (SSL_get_early_data_status(serverssl) != SSL_EARLY_DATA_REJECTED) {
printf("Unexpected early data status\n");
goto end;
}
if (SSL_accept(serverssl) <= 0) {
printf("Failed setting up server connection\n");
goto end;
}
if (SSL_get_early_data_status(clientssl) != SSL_EARLY_DATA_REJECTED) {
printf("Unexpected early data status (2)\n");
goto end;
}
/* Send some normal data from client to server */
if (!SSL_write_ex(clientssl, MSG2, strlen(MSG2), &written)
|| written != strlen(MSG2)) {
printf("Failed writing message 2\n");
goto end;
}
if (!SSL_read_ex(serverssl, buf, sizeof(buf), &readbytes)
|| readbytes != strlen(MSG2)
|| memcmp(MSG2, buf, strlen(MSG2))) {
printf("Failed reading message 2\n");
goto end;
}
testresult = 1;
end:
if(!testresult)
ERR_print_errors_fp(stdout);
SSL_SESSION_free(sess);
SSL_free(serverssl);
SSL_free(clientssl);
SSL_CTX_free(sctx);
SSL_CTX_free(cctx);
return testresult;
}
# ifndef OPENSSL_NO_TLS1_2
static int test_early_data_tls1_2(int idx)
{
SSL_CTX *cctx = NULL, *sctx = NULL;
SSL *clientssl = NULL, *serverssl = NULL;
int testresult = 0;
unsigned char buf[20];
size_t readbytes, written;
/*
* Test that a server attempting to read early data can handle a connection
* from a TLSv1.2 client.
*/
if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
&cctx, cert, privkey)) {
printf("Unable to create SSL_CTX pair\n");
goto end;
}
/* When idx == 1 we repeat the tests with read_ahead set */
if (idx > 0) {
SSL_CTX_set_read_ahead(cctx, 1);
SSL_CTX_set_read_ahead(sctx, 1);
}
if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
printf("Unable to create SSL objects\n");
goto end;
}
/* Write some data - should block due to handshake with server */
SSL_set_max_proto_version(clientssl, TLS1_2_VERSION);
SSL_set_connect_state(clientssl);
if (SSL_write_ex(clientssl, MSG1, strlen(MSG1), &written)) {
printf("Unexpected success writing message 1\n");
goto end;
}
/*
* Server should do TLSv1.2 handshake. First it will block waiting for more
* messages from client after ServerDone. Then SSL_read_early_data should
* finish and detect that early data has not been sent
if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
!= SSL_READ_EARLY_DATA_ERROR) {
printf("Unexpected success reading early data\n");
goto end;
}
/*
* Continue writing the message we started earlier. Will still block waiting
* for the CCS/Finished from server
*/
if (SSL_write_ex(clientssl, MSG1, strlen(MSG1), &written)) {
printf("Unexpected success writing message 1\n");
goto end;
}
if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
!= SSL_READ_EARLY_DATA_FINISH
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
|| readbytes != 0) {
printf("Failed reading early data\n");
goto end;
}
if (SSL_get_early_data_status(serverssl) != SSL_EARLY_DATA_NOT_SENT) {
printf("Unexpected early data status\n");
goto end;
}
/* Continue writing the message we started earlier */
if (!SSL_write_ex(clientssl, MSG1, strlen(MSG1), &written)
|| written != strlen(MSG1)) {
printf("Failed writing message 1\n");
goto end;
}
if (SSL_get_early_data_status(clientssl) != SSL_EARLY_DATA_NOT_SENT) {
printf("Unexpected early data status (2)\n");
goto end;
}
if (!SSL_read_ex(serverssl, buf, sizeof(buf), &readbytes)
|| readbytes != strlen(MSG1)
|| memcmp(MSG1, buf, strlen(MSG1))) {
printf("Failed reading message 1\n");
goto end;
}
if (!SSL_write_ex(serverssl, MSG2, strlen(MSG2), &written)
|| written != strlen(MSG2)) {
printf("Failed writing message 2\n");
goto end;
}
if (!SSL_read_ex(clientssl, buf, sizeof(buf), &readbytes)
|| readbytes != strlen(MSG2)
|| memcmp(MSG2, buf, strlen(MSG2))) {
printf("Failed reading message 2\n");
goto end;
}
testresult = 1;
end:
if(!testresult)
ERR_print_errors_fp(stdout);
SSL_free(serverssl);
SSL_free(clientssl);
SSL_CTX_free(sctx);
SSL_CTX_free(cctx);
return testresult;
}
# endif
#endif
int test_main(int argc, char *argv[])
if (argc != 3) {
printf("Invalid argument count\n");
}
cert = argv[1];
privkey = argv[2];
ADD_TEST(test_tlsext_status_type);
ADD_TEST(test_session_with_only_int_cache);
ADD_TEST(test_session_with_only_ext_cache);
ADD_TEST(test_session_with_both_cache);
ADD_ALL_TESTS(test_ssl_set_bio, TOTAL_SSL_SET_BIO_TESTS);
ADD_TEST(test_ssl_bio_pop_next_bio);
ADD_TEST(test_ssl_bio_pop_ssl_bio);
ADD_TEST(test_ssl_bio_change_rbio);
ADD_TEST(test_ssl_bio_change_wbio);
ADD_ALL_TESTS(test_set_sigalgs, OSSL_NELEM(testsigalgs) * 2);
ADD_TEST(test_keylog);
#ifndef OPENSSL_NO_TLS1_3
ADD_TEST(test_keylog_no_master_key);
#endif
ADD_ALL_TESTS(test_early_data_read_write, 2);
ADD_ALL_TESTS(test_early_data_skip, 2);
ADD_ALL_TESTS(test_early_data_not_sent, 2);
ADD_ALL_TESTS(test_early_data_not_expected, 2);
ADD_ALL_TESTS(test_early_data_tls1_2, 2);
testresult = run_tests(argv[0]);