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 Jan 28, 2025
1 parent c59d076 commit ad565e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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
2 changes: 1 addition & 1 deletion test/evp_skey_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ad565e0

Please sign in to comment.