From: Matt Caswell Date: Fri, 16 Mar 2018 09:53:38 +0000 (+0000) Subject: Add a test for 0RTT replay protection X-Git-Tag: OpenSSL_1_1_1-pre3~36 X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff_plain;h=78fb5374e1cc0f1f1d49055150e5415727b155a7;hp=66d7de163491bfa5819fb80b77d321beb58384d4 Add a test for 0RTT replay protection Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/5644) --- diff --git a/test/sslapitest.c b/test/sslapitest.c index 29eb2f8260..64f10cc192 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -1858,6 +1858,58 @@ static int test_early_data_read_write(int idx) return testresult; } +static int test_early_data_replay(int idx) +{ + SSL_CTX *cctx = NULL, *sctx = NULL; + SSL *clientssl = NULL, *serverssl = NULL; + int testresult = 0; + SSL_SESSION *sess = NULL; + + if (!TEST_true(setupearly_data_test(&cctx, &sctx, &clientssl, + &serverssl, &sess, idx))) + goto end; + + /* + * The server is configured to accept early data. Create a connection to + * "use up" the ticket + */ + if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)) + || !TEST_true(SSL_session_reused(clientssl))) + goto end; + + SSL_shutdown(clientssl); + SSL_shutdown(serverssl); + SSL_free(serverssl); + SSL_free(clientssl); + serverssl = clientssl = NULL; + + if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, + &clientssl, NULL, NULL)) + || !TEST_true(SSL_set_session(clientssl, sess)) + || !TEST_true(create_ssl_connection(serverssl, clientssl, + SSL_ERROR_NONE)) + /* + * This time we should not have resumed the session because we + * already used it once. + */ + || !TEST_false(SSL_session_reused(clientssl))) + goto end; + + testresult = 1; + + end: + if (sess != clientpsk) + SSL_SESSION_free(sess); + SSL_SESSION_free(clientpsk); + SSL_SESSION_free(serverpsk); + clientpsk = serverpsk = NULL; + SSL_free(serverssl); + SSL_free(clientssl); + SSL_CTX_free(sctx); + SSL_CTX_free(cctx); + return testresult; +} + /* * Helper function to test that a server attempting to read early data can * handle a connection from a client where the early data should be skipped. @@ -3688,6 +3740,11 @@ int setup_tests(void) #endif #ifndef OPENSSL_NO_TLS1_3 ADD_ALL_TESTS(test_early_data_read_write, 3); + /* + * We don't do replay tests for external PSK. Replay protection isn't used + * in that scenario. + */ + ADD_ALL_TESTS(test_early_data_replay, 2); ADD_ALL_TESTS(test_early_data_skip, 3); ADD_ALL_TESTS(test_early_data_skip_hrr, 3); ADD_ALL_TESTS(test_early_data_not_sent, 3);