summaryrefslogtreecommitdiffstats
path: root/crypto/evp/evp_pkey.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-04-06 18:18:18 +0100
committerMatt Caswell <matt@openssl.org>2020-04-15 11:24:13 +0100
commit472a88b79e779342adc3b85b5bea318de038ae14 (patch)
tree8a9a0eda32d60f98732f119c8f2f603576d2ea31 /crypto/evp/evp_pkey.c
parentca59b00bbd701b9e5e7ce213f44a4d7577d6d2db (diff)
Teach d2i_PrivateKey et al about libctx
The Ed448 private key decoding makes algorithm fetches. Therefore we teach d2i_PrivateKey et al about libctx and make sure it is passed through the layers. Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/11494)
Diffstat (limited to 'crypto/evp/evp_pkey.c')
-rw-r--r--crypto/evp/evp_pkey.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/evp/evp_pkey.c b/crypto/evp/evp_pkey.c
index a11b856c03..6a40f4b456 100644
--- a/crypto/evp/evp_pkey.c
+++ b/crypto/evp/evp_pkey.c
@@ -18,7 +18,8 @@
/* Extract a private key from a PKCS8 structure */
-EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8)
+EVP_PKEY *evp_pkcs82pkey_int(const PKCS8_PRIV_KEY_INFO *p8, OPENSSL_CTX *libctx,
+ const char *propq)
{
EVP_PKEY *pkey = NULL;
const ASN1_OBJECT *algoid;
@@ -28,24 +29,29 @@ EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8)
return NULL;
if ((pkey = EVP_PKEY_new()) == NULL) {
- EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_MALLOC_FAILURE);
+ EVPerr(0, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(algoid))) {
- EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
+ EVPerr(0, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
i2t_ASN1_OBJECT(obj_tmp, 80, algoid);
ERR_add_error_data(2, "TYPE=", obj_tmp);
goto error;
}
- if (pkey->ameth->priv_decode) {
+ if (pkey->ameth->priv_decode_with_libctx != NULL) {
+ if (!pkey->ameth->priv_decode_with_libctx(pkey, p8, libctx, propq)) {
+ EVPerr(0, EVP_R_PRIVATE_KEY_DECODE_ERROR);
+ goto error;
+ }
+ } else if (pkey->ameth->priv_decode != NULL) {
if (!pkey->ameth->priv_decode(pkey, p8)) {
- EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_PRIVATE_KEY_DECODE_ERROR);
+ EVPerr(0, EVP_R_PRIVATE_KEY_DECODE_ERROR);
goto error;
}
} else {
- EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_METHOD_NOT_SUPPORTED);
+ EVPerr(0, EVP_R_METHOD_NOT_SUPPORTED);
goto error;
}
@@ -56,6 +62,11 @@ EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8)
return NULL;
}
+EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8)
+{
+ return evp_pkcs82pkey_int(p8, NULL, NULL);
+}
+
/* Turn a private key into a PKCS8 structure */
PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey)