diff options
author | Matt Caswell <matt@openssl.org> | 2021-05-04 17:38:10 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2021-05-11 15:03:13 +0100 |
commit | fb9b3a7bce236c96d8db37e52db83997b4cb18db (patch) | |
tree | ebc02679f1fa6ad475edeadd4e72bb4da42ca4fd /test/p_test.c | |
parent | abaa2dd2981ba3c15456016c6248f539242cfb49 (diff) | |
download | openssl-fb9b3a7bce236c96d8db37e52db83997b4cb18db.zip openssl-fb9b3a7bce236c96d8db37e52db83997b4cb18db.tar.gz openssl-fb9b3a7bce236c96d8db37e52db83997b4cb18db.tar.bz2 |
Add additional testing of child libctx/providers
Add a case where a provider explicitly loads a provider into a child
libctx where it does not already exist.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14991)
Diffstat (limited to 'test/p_test.c')
-rw-r--r-- | test/p_test.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/test/p_test.c b/test/p_test.c index 421287e..8c7bdaf 100644 --- a/test/p_test.c +++ b/test/p_test.c @@ -32,12 +32,14 @@ #include <openssl/err.h> #include <openssl/evp.h> #include <openssl/crypto.h> +#include <openssl/provider.h> typedef struct p_test_ctx { char *thisfile; char *thisfunc; const OSSL_CORE_HANDLE *handle; OSSL_LIB_CTX *libctx; + OSSL_PROVIDER *deflt; } P_TEST_CTX; static OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL; @@ -127,7 +129,18 @@ static int p_get_params(void *provctx, OSSL_PARAM params[]) const char *msg = "Hello world"; unsigned char out[16]; - if (md4 != NULL && mdctx != NULL) { + /* + * We should have the default provider available that we loaded + * ourselves, and the base and legacy providers which we inherit + * from the parent libctx. We should also have "this" provider + * available. + */ + if (OSSL_PROVIDER_available(ctx->libctx, "default") + && OSSL_PROVIDER_available(ctx->libctx, "base") + && OSSL_PROVIDER_available(ctx->libctx, "legacy") + && OSSL_PROVIDER_available(ctx->libctx, "p_test") + && md4 != NULL + && mdctx != NULL) { if (EVP_DigestInit_ex(mdctx, md4, NULL) && EVP_DigestUpdate(mdctx, (const unsigned char *)msg, strlen(msg)) @@ -164,6 +177,8 @@ static const OSSL_ITEM *p_get_reason_strings(void *_) { static const OSSL_ITEM reason_strings[] = { {1, "dummy reason string"}, + {2, "Can't create child library context"}, + {3, "Can't load default provider"}, {0, NULL} }; @@ -230,6 +245,22 @@ int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, /* We only do this if we are linked with libcrypto */ ctx->libctx = OSSL_LIB_CTX_new_child(handle, oin); if (ctx->libctx == NULL) { + /* We set error "2" for a failure to create the child libctx*/ + p_set_error(ERR_LIB_PROV, 2, ctx->thisfile, OPENSSL_LINE, ctx->thisfunc, + NULL); + p_teardown(ctx); + return 0; + } + /* + * "default" has not been loaded into the parent libctx. We should be able + * to explicitly load it as a non-child provider. + */ + ctx->deflt = OSSL_PROVIDER_load(ctx->libctx, "default"); + if (ctx->deflt == NULL + || !OSSL_PROVIDER_available(ctx->libctx, "default")) { + /* We set error "3" for a failure to load the default provider */ + p_set_error(ERR_LIB_PROV, 3, ctx->thisfile, OPENSSL_LINE, ctx->thisfunc, + NULL); p_teardown(ctx); return 0; } @@ -251,6 +282,7 @@ static void p_teardown(void *provctx) P_TEST_CTX *ctx = (P_TEST_CTX *)provctx; #ifdef PROVIDER_INIT_FUNCTION_NAME + OSSL_PROVIDER_unload(ctx->deflt); OSSL_LIB_CTX_free(ctx->libctx); #endif free(ctx->thisfile); |