From: Pauli Date: Wed, 2 Aug 2023 00:41:22 +0000 (+1000) Subject: PBE test: load providers if auto config load is turned off X-Git-Tag: openssl-3.1.3~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bb4f22076bd834bc0c75ca4ee95ffb91535658b;p=thirdparty%2Fopenssl.git PBE test: load providers if auto config load is turned off Reviewed-by: Matt Caswell Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/21621) (cherry picked from commit 52ea255d9d560513f69c3f7f3f21513a693c865c) --- diff --git a/test/pbetest.c b/test/pbetest.c index d73ae66fa53..7bf0680785d 100644 --- a/test/pbetest.c +++ b/test/pbetest.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #if !defined OPENSSL_NO_RC4 && !defined OPENSSL_NO_MD5 \ || !defined OPENSSL_NO_DES && !defined OPENSSL_NO_SHA1 @@ -123,8 +125,27 @@ static int test_pkcs5_pbe_des_sha1(void) } #endif +#ifdef OPENSSL_NO_AUTOLOAD_CONFIG +/* + * For configurations where we are not autoloading configuration, we need + * to access the legacy provider. The easiest way is to load both the + * legacy and default providers directly and unload them on termination. + */ +static OSSL_PROVIDER *legacy, *dflt; +#endif + int setup_tests(void) { +#ifdef OPENSSL_NO_AUTOLOAD_CONFIG + /* Load required providers if not done via configuration */ + legacy = OSSL_PROVIDER_load(NULL, "legacy"); + dflt = OSSL_PROVIDER_load(NULL, "default"); + if (!TEST_ptr(legacy) || !TEST_ptr(dflt)) { + cleanup_tests(); + return -1; + } +#endif + #if !defined OPENSSL_NO_RC4 && !defined OPENSSL_NO_MD5 ADD_TEST(test_pkcs5_pbe_rc4_md5); #endif @@ -134,3 +155,13 @@ int setup_tests(void) return 1; } + +#ifdef OPENSSL_NO_AUTOLOAD_CONFIG +void cleanup_tests(void) +{ + /* Dispose of providers */ + OSSL_PROVIDER_unload(legacy); + OSSL_PROVIDER_unload(dflt); + legacy = dflt = NULL; +} +#endif