Skip to content

Commit

Permalink
Allow import of unknown keys via generic type
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
simo5 authored and beldmit committed Feb 7, 2025
1 parent 37d459f commit 6ab5de7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions crypto/evp/s_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions test/evp_skey_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6ab5de7

Please sign in to comment.