From c9da9fd90f97401f9525f9db04d9092377586ef9 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 | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crypto/evp/s_lib.c b/crypto/evp/s_lib.c index a6a52d9d279ac0..ae808e722069a0 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 97b80bf6b160f5..5fae3a812b9d39 100644 --- a/test/evp_skey_test.c +++ b/test/evp_skey_test.c @@ -216,7 +216,7 @@ static int test_des_raw_skey(void) || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) goto end; - skey = EVP_SKEY_import(libctx, "GENERIC-SECRET", NULL, OSSL_SKEYMGMT_SELECT_ALL, params); + skey = EVP_SKEY_import(libctx, "DES", NULL, OSSL_SKEYMGMT_SELECT_ALL, params); if (!TEST_ptr(skey)) goto end;