mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-05-18 20:39:42 +00:00
testutil: Add provider.c with test_get_libctx(), to use at least for SSL and CMP
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/11808)
This commit is contained in:
parent
06cee80a84
commit
1bb6f70da3
@ -22,7 +22,7 @@ IF[{- !$disabled{tests} -}]
|
|||||||
testutil/driver.c testutil/tests.c testutil/cb.c testutil/stanza.c \
|
testutil/driver.c testutil/tests.c testutil/cb.c testutil/stanza.c \
|
||||||
testutil/format_output.c \
|
testutil/format_output.c \
|
||||||
testutil/test_cleanup.c testutil/main.c testutil/testutil_init.c \
|
testutil/test_cleanup.c testutil/main.c testutil/testutil_init.c \
|
||||||
testutil/options.c testutil/test_options.c \
|
testutil/options.c testutil/test_options.c testutil/provider.c \
|
||||||
testutil/apps_mem.c testutil/random.c $LIBAPPSSRC
|
testutil/apps_mem.c testutil/random.c $LIBAPPSSRC
|
||||||
INCLUDE[libtestutil.a]=../include ../apps/include ..
|
INCLUDE[libtestutil.a]=../include ../apps/include ..
|
||||||
DEPEND[libtestutil.a]=../libcrypto
|
DEPEND[libtestutil.a]=../libcrypto
|
||||||
|
@ -513,12 +513,12 @@ err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPT_TEST_DECLARE_USAGE("conf_file modulename [fips_conf_file]\n")
|
#define USAGE "conf_file module_name [module_conf_file]\n"
|
||||||
|
OPT_TEST_DECLARE_USAGE(USAGE)
|
||||||
|
|
||||||
int setup_tests(void)
|
int setup_tests(void)
|
||||||
{
|
{
|
||||||
long num_tests;
|
long num_tests;
|
||||||
const char *modulename;
|
|
||||||
|
|
||||||
if (!test_skip_common_options()) {
|
if (!test_skip_common_options()) {
|
||||||
TEST_error("Error parsing test options\n");
|
TEST_error("Error parsing test options\n");
|
||||||
@ -529,29 +529,14 @@ int setup_tests(void)
|
|||||||
/* argv[1] should point to the test conf file */
|
/* argv[1] should point to the test conf file */
|
||||||
|| !TEST_int_gt(NCONF_load(conf, test_get_argument(0), NULL), 0)
|
|| !TEST_int_gt(NCONF_load(conf, test_get_argument(0), NULL), 0)
|
||||||
|| !TEST_int_ne(NCONF_get_number_e(conf, NULL, "num_tests",
|
|| !TEST_int_ne(NCONF_get_number_e(conf, NULL, "num_tests",
|
||||||
&num_tests), 0))
|
&num_tests), 0)) {
|
||||||
return 0;
|
TEST_error("usage: ssl_test %s", USAGE);
|
||||||
|
|
||||||
if (!TEST_ptr(modulename = test_get_argument(1)))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (strcmp(modulename, "none") != 0) {
|
|
||||||
const char *configfile = test_get_argument(2);
|
|
||||||
|
|
||||||
defctxnull = OSSL_PROVIDER_load(NULL, "null");
|
|
||||||
libctx = OPENSSL_CTX_new();
|
|
||||||
if (!TEST_ptr(libctx))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (configfile != NULL
|
|
||||||
&& !TEST_true(OPENSSL_CTX_load_config(libctx, configfile)))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
thisprov = OSSL_PROVIDER_load(libctx, modulename);
|
|
||||||
if (!TEST_ptr(thisprov))
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!test_get_libctx(&libctx, &defctxnull, &thisprov, 1, USAGE))
|
||||||
|
return 0;
|
||||||
|
|
||||||
ADD_ALL_TESTS(test_handshake, (int)num_tests);
|
ADD_ALL_TESTS(test_handshake, (int)num_tests);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
# include <openssl/provider.h>
|
||||||
# include <openssl/err.h>
|
# include <openssl/err.h>
|
||||||
# include <openssl/e_os2.h>
|
# include <openssl/e_os2.h>
|
||||||
# include <openssl/bn.h>
|
# include <openssl/bn.h>
|
||||||
@ -204,6 +205,10 @@ size_t test_get_argument_count(void);
|
|||||||
*/
|
*/
|
||||||
int test_skip_common_options(void);
|
int test_skip_common_options(void);
|
||||||
|
|
||||||
|
int test_get_libctx(OPENSSL_CTX **libctx,
|
||||||
|
OSSL_PROVIDER **default_null_provider,
|
||||||
|
OSSL_PROVIDER **provider, int argn, const char *usage);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal helpers. Test programs shouldn't use these directly, but should
|
* Internal helpers. Test programs shouldn't use these directly, but should
|
||||||
* rather link to one of the helper main() methods.
|
* rather link to one of the helper main() methods.
|
||||||
|
51
test/testutil/provider.c
Normal file
51
test/testutil/provider.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||||
|
* this file except in compliance with the License. You can obtain a copy
|
||||||
|
* in the file LICENSE in the source distribution or at
|
||||||
|
* https://www.openssl.org/source/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../testutil.h"
|
||||||
|
#include <openssl/provider.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int test_get_libctx(OPENSSL_CTX **libctx,
|
||||||
|
OSSL_PROVIDER **default_null_provider,
|
||||||
|
OSSL_PROVIDER **provider, int argn, const char *usage)
|
||||||
|
{
|
||||||
|
const char *module_name;
|
||||||
|
|
||||||
|
if (!TEST_ptr(module_name = test_get_argument(argn))) {
|
||||||
|
TEST_error("usage: <prog> %s", usage);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (strcmp(module_name, "none") != 0) {
|
||||||
|
const char *config_fname = test_get_argument(argn + 1);
|
||||||
|
|
||||||
|
*default_null_provider = OSSL_PROVIDER_load(NULL, "null");
|
||||||
|
*libctx = OPENSSL_CTX_new();
|
||||||
|
if (!TEST_ptr(*libctx)) {
|
||||||
|
TEST_error("Failed to create libctx\n");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config_fname != NULL
|
||||||
|
&& !TEST_true(OPENSSL_CTX_load_config(*libctx, config_fname))) {
|
||||||
|
TEST_error("Error loading config file %s\n", config_fname);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
*provider = OSSL_PROVIDER_load(*libctx, module_name);
|
||||||
|
if (!TEST_ptr(*provider)) {
|
||||||
|
TEST_error("Failed to load provider %s\n", module_name);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
err:
|
||||||
|
ERR_print_errors_fp(stderr);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user