The branch master has been updated via bca7ad6efd0e1e828033cae2440d83322bf3dc01 (commit) from 5ea64b456b1a27ae046f23d632a968a7583bb9eb (commit)
- Log ----------------------------------------------------------------- commit bca7ad6efd0e1e828033cae2440d83322bf3dc01 Author: Dr. David von Oheimb <david.von.ohe...@siemens.com> Date: Sat Sep 26 15:21:48 2020 +0200 Use adapted test_get_libctx() for simpler test setup and better error reporting Reviewed-by: Paul Dale <paul.d...@oracle.com> (Merged from https://github.com/openssl/openssl/pull/13001) ----------------------------------------------------------------------- Summary of changes: test/acvp_test.c | 11 +------- test/build.info | 2 +- test/cmp_client_test.c | 2 +- test/cmp_msg_test.c | 2 +- test/cmp_protect_test.c | 2 +- test/cmp_server_test.c | 2 +- test/cmp_vfy_test.c | 2 +- test/evp_extra_test2.c | 8 +----- test/evp_libctx_test.c | 14 +---------- test/evp_test.c | 14 ++--------- test/ssl_old_test.c | 21 +++------------- test/ssl_test.c | 2 +- test/testutil.h | 6 +++-- test/testutil/provider.c | 65 +++++++++++++++++++++++++++--------------------- 14 files changed, 57 insertions(+), 96 deletions(-) diff --git a/test/acvp_test.c b/test/acvp_test.c index 1686d759db..5c4a38749f 100644 --- a/test/acvp_test.c +++ b/test/acvp_test.c @@ -1434,18 +1434,9 @@ int setup_tests(void) } } - 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)); diff --git a/test/build.info b/test/build.info index 0386a1febf..81f9b9cb66 100644 --- a/test/build.info +++ b/test/build.info @@ -706,7 +706,7 @@ IF[{- !$disabled{tests} -}] 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 diff --git a/test/cmp_client_test.c b/test/cmp_client_test.c index 17f932a73a..efb185402b 100644 --- a/test/cmp_client_test.c +++ b/test/cmp_client_test.c @@ -366,7 +366,7 @@ int setup_tests(void) 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)) diff --git a/test/cmp_msg_test.c b/test/cmp_msg_test.c index 41ba5cf975..0b56d66d45 100644 --- a/test/cmp_msg_test.c +++ b/test/cmp_msg_test.c @@ -561,7 +561,7 @@ int setup_tests(void) 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)) diff --git a/test/cmp_protect_test.c b/test/cmp_protect_test.c index 3cca30144d..d4acb716e7 100644 --- a/test/cmp_protect_test.c +++ b/test/cmp_protect_test.c @@ -538,7 +538,7 @@ int setup_tests(void) 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)) diff --git a/test/cmp_server_test.c b/test/cmp_server_test.c index 49108bfa17..bff42c8baf 100644 --- a/test/cmp_server_test.c +++ b/test/cmp_server_test.c @@ -145,7 +145,7 @@ int setup_tests(void) 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))) { diff --git a/test/cmp_vfy_test.c b/test/cmp_vfy_test.c index 67112f6489..d45c938335 100644 --- a/test/cmp_vfy_test.c +++ b/test/cmp_vfy_test.c @@ -600,7 +600,7 @@ int setup_tests(void) 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 */ diff --git a/test/evp_extra_test2.c b/test/evp_extra_test2.c index f91e66a08b..9181061247 100644 --- a/test/evp_extra_test2.c +++ b/test/evp_extra_test2.c @@ -272,13 +272,7 @@ static int test_d2i_PrivateKey_ex(void) { 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; diff --git a/test/evp_libctx_test.c b/test/evp_libctx_test.c index cf39bf0871..c306bd9a16 100644 --- a/test/evp_libctx_test.c +++ b/test/evp_libctx_test.c @@ -648,19 +648,7 @@ int setup_tests(void) } } - 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) diff --git a/test/evp_test.c b/test/evp_test.c index d4d60694d4..cc579ff310 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -3590,22 +3590,12 @@ int setup_tests(void) } /* + * 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) diff --git a/test/ssl_old_test.c b/test/ssl_old_test.c index 54b1ca4236..f63aa58b12 100644 --- a/test/ssl_old_test.c +++ b/test/ssl_old_test.c @@ -57,6 +57,7 @@ # include <openssl/ct.h> #endif #include <openssl/provider.h> +#include "testutil.h" /* * Or gethostname won't be declared properly @@ -103,7 +104,6 @@ static unsigned int psk_server_callback(SSL *ssl, const char *identity, unsigned int max_psk_len); #endif -static BIO *bio_err = NULL; static BIO *bio_stdout = NULL; #ifndef OPENSSL_NO_NEXTPROTONEG @@ -1344,22 +1344,9 @@ int main(int argc, char *argv[]) } #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); diff --git a/test/ssl_test.c b/test/ssl_test.c index 09141b2fed..042a05e453 100644 --- a/test/ssl_test.c +++ b/test/ssl_test.c @@ -530,7 +530,7 @@ int setup_tests(void) 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); diff --git a/test/testutil.h b/test/testutil.h index f1e3aae6fb..91e4d4bdd9 100644 --- a/test/testutil.h +++ b/test/testutil.h @@ -205,8 +205,10 @@ size_t test_get_argument_count(void); */ 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); /* diff --git a/test/testutil/provider.c b/test/testutil/provider.c index c7ff44c754..c50ef035fc 100644 --- a/test/testutil/provider.c +++ b/test/testutil/provider.c @@ -11,37 +11,31 @@ #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; @@ -49,3 +43,18 @@ int test_get_libctx(OSSL_LIB_CTX **libctx, 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); +}