diff options
author | Dmitry Belyavskiy <beldmit@gmail.com> | 2023-08-28 13:38:33 +0200 |
---|---|---|
committer | Dmitry Belyavskiy <beldmit@gmail.com> | 2023-09-15 10:18:36 +0200 |
commit | b8aca10d8efac1611cfcb739202c34da39f7e3d0 (patch) | |
tree | ed3baebb1732fb4b69667082c5b3e9571398b094 /test/provider_pkey_test.c | |
parent | 1aac593600f9656170dd144ca1219fdcd8ee8322 (diff) | |
download | openssl-b8aca10d8efac1611cfcb739202c34da39f7e3d0.zip openssl-b8aca10d8efac1611cfcb739202c34da39f7e3d0.tar.gz openssl-b8aca10d8efac1611cfcb739202c34da39f7e3d0.tar.bz2 |
Store: API for deletion - tests
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21901)
Diffstat (limited to 'test/provider_pkey_test.c')
-rw-r--r-- | test/provider_pkey_test.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/provider_pkey_test.c b/test/provider_pkey_test.c index 7e69f4b..09b0606 100644 --- a/test/provider_pkey_test.c +++ b/test/provider_pkey_test.c @@ -18,6 +18,7 @@ #include "fake_rsaprov.h" static OSSL_LIB_CTX *libctx = NULL; +extern int key_deleted; /* From fake_rsaprov.c */ /* Fetch SIGNATURE method using a libctx and propq */ static int fetch_sig(OSSL_LIB_CTX *ctx, const char *alg, const char *propq, @@ -288,6 +289,76 @@ end: return ret; } +static int test_pkey_delete(void) +{ + OSSL_PROVIDER *deflt = NULL; + OSSL_PROVIDER *fake_rsa = NULL; + int ret = 0; + EVP_PKEY *pkey = NULL; + OSSL_STORE_LOADER *loader = NULL; + OSSL_STORE_CTX *ctx = NULL; + OSSL_STORE_INFO *info; + const char *propq = "?provider=fake-rsa"; + + /* It's important to load the default provider first for this test */ + if (!TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))) + goto end; + + if (!TEST_ptr(fake_rsa = fake_rsa_start(libctx))) + goto end; + + if (!TEST_ptr(loader = OSSL_STORE_LOADER_fetch(libctx, "fake_rsa", + propq))) + goto end; + + OSSL_STORE_LOADER_free(loader); + + /* First iteration: load key, check it, delete it */ + if (!TEST_ptr(ctx = OSSL_STORE_open_ex("fake_rsa:test", libctx, propq, + NULL, NULL, NULL, NULL, NULL))) + goto end; + + while (!OSSL_STORE_eof(ctx) + && (info = OSSL_STORE_load(ctx)) != NULL + && pkey == NULL) { + if (OSSL_STORE_INFO_get_type(info) == OSSL_STORE_INFO_PKEY) + pkey = OSSL_STORE_INFO_get1_PKEY(info); + OSSL_STORE_INFO_free(info); + info = NULL; + } + + if (!TEST_ptr(pkey) || !TEST_int_eq(EVP_PKEY_is_a(pkey, "RSA"), 1)) + goto end; + EVP_PKEY_free(pkey); + pkey = NULL; + + if (!TEST_int_eq(OSSL_STORE_delete("fake_rsa:test", libctx, propq, + NULL, NULL, NULL), 1)) + goto end; + if (!TEST_int_eq(OSSL_STORE_close(ctx), 1)) + goto end; + + /* Second iteration: load key should fail */ + if (!TEST_ptr(ctx = OSSL_STORE_open_ex("fake_rsa:test", libctx, propq, + NULL, NULL, NULL, NULL, NULL))) + goto end; + + while (!OSSL_STORE_eof(ctx)) { + info = OSSL_STORE_load(ctx); + if (!TEST_ptr_null(info)) + goto end; + } + + ret = 1; + +end: + fake_rsa_finish(fake_rsa); + OSSL_PROVIDER_unload(deflt); + OSSL_STORE_close(ctx); + fake_rsa_restore_store_state(); + return ret; +} + int setup_tests(void) { libctx = OSSL_LIB_CTX_new(); @@ -298,6 +369,7 @@ int setup_tests(void) ADD_TEST(test_alternative_keygen_init); ADD_TEST(test_pkey_eq); ADD_ALL_TESTS(test_pkey_store, 2); + ADD_TEST(test_pkey_delete); return 1; } |