From d6ded941c94803adf090f17093c8ff905f259ca8 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Fri, 21 May 2021 15:50:09 +0100 Subject: [PATCH] Provide the ability to create an X509_PUBKEY with a libctx/propq Reviewed-by: Shane Lontis Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15591) --- crypto/x509/x_pubkey.c | 12 ++++++++++++ include/openssl/x509.h.in | 1 + util/libcrypto.num | 1 + 3 files changed, 14 insertions(+) diff --git a/crypto/x509/x_pubkey.c b/crypto/x509/x_pubkey.c index c21184d9649..502caaa9a89 100644 --- a/crypto/x509/x_pubkey.c +++ b/crypto/x509/x_pubkey.c @@ -201,6 +201,18 @@ static const ASN1_EXTERN_FUNCS x509_pubkey_ff = { IMPLEMENT_EXTERN_ASN1(X509_PUBKEY, V_ASN1_SEQUENCE, x509_pubkey_ff) IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) +X509_PUBKEY *X509_PUBKEY_new_ex(OSSL_LIB_CTX *libctx, const char *propq) +{ + X509_PUBKEY *pubkey = NULL; + + pubkey = (X509_PUBKEY *)ASN1_item_new((X509_PUBKEY_it())); + if (!x509_pubkey_set0_libctx(pubkey, libctx, propq)) { + X509_PUBKEY_free(pubkey); + pubkey = NULL; + } + return pubkey; +} + /* * X509_PUBKEY_dup() must be implemented manually, because there is no * support for it in ASN1_EXTERN_FUNCS. diff --git a/include/openssl/x509.h.in b/include/openssl/x509.h.in index d5d3cdb719d..38c7b42c227 100644 --- a/include/openssl/x509.h.in +++ b/include/openssl/x509.h.in @@ -550,6 +550,7 @@ DECLARE_ASN1_FUNCTIONS(X509_VAL) DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) +X509_PUBKEY *X509_PUBKEY_new_ex(OSSL_LIB_CTX *libctx, const char *propq); int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); EVP_PKEY *X509_PUBKEY_get0(const X509_PUBKEY *key); EVP_PKEY *X509_PUBKEY_get(const X509_PUBKEY *key); diff --git a/util/libcrypto.num b/util/libcrypto.num index 6f763f10631..42211e4caa9 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -5407,3 +5407,4 @@ b2i_PVK_bio_ex ? 3_0_0 EXIST::FUNCTION: i2b_PVK_bio_ex ? 3_0_0 EXIST::FUNCTION: NCONF_get0_libctx ? 3_0_0 EXIST::FUNCTION: NCONF_get_section_names ? 3_0_0 EXIST::FUNCTION: +X509_PUBKEY_new_ex ? 3_0_0 EXIST::FUNCTION: -- 2.47.2