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);
53 cctx = SSL_CTX_new_with_libctx(libctx, NULL, TLS_client_method());
56 sctx = SSL_CTX_new_with_libctx(libctx, NULL, TLS_server_method());
61 * TODO(3.0): Make this work in TLSv1.3. Currently we can only do RSA key
62 * exchange, because we don't have key gen/param gen for EC yet - which
63 * implies TLSv1.2 only
65 if (!TEST_true(create_ssl_ctx_pair(NULL,
69 &sctx, &cctx, cert, privkey)))
72 /* Ensure we use a FIPS compatible ciphersuite and sigalg */
73 if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA256"))
74 || !TEST_true(SSL_CTX_set1_sigalgs_list(cctx, "RSA+SHA256")))
77 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
81 /* This time we expect success */
82 if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
86 * Verify that the default and fips providers in the default libctx are
89 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default"))
90 || !TEST_false(OSSL_PROVIDER_available(NULL, "fips")))
101 OSSL_PROVIDER_unload(prov);
102 OPENSSL_CTX_free(libctx);
107 int setup_tests(void)
109 char *certsdir = NULL;
111 if (!test_skip_common_options()) {
112 TEST_error("Error parsing test options\n");
116 if (!TEST_ptr(certsdir = test_get_argument(0))
117 || !TEST_ptr(modulename = test_get_argument(1))
118 || !TEST_ptr(configfile = test_get_argument(2)))
121 cert = test_mk_file_path(certsdir, "servercert.pem");
125 privkey = test_mk_file_path(certsdir, "serverkey.pem");
126 if (privkey == NULL) {
132 * For tests in this file we want to ensure the default ctx does not have
133 * the default provider loaded into the default ctx. So we load "legacy" to
134 * prevent default from being auto-loaded. This tests that there is no
135 * "leakage", i.e. when using SSL_CTX_new_with_libctx() we expect only the
136 * specific libctx to be used - nothing should fall back to the default
139 defctxlegacy = OSSL_PROVIDER_load(NULL, "legacy");
141 ADD_TEST(test_different_libctx);
146 void cleanup_tests(void)
148 OSSL_PROVIDER_unload(defctxlegacy);