2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/provider.h>
12 #include "ssltestlib.h"
15 static char *cert = NULL;
16 static char *privkey = NULL;
18 /* TODO(3.0): Re-enable this code. See comment in setup_tests() */
19 OSSL_PROVIDER *defctxlegacy = NULL;
21 static int test_different_libctx(void)
23 SSL_CTX *cctx = NULL, *sctx = NULL;
24 SSL *clientssl = NULL, *serverssl = NULL;
26 OPENSSL_CTX *libctx = OPENSSL_CTX_new();
28 /* Verify that the default provider in the default libctx is not available */
29 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default")))
32 cctx = SSL_CTX_new_with_libctx(libctx, NULL, TLS_client_method());
35 sctx = SSL_CTX_new_with_libctx(libctx, NULL, TLS_server_method());
40 * TODO(3.0): Make this work in TLSv1.3. Currently we can only do RSA key
41 * exchange, because we don't have key gen/param gen for EC yet - which
42 * implies TLSv1.2 only
44 if (!TEST_true(create_ssl_ctx_pair(NULL,
48 &sctx, &cctx, cert, privkey)))
51 /* Ensure we use a FIPS compatible ciphersuite and sigalg */
52 if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA256"))
53 || !TEST_true(SSL_CTX_set1_sigalgs_list(cctx, "RSA+SHA256")))
56 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
60 /* This time we expect success */
61 if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
65 * Verify that the default provider in the default libctx is still not
68 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default")))
79 OPENSSL_CTX_free(libctx);
86 char *certsdir = NULL;
88 * For tests in this file we want to ensure the default ctx does not have
89 * the default provider loaded into the default ctx. So we load "legacy" to
90 * prevent default from being auto-loaded. This tests that there is no
91 * "leakage", i.e. when using SSL_CTX_new_with_libctx() we expect only the
92 * specific libctx to be used - nothing should fall back to the default
95 defctxlegacy = OSSL_PROVIDER_load(NULL, "legacy");
97 if (!TEST_ptr(certsdir = test_get_argument(0)))
100 cert = test_mk_file_path(certsdir, "servercert.pem");
104 privkey = test_mk_file_path(certsdir, "serverkey.pem");
105 if (privkey == NULL) {
110 ADD_TEST(test_different_libctx);
115 void cleanup_tests(void)
117 /* TODO(3.0): Re-enable this code. See comment in setup_tests() */
118 OSSL_PROVIDER_unload(defctxlegacy);