PBE test: load providers if auto config load is turned off
authorPauli <pauli@openssl.org>
Wed, 2 Aug 2023 00:41:22 +0000 (10:41 +1000)
committerPauli <pauli@openssl.org>
Fri, 4 Aug 2023 01:58:32 +0000 (11:58 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/21621)

(cherry picked from commit 52ea255d9d560513f69c3f7f3f21513a693c865c)

test/pbetest.c

index d73ae66fa536afb517bea61e85331bf7384845b1..7bf0680785d80e76fd89215d092ba661e598c606 100644 (file)
@@ -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
@@ -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