From: Matt Caswell Date: Fri, 29 Jan 2021 17:25:33 +0000 (+0000) Subject: Add a multi thread test for downgrading keys X-Git-Tag: openssl-3.0.0-alpha13~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e8afd78af69d2229a5c36f542b13a54927709901;p=thirdparty%2Fopenssl.git Add a multi thread test for downgrading keys Reviewed-by: Richard Levitte Reviewed-by: Shane Lontis Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/14319) --- diff --git a/test/threadstest.c b/test/threadstest.c index 26807e294c3..2d3927e5913 100644 --- a/test/threadstest.c +++ b/test/threadstest.c @@ -401,23 +401,46 @@ static void thread_shared_evp_pkey(void) multi_success = 0; } +static void thread_downgrade_shared_evp_pkey(void) +{ +#ifndef OPENSSL_NO_DEPRECATED_3_0 + /* + * This test is only relevant for deprecated functions that perform + * downgrading + */ + if (EVP_PKEY_get0(shared_evp_pkey) == NULL) + multi_success = 0; +#else + /* Shouldn't ever get here */ + multi_success = 0; +#endif +} + + /* * Do work in multiple worker threads at the same time. * Test 0: General worker, using the default provider * Test 1: General worker, using the fips provider * Test 2: Simple fetch worker - * Test 3: Worker using a shared EVP_PKEY + * Test 3: Worker downgrading a shared EVP_PKEY + * Test 4: Worker using a shared EVP_PKEY */ static int test_multi(int idx) { thread_t thread1, thread2; int testresult = 0; OSSL_PROVIDER *prov = NULL, *prov2 = NULL; - void (*worker)(void); + void (*worker)(void) = NULL; + void (*worker2)(void) = NULL; if (idx == 1 && !do_fips) return TEST_skip("FIPS not supported"); +#ifdef OPENSSL_NO_DEPRECATED_3_0 + if (idx == 3) + return TEST_skip("Skipping tests for deprected functions"); +#endif + multi_success = 1; multi_libctx = OSSL_LIB_CTX_new(); if (!TEST_ptr(multi_libctx)) @@ -435,6 +458,9 @@ static int test_multi(int idx) worker = thread_multi_simple_fetch; break; case 3: + worker2 = thread_downgrade_shared_evp_pkey; + /* fall through */ + case 4: /* * If available we have both the default and fips providers for this * test @@ -450,9 +476,11 @@ static int test_multi(int idx) TEST_error("Invalid test index"); goto err; } + if (worker2 == NULL) + worker2 = worker; if (!TEST_true(run_thread(&thread1, worker)) - || !TEST_true(run_thread(&thread2, worker))) + || !TEST_true(run_thread(&thread2, worker2))) goto err; worker(); @@ -547,7 +575,7 @@ int setup_tests(void) ADD_TEST(test_thread_local); ADD_TEST(test_atomic); ADD_TEST(test_multi_load); - ADD_ALL_TESTS(test_multi, 4); + ADD_ALL_TESTS(test_multi, 5); return 1; }