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() */
20 OSSL_PROVIDER *defctxlegacy = NULL;
23 static int test_different_libctx(void)
25 SSL_CTX *cctx = NULL, *sctx = NULL;
26 SSL *clientssl = NULL, *serverssl = NULL;
28 OPENSSL_CTX *libctx = OPENSSL_CTX_new();
30 /* TODO(3.0): Re-enable this code. See comment in setup_tests() */
32 /* Verify that the default provider in the default libctx is not available */
33 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default")))
37 cctx = SSL_CTX_new_with_libctx(libctx, NULL, TLS_client_method());
40 sctx = SSL_CTX_new_with_libctx(libctx, NULL, TLS_server_method());
44 if (!TEST_true(create_ssl_ctx_pair(NULL,
48 &sctx, NULL, cert, privkey)))
51 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
55 /* This time we expect success */
56 if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
59 /* TODO(3.0): Re-enable this code. See comment in setup_tests() */
62 * Verify that the default provider in the default libctx is still not
65 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default")))
77 OPENSSL_CTX_free(libctx);
84 char *certsdir = NULL;
86 * TODO(3.0): Re-enable this code when key generation is provider aware. At
87 * the moment the below causes the tests to fail because libssl attempts to
88 * generate a key for the key_share, which ultimately invokes RAND_bytes().
89 * However, because key generation is not yet provider aware it just uses
90 * the default library context - and hence fails.
94 * For tests in this file we want to ensure the default ctx does not have
95 * the default provider loaded into the default ctx. So we load "legacy" to
96 * prevent default from being auto-loaded. This tests that there is no
97 * "leakage", i.e. when using SSL_CTX_new_with_libctx() we expect only the
98 * specific libctx to be used - nothing should fall back to the default
101 defctxlegacy = OSSL_PROVIDER_load(NULL, "legacy");
104 if (!TEST_ptr(certsdir = test_get_argument(0)))
107 cert = test_mk_file_path(certsdir, "servercert.pem");
111 privkey = test_mk_file_path(certsdir, "serverkey.pem");
112 if (privkey == NULL) {
117 ADD_TEST(test_different_libctx);
122 void cleanup_tests(void)
124 /* TODO(3.0): Re-enable this code. See comment in setup_tests() */
126 OSSL_PROVIDER_unload(defctxlegacy);