Skip to content

Commit

Permalink
PBE test: load providers if auto config load is turned off
Browse files Browse the repository at this point in the history
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #21621)

(cherry picked from commit 52ea255)
  • Loading branch information
paulidale committed Aug 4, 2023
1 parent 47429d9 commit 7bb4f22
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/pbetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <openssl/x509.h>
#include <openssl/rc4.h>
#include <openssl/md5.h>
#include <openssl/configuration.h>
#include <openssl/provider.h>

#if !defined OPENSSL_NO_RC4 && !defined OPENSSL_NO_MD5 \
|| !defined OPENSSL_NO_DES && !defined OPENSSL_NO_SHA1
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 7bb4f22

Please sign in to comment.