Add test for the provider configuration module
authorRichard Levitte <levitte@openssl.org>
Sat, 30 Mar 2019 21:10:39 +0000 (22:10 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 3 Apr 2019 09:42:48 +0000 (11:42 +0200)
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: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8549)

.gitignore
test/build.info
test/p_test.c
test/provider_internal_test.c
test/provider_internal_test.conf.in [new file with mode: 0644]
test/recipes/02-test_internal_provider.t

index 61c68f4c89cc78e490b9499151088a80ebf976dc..b32122c64a9c0dad4a05e9a13949afa1ebaba251 100644 (file)
@@ -60,6 +60,8 @@ Makefile
 /test/versions
 /test/ossl_shim/ossl_shim
 /test/rsa_complex
 /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
 
 # Certain files that get created by tests on the fly
 /test/test-runs
index 973536dc516d3eee3d763c6279ee79fe381af590..25abb068f339878becd093b76dbe9151411dc2b8 100644 (file)
@@ -616,6 +616,8 @@ IF[{- !$disabled{tests} -}]
     DEFINE[provider_test]=OPENSSL_NO_MODULE
     DEFINE[provider_internal_test]=OPENSSL_NO_MODULE
   ENDIF
     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
 
   PROGRAMS{noinst}=params_test
   SOURCE[params_test]=params_test.c
index 9e1ba8edb3bf0100cb2aaded0bfb6ed17951dc68..bf13a0a070c70827a42d4b6ec15f8bb6bb8d8a40 100644 (file)
@@ -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;
         if (strcmp(p->key, "greeting") == 0) {
             static char *opensslv = NULL;
             static char *provname = NULL;
+            static char *greeting = NULL;
             static OSSL_PARAM counter_request[] = {
             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},
                 { "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)) {
                 { NULL, 0, NULL, 0, NULL }
             };
             char buf[256];
             size_t buf_l;
 
             if (c_get_params(prov, counter_request)) {
-                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);
+                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...");
             }
             } else {
                 sprintf(buf, "Howdy stranger...");
             }
index cbb85c3687b0789dd93eb80b3f3758cb7e849d4d..54e6714ab13aed1b710a62851b22ddcb4c1ccbcd 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <stddef.h>
  */
 
 #include <stddef.h>
+#include <openssl/crypto.h>
 #include "internal/provider.h"
 #include "testutil.h"
 
 #include "internal/provider.h"
 #include "testutil.h"
 
@@ -20,20 +21,11 @@ static OSSL_PARAM greeting_request[] = {
     { NULL, 0, NULL, 0, NULL }
 };
 
     { 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;
     const char *greeting = NULL;
-    char expected_greeting[256];
     int ret = 0;
 
     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))
     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_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;
 }
 
     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";
 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))
     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
 }
 
 #ifndef OPENSSL_NO_MODULE
@@ -64,7 +68,21 @@ static int test_loaded_provider(void)
 
     return
         TEST_ptr(prov = ossl_provider_new(NULL, name, NULL))
 
     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
 
 }
 #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_builtin_provider);
 #ifndef OPENSSL_NO_MODULE
     ADD_TEST(test_loaded_provider);
+    ADD_TEST(test_configured_provider);
 #endif
     return 1;
 }
 #endif
     return 1;
 }
diff --git a/test/provider_internal_test.conf.in b/test/provider_internal_test.conf.in
new file mode 100644 (file)
index 0000000..12c2924
--- /dev/null
@@ -0,0 +1,13 @@
+{- 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
index 8275eb2725f67d7303348f20c0739a181158a04d..615d17a8d905cdc2e4d3d53f57d419baabd81cbd 100644 (file)
@@ -7,12 +7,13 @@
 # https://www.openssl.org/source/license.html
 
 use strict;
 # https://www.openssl.org/source/license.html
 
 use strict;
-use OpenSSL::Test qw(:DEFAULT bldtop_dir);
+use OpenSSL::Test qw(:DEFAULT bldtop_dir bldtop_file);
 use OpenSSL::Test::Simple;
 use OpenSSL::Test::Utils;
 
 setup("test_internal_provider");
 
 use OpenSSL::Test::Simple;
 use OpenSSL::Test::Utils;
 
 setup("test_internal_provider");
 
-$ENV{"OPENSSL_MODULES"} = bldtop_dir("test");
+$ENV{OPENSSL_MODULES} = bldtop_dir("test");
+$ENV{OPENSSL_CONF} = bldtop_file("test", "provider_internal_test.conf");
 
 simple_test("test_internal_provider", "provider_internal_test");
 
 simple_test("test_internal_provider", "provider_internal_test");