Ensure we use a non-zero time for tickets in early data
[openssl.git] / test / ssl_test.c
index 09141b2fedd6942ce9275d3f9472afe478a96dcd..eac86ccecf6e5174c351a10342f7fffe1bb230c8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -14,6 +14,9 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/provider.h>
+#ifndef OPENSSL_NO_QUIC
+#include <openssl/quic.h>
+#endif
 
 #include "helpers/handshake.h"
 #include "helpers/ssl_test_ctx.h"
@@ -409,12 +412,16 @@ static int test_handshake(int idx)
 #ifndef OPENSSL_NO_DTLS
     if (test_ctx->method == SSL_TEST_METHOD_DTLS) {
         server_ctx = SSL_CTX_new_ex(libctx, NULL, DTLS_server_method());
-        if (!TEST_true(SSL_CTX_set_max_proto_version(server_ctx, 0)))
+        if (!TEST_true(SSL_CTX_set_options(server_ctx,
+                        SSL_OP_ALLOW_CLIENT_RENEGOTIATION))
+                || !TEST_true(SSL_CTX_set_max_proto_version(server_ctx, 0)))
             goto err;
         if (test_ctx->extra.server.servername_callback !=
             SSL_TEST_SERVERNAME_CB_NONE) {
             if (!TEST_ptr(server2_ctx =
-                            SSL_CTX_new_ex(libctx, NULL, DTLS_server_method())))
+                            SSL_CTX_new_ex(libctx, NULL, DTLS_server_method()))
+                    || !TEST_true(SSL_CTX_set_options(server2_ctx,
+                            SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
                 goto err;
         }
         client_ctx = SSL_CTX_new_ex(libctx, NULL, DTLS_client_method());
@@ -423,7 +430,9 @@ static int test_handshake(int idx)
         if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {
             resume_server_ctx = SSL_CTX_new_ex(libctx, NULL,
                                                DTLS_server_method());
-            if (!TEST_true(SSL_CTX_set_max_proto_version(resume_server_ctx, 0)))
+            if (!TEST_true(SSL_CTX_set_max_proto_version(resume_server_ctx, 0))
+                    || !TEST_true(SSL_CTX_set_options(resume_server_ctx,
+                            SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
                 goto err;
             resume_client_ctx = SSL_CTX_new_ex(libctx, NULL,
                                                DTLS_client_method());
@@ -436,36 +445,76 @@ static int test_handshake(int idx)
     }
 #endif
     if (test_ctx->method == SSL_TEST_METHOD_TLS) {
+#if !defined(OPENSSL_NO_TLS1_3) \
+    && defined(OPENSSL_NO_EC) \
+    && defined(OPENSSL_NO_DH)
+        /* Without ec or dh there are no built-in groups for TLSv1.3 */
+        int maxversion = TLS1_2_VERSION;
+#else
+        int maxversion = 0;
+#endif
+
         server_ctx = SSL_CTX_new_ex(libctx, NULL, TLS_server_method());
-        if (!TEST_true(SSL_CTX_set_max_proto_version(server_ctx, 0)))
+        if (!TEST_true(SSL_CTX_set_max_proto_version(server_ctx, maxversion))
+                || !TEST_true(SSL_CTX_set_options(server_ctx,
+                            SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
             goto err;
         /* SNI on resumption isn't supported/tested yet. */
         if (test_ctx->extra.server.servername_callback !=
             SSL_TEST_SERVERNAME_CB_NONE) {
             if (!TEST_ptr(server2_ctx =
-                            SSL_CTX_new_ex(libctx, NULL, TLS_server_method())))
+                            SSL_CTX_new_ex(libctx, NULL, TLS_server_method()))
+                    || !TEST_true(SSL_CTX_set_options(server2_ctx,
+                            SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
                 goto err;
-            if (!TEST_true(SSL_CTX_set_max_proto_version(server2_ctx, 0)))
+            if (!TEST_true(SSL_CTX_set_max_proto_version(server2_ctx,
+                                                         maxversion)))
                 goto err;
         }
         client_ctx = SSL_CTX_new_ex(libctx, NULL, TLS_client_method());
-        if (!TEST_true(SSL_CTX_set_max_proto_version(client_ctx, 0)))
+        if (!TEST_true(SSL_CTX_set_max_proto_version(client_ctx, maxversion)))
             goto err;
 
         if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {
             resume_server_ctx = SSL_CTX_new_ex(libctx, NULL,
                                                TLS_server_method());
-            if (!TEST_true(SSL_CTX_set_max_proto_version(resume_server_ctx, 0)))
+            if (!TEST_true(SSL_CTX_set_max_proto_version(resume_server_ctx,
+                                                         maxversion))
+                    || !TEST_true(SSL_CTX_set_options(resume_server_ctx,
+                            SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
                 goto err;
             resume_client_ctx = SSL_CTX_new_ex(libctx, NULL,
                                                TLS_client_method());
-            if (!TEST_true(SSL_CTX_set_max_proto_version(resume_client_ctx, 0)))
+            if (!TEST_true(SSL_CTX_set_max_proto_version(resume_client_ctx,
+                                                         maxversion)))
                 goto err;
             if (!TEST_ptr(resume_server_ctx)
                     || !TEST_ptr(resume_client_ctx))
                 goto err;
         }
     }
+#ifndef OPENSSL_NO_QUIC
+    if (test_ctx->method == SSL_TEST_METHOD_QUIC) {
+        server_ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_server_method());
+        if (test_ctx->extra.server.servername_callback !=
+            SSL_TEST_SERVERNAME_CB_NONE) {
+            if (!TEST_ptr(server2_ctx =
+                            SSL_CTX_new_ex(libctx, NULL,
+                                           OSSL_QUIC_server_method())))
+                goto err;
+        }
+        client_ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
+        if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {
+            resume_server_ctx = SSL_CTX_new_ex(libctx, NULL,
+                                               OSSL_QUIC_server_method());
+            resume_client_ctx = SSL_CTX_new_ex(libctx, NULL,
+                                               OSSL_QUIC_client_method());
+            if (!TEST_ptr(resume_server_ctx)
+                    || !TEST_ptr(resume_client_ctx))
+                goto err;
+        }
+    }
+#endif
 
 #ifdef OPENSSL_NO_AUTOLOAD_CONFIG
     if (!TEST_true(OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL)))
@@ -530,7 +579,7 @@ int setup_tests(void)
         return 0;
     }
 
-    if (!test_get_libctx(&libctx, &defctxnull, &thisprov, 1, USAGE))
+    if (!test_arg_libctx(&libctx, &defctxnull, &thisprov, 1, USAGE))
         return 0;
 
     ADD_ALL_TESTS(test_handshake, (int)num_tests);