From: Richard Levitte Date: Fri, 7 Jul 2000 17:02:21 +0000 (+0000) Subject: Some error checking when loading keys X-Git-Tag: OpenSSL-engine-0_9_6-beta1~25 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2b912846b94247cb521cb878a164e8507f2b9d57;p=oweals%2Fopenssl.git Some error checking when loading keys --- diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h index acb480b578..cfe7e04ef0 100644 --- a/crypto/engine/engine.h +++ b/crypto/engine/engine.h @@ -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 diff --git a/crypto/engine/engine_err.c b/crypto/engine/engine_err.c index e738dcc790..75ae563bf7 100644 --- a/crypto/engine/engine_err.c +++ b/crypto/engine/engine_err.c @@ -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"}, diff --git a/crypto/engine/engine_lib.c b/crypto/engine/engine_lib.c index fa545cef3a..354f73a03f 100644 --- a/crypto/engine/engine_lib.c +++ b/crypto/engine/engine_lib.c @@ -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