]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add a test to check that child provider callbacks are working
authorMatt Caswell <matt@openssl.org>
Mon, 26 Apr 2021 15:00:04 +0000 (16:00 +0100)
committerMatt Caswell <matt@openssl.org>
Tue, 11 May 2021 13:59:43 +0000 (14:59 +0100)
Write a test to confirm that if a provider is unloaded/loaded into a
libctx then it is similarly unloaded/loaded from any child libctxs.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14991)

test/provider_test.c

index 0abf55e33d65be99503038d8833e387d94b63449..b2236e3a36679a948b72c4a3c03a1e257ac90b72 100644 (file)
@@ -34,6 +34,7 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
     char expected_greeting[256];
     int ok = 0;
     long err;
+    int dolegacycheck = (legacy != NULL);
 
     BIO_snprintf(expected_greeting, sizeof(expected_greeting),
                  "Hello OpenSSL %.20s, greetings from %s!",
@@ -41,7 +42,7 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
 
     if (!TEST_ptr(prov = OSSL_PROVIDER_load(*libctx, name)))
         goto err;
-    if (legacy != NULL) {
+    if (dolegacycheck) {
         if (!TEST_true(OSSL_PROVIDER_get_params(prov, digest_check))
                 || !TEST_true(digestsuccess))
             goto err;
@@ -49,14 +50,40 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
     if (!TEST_true(OSSL_PROVIDER_get_params(prov, greeting_request))
             || !TEST_ptr(greeting = greeting_request[0].data)
             || !TEST_size_t_gt(greeting_request[0].data_size, 0)
-            || !TEST_str_eq(greeting, expected_greeting)
-            || !TEST_true(OSSL_PROVIDER_unload(prov)))
+            || !TEST_str_eq(greeting, expected_greeting))
+        goto err;
+
+    /* Make sure we got the error we were expecting */
+    err = ERR_peek_last_error();
+    if (!TEST_int_gt(err, 0)
+            || !TEST_int_eq(ERR_GET_REASON(err), 1))
         goto err;
 
-    prov = NULL;
     OSSL_PROVIDER_unload(legacy);
     legacy = NULL;
 
+    if (dolegacycheck) {
+        /* Legacy provider should also be unloaded from child libctx */
+        if (!TEST_true(OSSL_PROVIDER_get_params(prov, digest_check))
+                || !TEST_false(digestsuccess))
+            goto err;
+        /*
+         * Loading the legacy provider again should make it available again in
+         * the child libctx.
+         */
+        legacy = OSSL_PROVIDER_load(*libctx, "legacy");
+        if (!TEST_ptr(legacy)
+                || !TEST_true(OSSL_PROVIDER_get_params(prov, digest_check))
+                || !TEST_true(digestsuccess))
+        goto err;
+        OSSL_PROVIDER_unload(legacy);
+        legacy = NULL;
+    }
+
+    if (!TEST_true(OSSL_PROVIDER_unload(prov)))
+        goto err;
+    prov = NULL;
+
     /*
      * We must free the libctx to force the provider to really be unloaded from
      * memory
@@ -64,12 +91,6 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
     OSSL_LIB_CTX_free(*libctx);
     *libctx = NULL;
 
-    /* Make sure we got the error we were expecting */
-    err = ERR_peek_last_error();
-    if (!TEST_int_gt(err, 0)
-            || !TEST_int_eq(ERR_GET_REASON(err), 1))
-        goto err;
-
     /* We print out all the data to make sure it can still be accessed */
     ERR_print_errors_fp(stderr);
     ok = 1;