Commit 6d872a83 authored by Richard Levitte's avatar Richard Levitte
Browse files

Add test for the provider configuration module



We reuse test/provider_internal_test.c and test/p_test.c,
and get it loaded one more time via the configuration file
test/provider_internal_test.conf

To support different platform standards regarding module
extensions, we generate test/provider_internal_test.conf

Reviewed-by: default avatarPaul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8549)
parent abbc2c40
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ Makefile
/test/versions
/test/ossl_shim/ossl_shim
/test/rsa_complex
# Other generated files in test/
/test/provider_internal_test.conf

# Certain files that get created by tests on the fly
/test/test-runs
+2 −0
Original line number Diff line number Diff line
@@ -616,6 +616,8 @@ IF[{- !$disabled{tests} -}]
    DEFINE[provider_test]=OPENSSL_NO_MODULE
    DEFINE[provider_internal_test]=OPENSSL_NO_MODULE
  ENDIF
  DEPEND[]=provider_internal_test.conf
  GENERATE[provider_internal_test.conf]=provider_internal_test.conf.in

  PROGRAMS{noinst}=params_test
  SOURCE[params_test]=params_test.c
+16 −4
Original line number Diff line number Diff line
@@ -52,21 +52,33 @@ static int p_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
        if (strcmp(p->key, "greeting") == 0) {
            static char *opensslv = NULL;
            static char *provname = NULL;
            static char *greeting = NULL;
            static OSSL_PARAM counter_request[] = {
                /* Known libcrypto provided parameters */
                { "openssl-version", OSSL_PARAM_UTF8_PTR,
                  &opensslv, sizeof(&opensslv), NULL },
                { "provider-name", OSSL_PARAM_UTF8_PTR,
                  &provname, sizeof(&provname), NULL},

                /* This might be present, if there's such a configuration */
                { "greeting", OSSL_PARAM_UTF8_PTR,
                  &greeting, sizeof(&greeting), NULL },

                { NULL, 0, NULL, 0, NULL }
            };
            char buf[256];
            size_t buf_l;

            if (c_get_params(prov, counter_request)) {
                if (greeting) {
                    strcpy(buf, greeting);
                } else {
                    const char *versionp = *(void **)counter_request[0].data;
                    const char *namep = *(void **)counter_request[1].data;

                    sprintf(buf, "Hello OpenSSL %.20s, greetings from %s!",
                            versionp, namep);
                }
            } else {
                sprintf(buf, "Howdy stranger...");
            }
+31 −12
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
 */

#include <stddef.h>
#include <openssl/crypto.h>
#include "internal/provider.h"
#include "testutil.h"

@@ -20,20 +21,11 @@ static OSSL_PARAM greeting_request[] = {
    { NULL, 0, NULL, 0, NULL }
};

static int test_provider(OSSL_PROVIDER *prov)
static int test_provider(OSSL_PROVIDER *prov, const char *expected_greeting)
{
    const char *name = NULL;
    const char *greeting = NULL;
    char expected_greeting[256];
    int ret = 0;

    if (!TEST_ptr(name = ossl_provider_name(prov)))
        return 0;

    BIO_snprintf(expected_greeting, sizeof(expected_greeting),
                 "Hello OpenSSL %.20s, greetings from %s!",
                 OPENSSL_VERSION_STR, name);

    ret =
        TEST_true(ossl_provider_activate(prov))
        && TEST_true(ossl_provider_get_params(prov, greeting_request))
@@ -41,10 +33,22 @@ static int test_provider(OSSL_PROVIDER *prov)
        && TEST_size_t_gt(greeting_request[0].data_size, 0)
        && TEST_str_eq(greeting, expected_greeting);

    TEST_info("Got this greeting: %s\n", greeting);
    ossl_provider_free(prov);
    return ret;
}

static const char *expected_greeting1(const char *name)
{
    static char expected_greeting[256] = "";

    snprintf(expected_greeting, sizeof(expected_greeting),
             "Hello OpenSSL %.20s, greetings from %s!",
             OPENSSL_VERSION_STR, name);

    return expected_greeting;
}

static int test_builtin_provider(void)
{
    const char *name = "p_test_builtin";
@@ -53,7 +57,7 @@ static int test_builtin_provider(void)
    return
        TEST_ptr(prov =
                 ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME))
        && test_provider(prov);
        && test_provider(prov, expected_greeting1(name));
}

#ifndef OPENSSL_NO_MODULE
@@ -64,7 +68,21 @@ static int test_loaded_provider(void)

    return
        TEST_ptr(prov = ossl_provider_new(NULL, name, NULL))
        && test_provider(prov);
        && test_provider(prov, expected_greeting1(name));
}

static int test_configured_provider(void)
{
    const char *name = "p_test_configured";
    OSSL_PROVIDER *prov = NULL;
    /* This MUST match the config file */
    const char *expected_greeting =
        "Hello OpenSSL, greetings from Test Provider";

    return
        OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL)
        && TEST_ptr(prov = ossl_provider_find(NULL, name))
        && test_provider(prov, expected_greeting);
}
#endif

@@ -73,6 +91,7 @@ int setup_tests(void)
    ADD_TEST(test_builtin_provider);
#ifndef OPENSSL_NO_MODULE
    ADD_TEST(test_loaded_provider);
    ADD_TEST(test_configured_provider);
#endif
    return 1;
}
+13 −0
Original line number Diff line number Diff line
{- use platform -}
openssl_conf = openssl_init

[openssl_init]
providers = providers

[providers]
p_test_configured = p_test_configured

[p_test_configured]
module = {- platform->dso('p_test') -}
activate = 1
greeting = Hello OpenSSL, greetings from Test Provider
Loading