]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Init the child providers immediately on creation of the child libctx
authorMatt Caswell <matt@openssl.org>
Thu, 13 May 2021 14:35:42 +0000 (15:35 +0100)
committerMatt Caswell <matt@openssl.org>
Sat, 15 May 2021 09:33:42 +0000 (10:33 +0100)
We were deferring the initial creation of the child providers until the
first fetch. This is a carry over from an earlier iteration of the child
lib ctx development and is no longer necessary. In fact we need to init
the child providers immediately otherwise not all providers quite init
correctly.

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

crypto/provider_child.c
crypto/provider_core.c
doc/internal/man3/ossl_provider_new.pod
include/internal/provider.h

index 0ca61c068608551db19547b1b793e936353920cc..2487d43fd7a4215ce1c36b61b1eabe760c36c7be 100644 (file)
@@ -198,44 +198,6 @@ static int provider_remove_child_cb(const OSSL_CORE_HANDLE *prov, void *cbdata)
     return 1;
 }
 
-int ossl_provider_init_child_providers(OSSL_LIB_CTX *ctx)
-{
-    struct child_prov_globals *gbl;
-
-    /* Should never happen */
-    if (ctx == NULL)
-        return 0;
-
-    gbl = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_CHILD_PROVIDER_INDEX,
-                                &child_prov_ossl_ctx_method);
-    if (gbl == NULL)
-        return 0;
-
-    if (!CRYPTO_THREAD_read_lock(gbl->lock))
-        return 0;
-    if (gbl->isinited) {
-        CRYPTO_THREAD_unlock(gbl->lock);
-        return 1;
-    }
-    CRYPTO_THREAD_unlock(gbl->lock);
-
-    if (!CRYPTO_THREAD_write_lock(gbl->lock))
-        return 0;
-    if (!gbl->isinited) {
-        if (!gbl->c_provider_register_child_cb(gbl->handle,
-                                               provider_create_child_cb,
-                                               provider_remove_child_cb,
-                                               ctx)) {
-            CRYPTO_THREAD_unlock(gbl->lock);
-            return 0;
-        }
-        gbl->isinited = 1;
-    }
-    CRYPTO_THREAD_unlock(gbl->lock);
-
-    return 1;
-}
-
 int ossl_provider_init_as_child(OSSL_LIB_CTX *ctx,
                                 const OSSL_CORE_HANDLE *handle,
                                 const OSSL_DISPATCH *in)
@@ -300,6 +262,14 @@ int ossl_provider_init_as_child(OSSL_LIB_CTX *ctx,
     if (gbl->lock == NULL)
         return 0;
 
+    if (!gbl->c_provider_register_child_cb(gbl->handle,
+                                           provider_create_child_cb,
+                                           provider_remove_child_cb,
+                                           ctx))
+        return 0;
+
+    gbl->isinited = 1;
+
     return 1;
 }
 
index f0b429d986c08cfb6f6d7b314273dc4a439d0815..b384f74fd24614e96a1de8b4407aad47a14b865d 100644 (file)
@@ -276,9 +276,6 @@ OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
         if (!noconfig) {
             if (ossl_lib_ctx_is_default(libctx))
                 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
-            if (ossl_lib_ctx_is_child(libctx)
-                    && !ossl_provider_init_child_providers(libctx))
-                return NULL;
         }
 #endif
 
@@ -1007,9 +1004,6 @@ int ossl_provider_doall_activated(OSSL_LIB_CTX *ctx,
      */
     if (ossl_lib_ctx_is_default(ctx))
         OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
-    if (ossl_lib_ctx_is_child(ctx)
-            && !ossl_provider_init_child_providers(ctx))
-        return 0;
 #endif
 
     if (store == NULL)
index ff347bad3f628bc2bc7b4ba99568df759d09dbe6..7ab60eb3a5ad720d4c08139fe177c169c5e25434 100644 (file)
@@ -7,7 +7,7 @@ ossl_provider_free,
 ossl_provider_set_fallback, ossl_provider_set_module_path,
 ossl_provider_add_parameter, ossl_provider_set_child, ossl_provider_get_parent,
 ossl_provider_up_ref_parent, ossl_provider_free_parent,
-ossl_provider_get0_dispatch, ossl_provider_init_child_providers,
+ossl_provider_get0_dispatch,
 ossl_provider_init_as_child,
 ossl_provider_activate, ossl_provider_deactivate, ossl_provider_available,
 ossl_provider_ctx,
@@ -95,7 +95,6 @@ ossl_provider_get_capabilities
                                       int *result);
  int ossl_provider_clear_all_operation_bits(OSSL_LIB_CTX *libctx);
 
- int ossl_provider_init_child_providers(OSSL_LIB_CTX *ctx);
  int ossl_provider_init_as_child(OSSL_LIB_CTX *ctx,
                                  const OSSL_CORE_HANDLE *handle,
                                  const OSSL_DISPATCH *in);
@@ -291,10 +290,6 @@ I<*result> to 1 or 0 accorddingly.
 ossl_provider_clear_all_operation_bits() clears all of the operation bits
 to (0) for all providers in the library context I<libctx>.
 
-ossl_provider_init_child_providers() registers the callbacks required to
-receive notifications about loading and unloading of providers in the parent
-library context.
-
 ossl_provider_init_as_child() stores in the library context I<ctx> references to
 the necessary upcalls for managing child providers. The I<handle> and I<in>
 parameters are the B<OSSL_CORE_HANDLE> and B<OSSL_DISPATCH> pointers that were
index 5b0af7a335d0f5ac2174efe9bf3620a892ed59f0..020cbc8a9ee066086950f9994b304fbbf404efe8 100644 (file)
@@ -108,7 +108,6 @@ int ossl_provider_clear_all_operation_bits(OSSL_LIB_CTX *libctx);
 void ossl_provider_add_conf_module(void);
 
 /* Child providers */
-int ossl_provider_init_child_providers(OSSL_LIB_CTX *ctx);
 int ossl_provider_init_as_child(OSSL_LIB_CTX *ctx,
                                 const OSSL_CORE_HANDLE *handle,
                                 const OSSL_DISPATCH *in);