diff options
author | Dmitry Belyavskiy <beldmit@gmail.com> | 2023-08-02 17:54:01 +0200 |
---|---|---|
committer | Dmitry Belyavskiy <beldmit@gmail.com> | 2023-08-30 21:55:47 +0200 |
commit | 9d2f7e1f611f03e65f25adf08b76e08821b315da (patch) | |
tree | 4266d8ecdf4ab3db508db67bd91687a80d1a0ed6 /crypto | |
parent | d57d0b818935c20a7b468c0e717773ea8a3373e6 (diff) | |
download | openssl-9d2f7e1f611f03e65f25adf08b76e08821b315da.tar.gz |
OSSL_PROVIDER_load_ex
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21604)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/provider.c | 21 | ||||
-rw-r--r-- | crypto/provider_child.c | 2 | ||||
-rw-r--r-- | crypto/provider_conf.c | 2 | ||||
-rw-r--r-- | crypto/provider_core.c | 27 |
4 files changed, 42 insertions, 10 deletions
diff --git a/crypto/provider.c b/crypto/provider.c index 65f919aec2..9cc51d3ae7 100644 --- a/crypto/provider.c +++ b/crypto/provider.c @@ -15,15 +15,15 @@ #include "internal/provider.h" #include "provider_local.h" -OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name, - int retain_fallbacks) +OSSL_PROVIDER *OSSL_PROVIDER_try_load_ex(OSSL_LIB_CTX *libctx, const char *name, + OSSL_PARAM *params, int retain_fallbacks) { OSSL_PROVIDER *prov = NULL, *actual; int isnew = 0; /* Find it or create it */ if ((prov = ossl_provider_find(libctx, name, 0)) == NULL) { - if ((prov = ossl_provider_new(libctx, name, NULL, 0)) == NULL) + if ((prov = ossl_provider_new(libctx, name, NULL, params, 0)) == NULL) return NULL; isnew = 1; } @@ -49,14 +49,25 @@ OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name, return actual; } -OSSL_PROVIDER *OSSL_PROVIDER_load(OSSL_LIB_CTX *libctx, const char *name) +OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name, + int retain_fallbacks) +{ + return OSSL_PROVIDER_try_load_ex(libctx, name, NULL, retain_fallbacks); +} + +OSSL_PROVIDER *OSSL_PROVIDER_load_ex(OSSL_LIB_CTX *libctx, const char *name, OSSL_PARAM *params) { /* Any attempt to load a provider disables auto-loading of defaults */ if (ossl_provider_disable_fallback_loading(libctx)) - return OSSL_PROVIDER_try_load(libctx, name, 0); + return OSSL_PROVIDER_try_load_ex(libctx, name, params, 0); return NULL; } +OSSL_PROVIDER *OSSL_PROVIDER_load(OSSL_LIB_CTX *libctx, const char *name) +{ + return OSSL_PROVIDER_load_ex(libctx, name, NULL); +} + int OSSL_PROVIDER_unload(OSSL_PROVIDER *prov) { if (!ossl_provider_deactivate(prov, 1)) diff --git a/crypto/provider_child.c b/crypto/provider_child.c index 176a3a5cb2..ed8ee3b3a1 100644 --- a/crypto/provider_child.c +++ b/crypto/provider_child.c @@ -132,7 +132,7 @@ static int provider_create_child_cb(const OSSL_CORE_HANDLE *prov, void *cbdata) * init children */ if ((cprov = ossl_provider_new(ctx, provname, ossl_child_provider_init, - 1)) == NULL) + NULL, 1)) == NULL) goto err; if (!ossl_provider_activate(cprov, 0, 0)) { diff --git a/crypto/provider_conf.c b/crypto/provider_conf.c index 9751caac8e..11294b2996 100644 --- a/crypto/provider_conf.c +++ b/crypto/provider_conf.c @@ -158,7 +158,7 @@ static int provider_conf_activate(OSSL_LIB_CTX *libctx, const char *name, } prov = ossl_provider_find(libctx, name, 1); if (prov == NULL) - prov = ossl_provider_new(libctx, name, NULL, 1); + prov = ossl_provider_new(libctx, name, NULL, NULL, 1); if (prov == NULL) { CRYPTO_THREAD_unlock(pcgbl->lock); if (soft) diff --git a/crypto/provider_core.c b/crypto/provider_core.c index 4cb3e21f69..2e2c597f37 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -518,7 +518,7 @@ static int provider_free_intern(OSSL_PROVIDER *prov, int deactivate) */ OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name, OSSL_provider_init_fn *init_function, - int noconfig) + OSSL_PARAM *params, int noconfig) { struct provider_store_st *store = NULL; OSSL_PROVIDER_INFO template; @@ -540,7 +540,7 @@ OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name, } } if (p->name == NULL) { - /* Check if this is a user added builtin provider */ + /* Check if this is a user added provider */ if (!CRYPTO_THREAD_read_lock(store->lock)) return NULL; for (i = 0, p = store->provinfo; i < store->numprovinfo; p++, i++) { @@ -555,8 +555,29 @@ OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name, template.init = init_function; } + if (params != NULL) { + int i; + + template.parameters = sk_INFOPAIR_new_null(); + if (template.parameters == NULL) + return NULL; + + for (i = 0; params[i].key != NULL; i++) { + if (params[i].data_type != OSSL_PARAM_UTF8_STRING) + continue; + if (ossl_provider_info_add_parameter(&template, params[i].key, + (char *)params[i].data) <= 0) + return NULL; + } + } + /* provider_new() generates an error, so no need here */ - if ((prov = provider_new(name, template.init, template.parameters)) == NULL) + prov = provider_new(name, template.init, template.parameters); + + if (params != NULL) /* We copied the parameters, let's free them */ + sk_INFOPAIR_pop_free(template.parameters, infopair_free); + + if (prov == NULL) return NULL; prov->libctx = libctx; |