]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Merge ossl_provider_activate() and ossl_provider_activate_child()
authorMatt Caswell <matt@openssl.org>
Mon, 21 Jun 2021 11:08:39 +0000 (12:08 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 24 Jun 2021 13:48:14 +0000 (14:48 +0100)
These 2 functions have become so close to each other that they may as well
be just one function.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15854)

crypto/provider.c
crypto/provider_child.c
crypto/provider_conf.c
crypto/provider_core.c
include/internal/provider.h
test/provider_internal_test.c

index f5dbc4f94a4fa8f89ab585e6e2af7794c19d05e9..6b5b7beefec4fdfb8129656d5bab1efc5e4efe6a 100644 (file)
@@ -26,7 +26,7 @@ OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name,
         isnew = 1;
     }
 
-    if (!ossl_provider_activate(prov, 1)) {
+    if (!ossl_provider_activate(prov, 1, 0)) {
         ossl_provider_free(prov);
         return NULL;
     }
index b077e95ffcbc0892a9f79a36c1f7fc77fe54e85b..3cad1c564f46cf46fe2e4281e909b7ff5c8d9f4a 100644 (file)
@@ -137,7 +137,7 @@ static int provider_create_child_cb(const OSSL_CORE_HANDLE *prov, void *cbdata)
          * or it could have been explicitly loaded. If explicitly loaded we
          * ignore it - i.e. we don't start treating it like a child.
          */
-        if (!ossl_provider_activate_child(cprov, prov, ossl_child_provider_init))
+        if (!ossl_provider_activate(cprov, 0, 1))
             goto err;
     } else {
         /*
@@ -148,7 +148,7 @@ static int provider_create_child_cb(const OSSL_CORE_HANDLE *prov, void *cbdata)
                                        1)) == NULL)
             goto err;
 
-        if (!ossl_provider_activate(cprov, 0))
+        if (!ossl_provider_activate(cprov, 0, 0))
             goto err;
 
         if (!ossl_provider_set_child(cprov, prov)
index 1e59e959e3af75a6f456a5f9bcef06ef73e0f3ef..398340c3d2b5e6afa9c01c5423cc064390110f8d 100644 (file)
@@ -171,7 +171,7 @@ static int provider_conf_load(OSSL_LIB_CTX *libctx, const char *name,
         ok = provider_conf_params(prov, NULL, NULL, value, cnf);
 
         if (ok) {
-            if (!ossl_provider_activate(prov, 1)) {
+            if (!ossl_provider_activate(prov, 1, 0)) {
                 ok = 0;
             } else if (!ossl_provider_add_to_store(prov, 0)) {
                 ossl_provider_deactivate(prov);
index 83c6bf28f052ea1b5d6f756e08c2dc454ad4d166..e41c49e0ad2631dbf8d91e65c674e2fc050e9a01 100644 (file)
@@ -431,7 +431,7 @@ int ossl_provider_up_ref(OSSL_PROVIDER *prov)
 static int provider_up_ref_intern(OSSL_PROVIDER *prov, int activate)
 {
     if (activate)
-        return ossl_provider_activate(prov, 1);
+        return ossl_provider_activate(prov, 1, 0);
 
     return ossl_provider_up_ref(prov);
 }
@@ -1027,12 +1027,20 @@ static int provider_flush_store_cache(const OSSL_PROVIDER *prov)
     return 1;
 }
 
-int ossl_provider_activate(OSSL_PROVIDER *prov, int upcalls)
+int ossl_provider_activate(OSSL_PROVIDER *prov, int upcalls, int aschild)
 {
     int count;
 
     if (prov == NULL)
         return 0;
+#ifndef FIPS_MODULE
+    /*
+     * If aschild is true, then we only actually do the activation if the
+     * provider is a child. If its not, this is still success.
+     */
+    if (aschild && !prov->ischild)
+        return 1;
+#endif
     if ((count = provider_activate(prov, 1, upcalls)) > 0)
         return count == 1 ? provider_flush_store_cache(prov) : 1;
 
@@ -1462,39 +1470,6 @@ int ossl_provider_set_child(OSSL_PROVIDER *prov, const OSSL_CORE_HANDLE *handle)
     return 1;
 }
 
-int ossl_provider_activate_child(OSSL_PROVIDER *prov,
-                                 const OSSL_CORE_HANDLE *handle,
-                                 OSSL_provider_init_fn *init_function)
-{
-    int flush = 0;
-
-    if (!CRYPTO_THREAD_write_lock(prov->store->lock))
-        return 0;
-    if (!CRYPTO_THREAD_write_lock(prov->flag_lock)) {
-        CRYPTO_THREAD_unlock(prov->store->lock);
-        return 0;
-    }
-    /*
-     * The provider could be in one of two states: (1) Already a child,
-     * (2) Not a child (not eligible to be one).
-     */
-    if (prov->ischild && provider_activate(prov, 0, 0))
-        flush = 1;
-
-    CRYPTO_THREAD_unlock(prov->flag_lock);
-    CRYPTO_THREAD_unlock(prov->store->lock);
-
-    if (flush)
-        provider_flush_store_cache(prov);
-
-    /*
-     * We report success whether or not the provider was a child. If its not
-     * a child then it has been explicitly loaded as a non child provider and
-     * we should keep it like that.
-     */
-    return 1;
-}
-
 int ossl_provider_default_props_update(OSSL_LIB_CTX *libctx, const char *props)
 {
 #ifndef FIPS_MODULE
index b6e413f7a4108d53d1ab519ccb09f722a28dae27..9b1d9495ddad8a506455cb279f28c7a426aee65b 100644 (file)
@@ -44,9 +44,6 @@ int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
 
 int ossl_provider_is_child(const OSSL_PROVIDER *prov);
 int ossl_provider_set_child(OSSL_PROVIDER *prov, const OSSL_CORE_HANDLE *handle);
-int ossl_provider_activate_child(OSSL_PROVIDER *prov,
-                                 const OSSL_CORE_HANDLE *handle,
-                                 OSSL_provider_init_fn *init_function);
 const OSSL_CORE_HANDLE *ossl_provider_get_parent(OSSL_PROVIDER *prov);
 int ossl_provider_up_ref_parent(OSSL_PROVIDER *prov, int activate);
 int ossl_provider_free_parent(OSSL_PROVIDER *prov, int deactivate);
@@ -59,7 +56,7 @@ int ossl_provider_disable_fallback_loading(OSSL_LIB_CTX *libctx);
  * Activate the Provider
  * If the Provider is a module, the module will be loaded
  */
-int ossl_provider_activate(OSSL_PROVIDER *prov, int upcalls);
+int ossl_provider_activate(OSSL_PROVIDER *prov, int upcalls, int aschild);
 int ossl_provider_deactivate(OSSL_PROVIDER *prov);
 int ossl_provider_add_to_store(OSSL_PROVIDER *prov, int retain_fallbacks);
 
index 87906c1bdcb1745e87160cab478e554ac5cb1021..d9cc68d59dc9b3bb1c3785a55fd3eccba4f58fb9 100644 (file)
@@ -26,7 +26,7 @@ static int test_provider(OSSL_PROVIDER *prov, const char *expected_greeting)
     int ret = 0;
 
     ret =
-        TEST_true(ossl_provider_activate(prov, 1))
+        TEST_true(ossl_provider_activate(prov, 1, 0))
         && TEST_true(ossl_provider_get_params(prov, greeting_request))
         && TEST_ptr(greeting = greeting_request[0].data)
         && TEST_size_t_gt(greeting_request[0].data_size, 0)