summaryrefslogtreecommitdiffstats
path: root/crypto/evp/evp_fetch.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-03-25 12:12:59 +0000
committerMatt Caswell <matt@openssl.org>2020-03-27 11:12:27 +0000
commit6b1e5fa4873ff2f7741f996961f26ab9818ee190 (patch)
treebdadaacc076978ce4b1bca51100414319ac7e682 /crypto/evp/evp_fetch.c
parent9727f4e7fd02e55b637058249cd8e1bc80501c7f (diff)
Put an error on the stack in the event of a fetch failure
Fetch failures are a common problem and it is useful to have detailed information about what was requested in the event of a failure. Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/11405)
Diffstat (limited to 'crypto/evp/evp_fetch.c')
-rw-r--r--crypto/evp/evp_fetch.c54
1 files changed, 48 insertions, 6 deletions
diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c
index da7f33e95e..e808bf818f 100644
--- a/crypto/evp/evp_fetch.c
+++ b/crypto/evp/evp_fetch.c
@@ -294,9 +294,26 @@ void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id,
int (*up_ref_method)(void *),
void (*free_method)(void *))
{
- return inner_evp_generic_fetch(libctx,
- operation_id, 0, name, properties,
- new_method, up_ref_method, free_method);
+ void *ret = inner_evp_generic_fetch(libctx,
+ operation_id, 0, name, properties,
+ new_method, up_ref_method, free_method);
+
+ if (ret == NULL) {
+ int code = EVP_R_FETCH_FAILED;
+
+#ifdef FIPS_MODE
+ ERR_raise(ERR_LIB_EVP, code);
+#else
+ ERR_raise_data(ERR_LIB_EVP, code,
+ "%s, Algorithm (%s), Properties (%s)",
+ (openssl_ctx_is_default(libctx)
+ ? "Default library context"
+ : "Non-default library context"),
+ name = NULL ? "<null>" : name,
+ properties == NULL ? "<null>" : properties);
+#endif
+ }
+ return ret;
}
/*
@@ -314,9 +331,34 @@ void *evp_generic_fetch_by_number(OPENSSL_CTX *libctx, int operation_id,
int (*up_ref_method)(void *),
void (*free_method)(void *))
{
- return inner_evp_generic_fetch(libctx,
- operation_id, name_id, NULL, properties,
- new_method, up_ref_method, free_method);
+ void *ret = inner_evp_generic_fetch(libctx,
+ operation_id, name_id, NULL,
+ properties, new_method, up_ref_method,
+ free_method);
+
+ if (ret == NULL) {
+ int code = EVP_R_FETCH_FAILED;
+
+#ifdef FIPS_MODE
+ ERR_raise(ERR_LIB_EVP, code);
+#else
+ {
+ OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
+ const char *name = (namemap == NULL)
+ ? NULL
+ : ossl_namemap_num2name(namemap, name_id, 0);
+
+ ERR_raise_data(ERR_LIB_EVP, code,
+ "%s, Algorithm (%s), Properties (%s)",
+ (openssl_ctx_is_default(libctx)
+ ? "Default library context"
+ : "Non-default library context"),
+ name = NULL ? "<null>" : name,
+ properties == NULL ? "<null>" : properties);
+ }
+#endif
+ }
+ return ret;
}
int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq)