aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssl/test/quicapitest.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssl/test/quicapitest.c')
-rw-r--r--crypto/openssl/test/quicapitest.c152
1 files changed, 66 insertions, 86 deletions
diff --git a/crypto/openssl/test/quicapitest.c b/crypto/openssl/test/quicapitest.c
index b98a94055301..4e887c13d14c 100644
--- a/crypto/openssl/test/quicapitest.c
+++ b/crypto/openssl/test/quicapitest.c
@@ -428,91 +428,6 @@ static int test_version(void)
}
#if defined(DO_SSL_TRACE_TEST)
-static void strip_line_ends(char *str)
-{
- size_t i;
-
- for (i = strlen(str);
- i > 0 && (str[i - 1] == '\n' || str[i - 1] == '\r');
- i--);
-
- str[i] = '\0';
-}
-
-static int compare_with_file(BIO *membio)
-{
- BIO *file = NULL, *newfile = NULL;
- char buf1[8192], buf2[8192];
- char *reffile;
- int ret = 0;
- size_t i;
-
-#ifdef OPENSSL_NO_ZLIB
- reffile = test_mk_file_path(datadir, "ssltraceref.txt");
-#else
- reffile = test_mk_file_path(datadir, "ssltraceref-zlib.txt");
-#endif
- if (!TEST_ptr(reffile))
- goto err;
-
- file = BIO_new_file(reffile, "rb");
- if (!TEST_ptr(file))
- goto err;
-
- newfile = BIO_new_file("ssltraceref-new.txt", "wb");
- if (!TEST_ptr(newfile))
- goto err;
-
- while (BIO_gets(membio, buf2, sizeof(buf2)) > 0)
- if (BIO_puts(newfile, buf2) <= 0) {
- TEST_error("Failed writing new file data");
- goto err;
- }
-
- if (!TEST_int_ge(BIO_seek(membio, 0), 0))
- goto err;
-
- while (BIO_gets(file, buf1, sizeof(buf1)) > 0) {
- size_t line_len;
-
- if (BIO_gets(membio, buf2, sizeof(buf2)) <= 0) {
- TEST_error("Failed reading mem data");
- goto err;
- }
- strip_line_ends(buf1);
- strip_line_ends(buf2);
- line_len = strlen(buf1);
- if (line_len > 0 && buf1[line_len - 1] == '?') {
- /* Wildcard at the EOL means ignore anything after it */
- if (strlen(buf2) > line_len)
- buf2[line_len] = '\0';
- }
- if (line_len != strlen(buf2)) {
- TEST_error("Actual and ref line data length mismatch");
- TEST_info("%s", buf1);
- TEST_info("%s", buf2);
- goto err;
- }
- for (i = 0; i < line_len; i++) {
- /* '?' is a wild card character in the reference text */
- if (buf1[i] == '?')
- buf2[i] = '?';
- }
- if (!TEST_str_eq(buf1, buf2))
- goto err;
- }
- if (!TEST_true(BIO_eof(file))
- || !TEST_true(BIO_eof(membio)))
- goto err;
-
- ret = 1;
- err:
- OPENSSL_free(reffile);
- BIO_free(file);
- BIO_free(newfile);
- return ret;
-}
-
/*
* Tests that the SSL_trace() msg_callback works as expected with a QUIC
* connection. This also provides testing of the msg_callback at the same time.
@@ -524,6 +439,7 @@ static int test_ssl_trace(void)
QUIC_TSERVER *qtserv = NULL;
int testresult = 0;
BIO *bio = NULL;
+ char *reffile = NULL;
if (!TEST_ptr(cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method()))
|| !TEST_ptr(bio = BIO_new(BIO_s_mem()))
@@ -547,7 +463,13 @@ static int test_ssl_trace(void)
if (!TEST_int_gt(BIO_pending(bio), 0))
goto err;
} else {
- if (!TEST_true(compare_with_file(bio)))
+
+# ifdef OPENSSL_NO_ZLIB
+ reffile = test_mk_file_path(datadir, "ssltraceref.txt");
+# else
+ reffile = test_mk_file_path(datadir, "ssltraceref-zlib.txt");
+# endif
+ if (!TEST_true(compare_with_reference_file(bio, reffile)))
goto err;
}
@@ -557,6 +479,7 @@ static int test_ssl_trace(void)
SSL_free(clientquic);
SSL_CTX_free(cctx);
BIO_free(bio);
+ OPENSSL_free(reffile);
return testresult;
}
@@ -2863,6 +2786,62 @@ static int test_ssl_set_verify(void)
return testresult;
}
+/*
+ * When the server has a different primary group than the client, the server
+ * should not fail on the client hello retry.
+ */
+static int test_client_hello_retry(void)
+{
+#if !defined(OPENSSL_NO_EC) && !defined(OPENSSL_NO_ECX)
+ SSL_CTX *cctx = NULL, *sctx = NULL;
+ SSL *clientssl = NULL, *serverssl = NULL, *qlistener = NULL;
+ int testresult = 0, i = 0, ret = 0;
+
+ if (!TEST_ptr(sctx = create_server_ctx())
+ || !TEST_ptr(cctx = create_client_ctx()))
+ goto err;
+ /*
+ * set the specific groups for the test
+ */
+ if (!TEST_true(SSL_CTX_set1_groups_list(cctx, "secp384r1:secp256r1")))
+ goto err;
+ if (!TEST_true(SSL_CTX_set1_groups_list(sctx, "secp256r1")))
+ goto err;
+
+ if (!create_quic_ssl_objects(sctx, cctx, &qlistener, &clientssl))
+ goto err;
+
+ /* Send ClientHello and server retry */
+ for (i = 0; i < 2; i++) {
+ ret = SSL_connect(clientssl);
+ if (!TEST_int_le(ret, 0)
+ || !TEST_int_eq(SSL_get_error(clientssl, ret), SSL_ERROR_WANT_READ))
+ goto err;
+ SSL_handle_events(qlistener);
+ }
+
+ /* We expect a server SSL object which has not yet completed its handshake */
+ serverssl = SSL_accept_connection(qlistener, 0);
+
+ /* Call SSL_accept() and SSL_connect() until we are connected */
+ if (!TEST_true(create_bare_ssl_connection(serverssl, clientssl,
+ SSL_ERROR_NONE, 0, 0)))
+ goto err;
+
+ testresult = 1;
+
+err:
+ SSL_CTX_free(cctx);
+ SSL_CTX_free(sctx);
+ SSL_free(clientssl);
+ SSL_free(serverssl);
+ SSL_free(qlistener);
+
+ return testresult;
+#else
+ return TEST_skip("EC(X) keys are not supported in this build");
+#endif
+}
/***********************************************************************************/
OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n")
@@ -2964,6 +2943,7 @@ int setup_tests(void)
ADD_TEST(test_server_method_with_ssl_new);
ADD_TEST(test_ssl_accept_connection);
ADD_TEST(test_ssl_set_verify);
+ ADD_TEST(test_client_hello_retry);
return 1;
err:
cleanup_tests();