diff options
Diffstat (limited to 'crypto/provider_core.c')
-rw-r--r-- | crypto/provider_core.c | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/crypto/provider_core.c b/crypto/provider_core.c index f87ccfa4a2..598f1ba214 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -57,6 +57,7 @@ struct ossl_provider_st { unsigned int flag_initialized:1; unsigned int flag_activated:1; unsigned int flag_fallback:1; /* Can be used as fallback */ + unsigned int flag_couldbechild:1; /* Getting and setting the flags require synchronization */ CRYPTO_RWLOCK *flag_lock; @@ -306,6 +307,7 @@ static OSSL_PROVIDER *provider_new(const char *name, } prov->init_function = init_function; + prov->flag_couldbechild = 1; return prov; } @@ -646,6 +648,7 @@ static int provider_init(OSSL_PROVIDER *prov, int flag_lock) } prov->provctx = tmp_provctx; prov->dispatch = provider_dispatch; + prov->flag_couldbechild = 0; for (; provider_dispatch->function_id != 0; provider_dispatch++) { switch (provider_dispatch->function_id) { @@ -1281,23 +1284,60 @@ const OSSL_CORE_HANDLE *ossl_provider_get_parent(OSSL_PROVIDER *prov) return prov->handle; } -int ossl_provider_set_child(OSSL_PROVIDER *prov, const OSSL_CORE_HANDLE *handle) +int ossl_provider_is_child(const OSSL_PROVIDER *prov) { - struct provider_store_st *store = NULL; - - if ((store = get_provider_store(prov->libctx)) == NULL) - return 0; + return prov->ischild; +} +int ossl_provider_set_child(OSSL_PROVIDER *prov, const OSSL_CORE_HANDLE *handle) +{ prov->handle = handle; prov->ischild = 1; - if (!CRYPTO_THREAD_write_lock(store->lock)) + return 1; +} + +int ossl_provider_convert_to_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 three states: (1) Already a child, + * (2) Not a child (but eligible to be one), or (3) Not a child (not + * eligible to be one). + */ + if (prov->flag_couldbechild) { + ossl_provider_set_child(prov, handle); + prov->init_function = init_function; + } + if (prov->ischild && provider_activate(prov, 0, 0)) { + flush = 1; + prov->store->use_fallbacks = 0; + } - CRYPTO_THREAD_unlock(store->lock); + 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 eligible for conversion + * to a child. If its not elgibile then it has already been loaded as a non + * child provider and we should keep it like that. + */ return 1; } + #ifndef FIPS_MODULE static int ossl_provider_register_child_cb(const OSSL_CORE_HANDLE *handle, int (*create_cb)( @@ -1337,6 +1377,13 @@ static int ossl_provider_register_child_cb(const OSSL_CORE_HANDLE *handle, max = sk_OSSL_PROVIDER_num(store->providers); for (i = 0; i < max; i++) { prov = sk_OSSL_PROVIDER_value(store->providers, i); + /* + * We require register_child_cb to be called during a provider init + * function. The currently initing provider will never be activated yet + * and we we should not attempt to aquire the flag_lock for it. + */ + if (prov == thisprov) + continue; if (!CRYPTO_THREAD_read_lock(prov->flag_lock)) break; /* |