2019-02-20 21:55:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 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 <stddef.h>
|
|
|
|
#include <openssl/provider.h>
|
|
|
|
#include "testutil.h"
|
|
|
|
|
2019-03-12 11:36:08 +00:00
|
|
|
#if !defined(DSO_VMS) && !defined(DSO_DLCFN) && !defined(DSO_DL) \
|
|
|
|
&& !defined(DSO_WIN32) && !defined(DSO_DLFCN)
|
|
|
|
# define OPENSSL_NO_DSO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-02-20 21:55:43 +00:00
|
|
|
extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
|
|
|
|
|
|
|
|
static char buf[256];
|
|
|
|
static size_t buf_l = 0;
|
|
|
|
static OSSL_PARAM greeting_request[] = {
|
|
|
|
{ "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf), &buf_l },
|
|
|
|
{ NULL, 0, NULL, 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int test_provider(const char *name)
|
|
|
|
{
|
|
|
|
OSSL_PROVIDER *prov = NULL;
|
|
|
|
const char *greeting = NULL;
|
|
|
|
char expected_greeting[256];
|
|
|
|
|
2019-03-25 01:37:24 +00:00
|
|
|
BIO_snprintf(expected_greeting, sizeof(expected_greeting),
|
2019-03-26 05:20:22 +00:00
|
|
|
"Hello OpenSSL %.20s, greetings from %s!",
|
|
|
|
OPENSSL_VERSION_STR, name);
|
2019-02-20 21:55:43 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
TEST_ptr(prov = OSSL_PROVIDER_load(NULL, name))
|
|
|
|
&& TEST_true(OSSL_PROVIDER_get_params(prov, greeting_request))
|
2019-03-11 20:51:01 +00:00
|
|
|
&& TEST_ptr(greeting = greeting_request[0].data)
|
|
|
|
&& TEST_size_t_gt(greeting_request[0].data_size, 0)
|
2019-02-20 21:55:43 +00:00
|
|
|
&& TEST_str_eq(greeting, expected_greeting)
|
|
|
|
&& TEST_true(OSSL_PROVIDER_unload(prov));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_builtin_provider(void)
|
|
|
|
{
|
|
|
|
const char *name = "p_test_builtin";
|
|
|
|
|
|
|
|
return
|
|
|
|
TEST_true(OSSL_PROVIDER_add_builtin(NULL, name,
|
2019-03-12 11:36:08 +00:00
|
|
|
PROVIDER_INIT_FUNCTION_NAME))
|
2019-02-20 21:55:43 +00:00
|
|
|
&& test_provider(name);
|
|
|
|
}
|
|
|
|
|
2019-03-12 11:36:08 +00:00
|
|
|
#ifndef OPENSSL_NO_DSO
|
2019-02-20 21:55:43 +00:00
|
|
|
static int test_loaded_provider(void)
|
|
|
|
{
|
|
|
|
const char *name = "p_test";
|
|
|
|
|
|
|
|
return test_provider(name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int setup_tests(void)
|
|
|
|
{
|
|
|
|
ADD_TEST(test_builtin_provider);
|
2019-03-12 11:36:08 +00:00
|
|
|
#ifndef OPENSSL_NO_DSO
|
2019-02-20 21:55:43 +00:00
|
|
|
ADD_TEST(test_loaded_provider);
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|