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
11 #include <openssl/provider.h>
13 #include "ssltestlib.h"
16 static char *cert = NULL;
17 static char *privkey = NULL;
18 static char *modulename = NULL;
19 static char *configfile = NULL;
21 static 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();
29 OSSL_PROVIDER *prov = NULL;
32 * Verify that the default and fips providers in the default libctx are not
35 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default"))
36 || !TEST_false(OSSL_PROVIDER_available(NULL, "fips")))
39 if (!TEST_true(OPENSSL_CTX_load_config(libctx, configfile)))
42 prov = OSSL_PROVIDER_load(libctx, modulename);
44 /* Check we have the provider available */
45 || !TEST_true(OSSL_PROVIDER_available(libctx, modulename)))
47 /* Check the default provider is not available */
48 if (strcmp(modulename, "default") != 0
49 && !TEST_false(OSSL_PROVIDER_available(libctx, "default")))
51 TEST_note("%s provider loaded", modulename);
54 * TODO(3.0): Make this work in TLSv1.3. Currently we can only do RSA key
55 * exchange, because we don't have key gen/param gen for EC yet - which
56 * implies TLSv1.2 only
58 if (!TEST_true(create_ssl_ctx_pair(libctx,
63 &sctx, &cctx, cert, privkey)))
66 /* Ensure we use a FIPS compatible ciphersuite and sigalg */
67 if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA256"))
68 || !TEST_true(SSL_CTX_set1_sigalgs_list(cctx, "RSA+SHA256")))
71 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
75 /* This time we expect success */
76 if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
80 * Verify that the default and fips providers in the default libctx are
83 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default"))
84 || !TEST_false(OSSL_PROVIDER_available(NULL, "fips")))
95 OSSL_PROVIDER_unload(prov);
96 OPENSSL_CTX_free(libctx);
101 int setup_tests(void)
103 char *certsdir = NULL;
105 if (!test_skip_common_options()) {
106 TEST_error("Error parsing test options\n");
110 if (!TEST_ptr(certsdir = test_get_argument(0))
111 || !TEST_ptr(modulename = test_get_argument(1))
112 || !TEST_ptr(configfile = test_get_argument(2)))
115 cert = test_mk_file_path(certsdir, "servercert.pem");
119 privkey = test_mk_file_path(certsdir, "serverkey.pem");
120 if (privkey == NULL) {
126 * For tests in this file we want to ensure the default ctx does not have
127 * the default provider loaded into the default ctx. So we load "legacy" to
128 * prevent default from being auto-loaded. This tests that there is no
129 * "leakage", i.e. when using SSL_CTX_new_with_libctx() we expect only the
130 * specific libctx to be used - nothing should fall back to the default
133 defctxlegacy = OSSL_PROVIDER_load(NULL, "legacy");
135 ADD_TEST(test_different_libctx);
140 void cleanup_tests(void)
142 OSSL_PROVIDER_unload(defctxlegacy);