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 <simo@redhat.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/26753)
This commit is contained in:
Simo Sorce 2025-01-13 18:02:55 -05:00 committed by Dmitry Belyavskiy
parent df93d1327a
commit 71debb7b84
2 changed files with 11 additions and 4 deletions

View File

@ -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;

View File

@ -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;