diff options
author | Matt Caswell <matt@openssl.org> | 2021-05-13 16:52:19 +0200 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2021-05-15 11:33:52 +0200 |
commit | 522827160936319841f3f83fd246f92da96f5686 (patch) | |
tree | 273398f5dec8c535b415015fc331d424bc63aa24 | |
parent | Init the child providers immediately on creation of the child libctx (diff) | |
download | openssl-522827160936319841f3f83fd246f92da96f5686.tar.xz openssl-522827160936319841f3f83fd246f92da96f5686.zip |
Load the default provider into the p_test provider later
Loading it earlier causes some of the later testing to pass when it should
fail and masked a bug.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15270)
-rw-r--r-- | test/p_test.c | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/test/p_test.c b/test/p_test.c index 8c7bdaf7b8..22bf8648fe 100644 --- a/test/p_test.c +++ b/test/p_test.c @@ -39,7 +39,6 @@ typedef struct p_test_ctx { 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; @@ -61,6 +60,18 @@ static OSSL_FUNC_provider_get_params_fn p_get_params; static OSSL_FUNC_provider_get_reason_strings_fn p_get_reason_strings; static OSSL_FUNC_provider_teardown_fn p_teardown; +static void p_set_error(int lib, int reason, const char *file, int line, + const char *func, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + c_new_error(NULL); + c_set_error_debug(NULL, file, line, func); + c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, ap); + va_end(ap); +} + static const OSSL_PARAM *p_gettable_params(void *_) { return p_param_types; @@ -128,6 +139,20 @@ static int p_get_params(void *provctx, OSSL_PARAM params[]) EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); const char *msg = "Hello world"; unsigned char out[16]; + OSSL_PROVIDER *deflt; + + /* + * "default" has not been loaded into the parent libctx. We should be able + * to explicitly load it as a non-child provider. + */ + deflt = OSSL_PROVIDER_load(ctx->libctx, "default"); + if (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); + ok = 0; + } /* * We should have the default provider available that we loaded @@ -135,7 +160,8 @@ static int p_get_params(void *provctx, OSSL_PARAM params[]) * from the parent libctx. We should also have "this" provider * available. */ - if (OSSL_PROVIDER_available(ctx->libctx, "default") + if (ok + && 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") @@ -144,11 +170,12 @@ static int p_get_params(void *provctx, OSSL_PARAM params[]) if (EVP_DigestInit_ex(mdctx, md4, NULL) && EVP_DigestUpdate(mdctx, (const unsigned char *)msg, strlen(msg)) - &&EVP_DigestFinal(mdctx, out, NULL)) + && EVP_DigestFinal(mdctx, out, NULL)) digestsuccess = 1; } EVP_MD_CTX_free(mdctx); EVP_MD_free(md4); + OSSL_PROVIDER_unload(deflt); #endif if (p->data_size >= sizeof(digestsuccess)) { *(unsigned int *)p->data = digestsuccess; @@ -161,18 +188,6 @@ static int p_get_params(void *provctx, OSSL_PARAM params[]) return ok; } -static void p_set_error(int lib, int reason, const char *file, int line, - const char *func, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - c_new_error(NULL); - c_set_error_debug(NULL, file, line, func); - c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, ap); - va_end(ap); -} - static const OSSL_ITEM *p_get_reason_strings(void *_) { static const OSSL_ITEM reason_strings[] = { @@ -251,19 +266,6 @@ int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, 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; - } #endif /* @@ -282,7 +284,6 @@ 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); |