}
}
- prov_null = OSSL_PROVIDER_load(NULL, "null");
- if (prov_null == NULL) {
- opt_printf_stderr("Failed to load null provider into default libctx\n");
+ if (!test_get_libctx(&libctx, &prov_null, config_file, NULL, NULL))
return 0;
- }
- libctx = OSSL_LIB_CTX_new();
- if (libctx == NULL
- || !OSSL_LIB_CTX_load_config(libctx, config_file)) {
- opt_printf_stderr("Failed to load config\n");
- return 0;
- }
OSSL_SELF_TEST_set_callback(libctx, self_test_events, &self_test_args);
ADD_ALL_TESTS(cipher_enc_dec_test, OSSL_NELEM(cipher_enc_data));
SOURCE[ssl_old_test]=ssl_old_test.c helpers/predefined_dhparams.c
INCLUDE[ssl_old_test]=.. ../include ../apps/include
- DEPEND[ssl_old_test]=../libcrypto.a ../libssl.a
+ DEPEND[ssl_old_test]=../libcrypto.a ../libssl.a libtestutil.a
ENDIF
PROGRAMS{noinst}=asn1_time_test
return 0;
}
- if (!test_get_libctx(&libctx, &default_null_provider, &provider, 5, USAGE))
+ if (!test_arg_libctx(&libctx, &default_null_provider, &provider, 5, USAGE))
return 0;
if (!TEST_ptr(server_key = load_pem_key(server_key_f, libctx))
return 0;
}
- if (!test_get_libctx(&libctx, &default_null_provider, &provider, 3, USAGE))
+ if (!test_arg_libctx(&libctx, &default_null_provider, &provider, 3, USAGE))
return 0;
if (!TEST_ptr(newkey = load_pem_key(newkey_f, libctx))
return 0;
}
- if (!test_get_libctx(&libctx, &default_null_provider, &provider, 10, USAGE))
+ if (!test_arg_libctx(&libctx, &default_null_provider, &provider, 10, USAGE))
return 0;
if (!TEST_ptr(loadedkey = load_pem_key(server_key_f, libctx))
return 0;
}
- if (!test_get_libctx(&libctx, &default_null_provider, &provider, 1, USAGE))
+ if (!test_arg_libctx(&libctx, &default_null_provider, &provider, 1, USAGE))
return 0;
if (!TEST_ptr(request = load_pkimsg(request_f))) {
return 0;
}
- if (!test_get_libctx(&libctx, &default_null_provider, &provider, 14, USAGE))
+ if (!test_arg_libctx(&libctx, &default_null_provider, &provider, 14, USAGE))
return 0;
/* Load certificates for cert chain */
int setup_tests(void)
{
- mainctx = OSSL_LIB_CTX_new();
-
- if (!TEST_ptr(mainctx))
- return 0;
-
- nullprov = OSSL_PROVIDER_load(NULL, "null");
- if (!TEST_ptr(nullprov)) {
+ if (!test_get_libctx(&mainctx, &nullprov, NULL, NULL, NULL)) {
OSSL_LIB_CTX_free(mainctx);
mainctx = NULL;
return 0;
}
}
- nullprov = OSSL_PROVIDER_load(NULL, "null");
- if (!TEST_ptr(nullprov))
- return 0;
-
- libctx = OSSL_LIB_CTX_new();
- if (!TEST_ptr(libctx))
- return 0;
- if (config_file != NULL
- && !TEST_true(OSSL_LIB_CTX_load_config(libctx, config_file)))
- return 0;
-
- libprov = OSSL_PROVIDER_load(libctx, prov_name);
- if (!TEST_ptr(libprov))
+ if (!test_get_libctx(&libctx, &nullprov, config_file, &libprov, prov_name))
return 0;
#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DH)
}
/*
+ * Load the provider via configuration into the created library context.
* Load the 'null' provider into the default library context to ensure that
* the the tests do not fallback to using the default provider.
*/
- prov_null = OSSL_PROVIDER_load(NULL, "null");
- if (prov_null == NULL) {
- opt_printf_stderr("Failed to load null provider into default libctx\n");
+ if (!test_get_libctx(&libctx, &prov_null, config_file, NULL, NULL))
return 0;
- }
-
- /* load the provider via configuration into the created library context */
- libctx = OSSL_LIB_CTX_new();
- if (libctx == NULL
- || !OSSL_LIB_CTX_load_config(libctx, config_file)) {
- TEST_error("Failed to load config %s\n", config_file);
- return 0;
- }
n = test_get_argument_count();
if (n == 0)
# include <openssl/ct.h>
#endif
#include <openssl/provider.h>
+#include "testutil.h"
/*
* Or gethostname won't be declared properly
unsigned int max_psk_len);
#endif
-static BIO *bio_err = NULL;
static BIO *bio_stdout = NULL;
#ifndef OPENSSL_NO_NEXTPROTONEG
}
#endif
- if (provider != NULL) {
- defctxnull = OSSL_PROVIDER_load(NULL, "null");
- if (defctxnull == NULL)
- goto end;
- libctx = OSSL_LIB_CTX_new();
- if (libctx == NULL)
- goto end;
-
- if (config != NULL
- && !OSSL_LIB_CTX_load_config(libctx, config))
- goto end;
-
- thisprov = OSSL_PROVIDER_load(libctx, provider);
- if (thisprov == NULL)
- goto end;
- }
+ if (provider != NULL
+ && !test_get_libctx(&libctx, &defctxnull, config, &thisprov, provider))
+ goto end;
c_ctx = SSL_CTX_new_ex(libctx, NULL, meth);
s_ctx = SSL_CTX_new_ex(libctx, NULL, meth);
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);
*/
int test_skip_common_options(void);
-int test_get_libctx(OSSL_LIB_CTX **libctx,
- OSSL_PROVIDER **default_null_provider,
+int test_get_libctx(OSSL_LIB_CTX **libctx, OSSL_PROVIDER **default_null_prov,
+ const char *config_file,
+ OSSL_PROVIDER **provider, const char *module_name);
+int test_arg_libctx(OSSL_LIB_CTX **libctx, OSSL_PROVIDER **default_null_prov,
OSSL_PROVIDER **provider, int argn, const char *usage);
/*
#include <openssl/provider.h>
#include <string.h>
-int test_get_libctx(OSSL_LIB_CTX **libctx,
- OSSL_PROVIDER **default_null_provider,
- OSSL_PROVIDER **provider, int argn, const char *usage)
+int test_get_libctx(OSSL_LIB_CTX **libctx, OSSL_PROVIDER **default_null_prov,
+ const char *config_file,
+ OSSL_PROVIDER **provider, const char *module_name)
{
- const char *module_name;
+ if ((*libctx = OSSL_LIB_CTX_new()) == NULL) {
+ opt_printf_stderr("Failed to create libctx\n");
+ goto err;
+ }
- if (!TEST_ptr(module_name = test_get_argument(argn))) {
- TEST_error("usage: <prog> %s", usage);
- return 0;
+ if (default_null_prov != NULL
+ && (*default_null_prov = OSSL_PROVIDER_load(NULL, "null")) == NULL) {
+ opt_printf_stderr("Failed to load null provider into default libctx\n");
+ goto err;
}
- if (strcmp(module_name, "none") != 0) {
- const char *config_fname = test_get_argument(argn + 1);
-
- *default_null_provider = OSSL_PROVIDER_load(NULL, "null");
- *libctx = OSSL_LIB_CTX_new();
- if (!TEST_ptr(*libctx)) {
- TEST_error("Failed to create libctx\n");
- goto err;
- }
-
- if (config_fname != NULL
- && !TEST_true(OSSL_LIB_CTX_load_config(*libctx, config_fname))) {
- TEST_error("Error loading config file %s\n", config_fname);
- goto err;
- }
-
- *provider = OSSL_PROVIDER_load(*libctx, module_name);
- if (!TEST_ptr(*provider)) {
- TEST_error("Failed to load provider %s\n", module_name);
- goto err;
- }
+
+ if (config_file != NULL
+ && !OSSL_LIB_CTX_load_config(*libctx, config_file)) {
+ opt_printf_stderr("Error loading config from file %s\n", config_file);
+ goto err;
+ }
+
+ if (module_name != NULL
+ && (*provider = OSSL_PROVIDER_load(*libctx, module_name)) == NULL) {
+ opt_printf_stderr("Failed to load provider %s\n", module_name);
+ goto err;
}
return 1;
ERR_print_errors_fp(stderr);
return 0;
}
+
+int test_arg_libctx(OSSL_LIB_CTX **libctx, OSSL_PROVIDER **default_null_prov,
+ OSSL_PROVIDER **provider, int argn, const char *usage)
+{
+ const char *module_name;
+
+ if (!TEST_ptr(module_name = test_get_argument(argn))) {
+ TEST_error("usage: <prog> %s", usage);
+ return 0;
+ }
+ if (strcmp(module_name, "none") == 0)
+ return 1;
+ return test_get_libctx(libctx, default_null_prov,
+ test_get_argument(argn + 1), provider, module_name);
+}