summaryrefslogtreecommitdiffstats
path: root/test/evp_fetch_prov_test.c
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2020-03-20 11:25:39 +0100
committerShane Lontis <shane.lontis@oracle.com>2020-03-20 11:25:39 +0100
commit22e27978b29b2cdc1db79659ed653d6cf31834ab (patch)
treef156d63b1f889794d723167e59108d088fbe5907 /test/evp_fetch_prov_test.c
parentUse RAND_bytes_ex in crypto/rsa (diff)
downloadopenssl-22e27978b29b2cdc1db79659ed653d6cf31834ab.tar.xz
openssl-22e27978b29b2cdc1db79659ed653d6cf31834ab.zip
Add support for passing the libctx to the config loader
The self tests for the fips module are triggered on startup and they need to know the core's libctx in order to function correctly. As the provider can be autoloaded via configuration it then needs to propagate the callers libctx down to the provider via the config load. Note that OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, ..) is still called, but will only load the default configuration if the OPENSSL_CONF environment variable is set. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/11240)
Diffstat (limited to 'test/evp_fetch_prov_test.c')
-rw-r--r--test/evp_fetch_prov_test.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/evp_fetch_prov_test.c b/test/evp_fetch_prov_test.c
index ca39236cd6..14a3bb778d 100644
--- a/test/evp_fetch_prov_test.c
+++ b/test/evp_fetch_prov_test.c
@@ -20,6 +20,7 @@
#include <openssl/provider.h>
#include "testutil.h"
+static char *config_file = NULL;
static char *alg = "digest";
static int use_default_ctx = 0;
static char *fetch_property = NULL;
@@ -32,6 +33,7 @@ typedef enum OPTION_choice {
OPT_FETCH_PROPERTY,
OPT_FETCH_FAILURE,
OPT_USE_DEFAULTCTX,
+ OPT_CONFIG_FILE,
OPT_TEST_ENUM
} OPTION_CHOICE;
@@ -39,6 +41,7 @@ const OPTIONS *test_get_options(void)
{
static const OPTIONS test_options[] = {
OPT_TEST_OPTIONS_WITH_EXTRA_USAGE("[provname...]\n"),
+ { "config", OPT_CONFIG_FILE, '<', "The configuration file to use for the libctx" },
{ "type", OPT_ALG_FETCH_TYPE, 's', "The fetch type to test" },
{ "property", OPT_FETCH_PROPERTY, 's', "The fetch property e.g. provider=fips" },
{ "fetchfail", OPT_FETCH_FAILURE, '-', "fetch is expected to fail" },
@@ -75,7 +78,7 @@ static int calculate_digest(const EVP_MD *md, const char *msg, size_t len,
static int load_providers(OPENSSL_CTX **libctx, OSSL_PROVIDER *prov[])
{
- OPENSSL_CTX *ctx;
+ OPENSSL_CTX *ctx = NULL;
int ret = 0;
size_t i;
@@ -83,6 +86,8 @@ static int load_providers(OPENSSL_CTX **libctx, OSSL_PROVIDER *prov[])
if (!TEST_ptr(ctx))
goto err;
+ if (!TEST_true(OPENSSL_CTX_load_config(ctx, config_file)))
+ goto err;
if (test_get_argument_count() > 2)
goto err;
@@ -92,9 +97,12 @@ static int load_providers(OPENSSL_CTX **libctx, OSSL_PROVIDER *prov[])
if (!TEST_ptr(prov[i]))
goto err;
}
+
ret = 1;
*libctx = ctx;
err:
+ if (ret == 0)
+ OPENSSL_CTX_free(ctx);
return ret;
}
@@ -231,6 +239,9 @@ int setup_tests(void)
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
+ case OPT_CONFIG_FILE:
+ config_file = opt_arg();
+ break;
case OPT_ALG_FETCH_TYPE:
alg = opt_arg();
break;