summaryrefslogtreecommitdiffstats
path: root/crypto/x509/x_all.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/x509/x_all.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/x509/x_all.c')
-rw-r--r--crypto/x509/x_all.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c
index ce8c23b654..0f31c5155f 100644
--- a/crypto/x509/x_all.c
+++ b/crypto/x509/x_all.c
@@ -24,6 +24,7 @@
#include <openssl/rsa.h>
#include <openssl/dsa.h>
#include <openssl/x509v3.h>
+#include "crypto/asn1.h"
static void clean_id_ctx(EVP_MD_CTX *ctx)
{
@@ -594,6 +595,22 @@ EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, fp, a);
}
+EVP_PKEY *d2i_PrivateKey_ex_fp(FILE *fp, EVP_PKEY **a, OPENSSL_CTX *libctx,
+ const char *propq)
+{
+ BIO *b;
+ void *ret;
+
+ if ((b = BIO_new(BIO_s_file())) == NULL) {
+ X509err(0, ERR_R_BUF_LIB);
+ return NULL;
+ }
+ BIO_set_fp(b, fp, BIO_NOCLOSE);
+ ret = d2i_PrivateKey_ex_bio(b, a, libctx, propq);
+ BIO_free(b);
+ return ret;
+}
+
int i2d_PUBKEY_fp(FILE *fp, const EVP_PKEY *pkey)
{
return ASN1_i2d_fp_of(EVP_PKEY, i2d_PUBKEY, fp, pkey);
@@ -642,6 +659,25 @@ EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a)
return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, bp, a);
}
+EVP_PKEY *d2i_PrivateKey_ex_bio(BIO *bp, EVP_PKEY **a, OPENSSL_CTX *libctx,
+ const char *propq)
+{
+ BUF_MEM *b = NULL;
+ const unsigned char *p;
+ void *ret = NULL;
+ int len;
+
+ len = asn1_d2i_read_bio(bp, &b);
+ if (len < 0)
+ goto err;
+
+ p = (unsigned char *)b->data;
+ ret = d2i_AutoPrivateKey_ex(a, &p, len, libctx, propq);
+ err:
+ BUF_MEM_free(b);
+ return ret;
+}
+
int i2d_PUBKEY_bio(BIO *bp, const EVP_PKEY *pkey)
{
return ASN1_i2d_bio_of(EVP_PKEY, i2d_PUBKEY, bp, pkey);