From 023c4d019dee535f2918c3d688d2b3182c5a6223 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 13 Jan 2025 18:02:55 -0500 Subject: [PATCH] Allow import of unknown keys via generic type This allows to use SKEY even w/o a specific skey managment available, however it bears the risk of allowing users to mispell the key type and not see the error of their ways until they expect a specific provider to pick this up and fail. Signed-off-by: Simo Sorce --- crypto/evp/s_lib.c | 11 +++++++++-- test/evp_skey_test.c | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crypto/evp/s_lib.c b/crypto/evp/s_lib.c index 669c6f97ee3fe..f4f011f9d3b22 100644 --- a/crypto/evp/s_lib.c +++ b/crypto/evp/s_lib.c @@ -65,8 +65,15 @@ EVP_SKEY *EVP_SKEY_import(OSSL_LIB_CTX *libctx, const char *skeymgmtname, const skeymgmt = EVP_SKEYMGMT_fetch(libctx, skeymgmtname, propquery); if (skeymgmt == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_FETCH_FAILED); - goto err; + /* + * if the specific key_type is unknown, attempt to use the generic + * key management + */ + skeymgmt = EVP_SKEYMGMT_fetch(libctx, OSSL_SKEY_TYPE_GENERIC, propquery); + if (skeymgmt == NULL) { + ERR_raise(ERR_LIB_EVP, ERR_R_FETCH_FAILED); + goto err; + } } skey->skeymgmt = skeymgmt; diff --git a/test/evp_skey_test.c b/test/evp_skey_test.c index 8f70e5a24150f..c156f698b25c8 100644 --- a/test/evp_skey_test.c +++ b/test/evp_skey_test.c @@ -206,8 +206,8 @@ static int test_des_raw_skey(void) goto end; /* Create EVP_SKEY */ - skey = EVP_SKEY_import_raw_key(libctx, "GENERIC-SECRET", des_key, - sizeof(des_key), NULL); + skey = EVP_SKEY_import_raw_key(libctx, "DES", des_key, sizeof(des_key), + NULL); if (!TEST_ptr(skey)) goto end;