Some error checking when loading keys

This commit is contained in:
Richard Levitte 2000-07-07 17:02:21 +00:00
parent 854067e8e4
commit 2b912846b9
3 changed files with 24 additions and 2 deletions

View file

@ -359,6 +359,8 @@ void ERR_load_ENGINE_strings(void);
#define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119
#define ENGINE_R_DSO_FAILURE 104
#define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105
#define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128
#define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129
#define ENGINE_R_FINISH_FAILED 106
#define ENGINE_R_GET_HANDLE_FAILED 107
#define ENGINE_R_ID_OR_NAME_MISSING 108

View file

@ -140,6 +140,8 @@ static ERR_STRING_DATA ENGINE_str_reasons[]=
{ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
{ENGINE_R_DSO_FAILURE ,"DSO failure"},
{ENGINE_R_ENGINE_IS_NOT_IN_LIST ,"engine is not in the list"},
{ENGINE_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"},
{ENGINE_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"},
{ENGINE_R_FINISH_FAILED ,"finish failed"},
{ENGINE_R_GET_HANDLE_FAILED ,"could not obtain hardware handle"},
{ENGINE_R_ID_OR_NAME_MISSING ,"'id' or 'name' missing"},

View file

@ -219,6 +219,8 @@ int ENGINE_finish(ENGINE *e)
EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
const char *passphrase)
{
EVP_PKEY *pkey;
if(e == NULL)
{
ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
@ -239,12 +241,21 @@ EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
return 0;
}
CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
return e->load_privkey(key_id, passphrase);
pkey = e->load_privkey(key_id, passphrase);
if (!pkey)
{
ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
return 0;
}
return pkey;
}
EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
const char *passphrase)
{
EVP_PKEY *pkey;
if(e == NULL)
{
ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
@ -265,7 +276,14 @@ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
return 0;
}
CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
return e->load_pubkey(key_id, passphrase);
pkey = e->load_pubkey(key_id, passphrase);
if (!pkey)
{
ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
return 0;
}
return pkey;
}
/* Initialise a engine type for use (or up its functional reference count