From 408113c05087393cc1623a51a0e5bfe8483e302d Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Mon, 20 Jan 2020 16:01:02 +0300 Subject: [PATCH] New functions for PKCS8 attributes management This commit introduces functions PKCS8_pkey_add1_attr_by_OBJ and PKCS8_pkey_add1_attr Reviewed-by: Tomas Mraz Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/10900) --- crypto/asn1/p8_pkey.c | 11 +++++++++++ include/openssl/x509.h | 4 ++++ util/libcrypto.num | 2 ++ 3 files changed, 17 insertions(+) diff --git a/crypto/asn1/p8_pkey.c b/crypto/asn1/p8_pkey.c index c55353ae11..77e64a9ac1 100644 --- a/crypto/asn1/p8_pkey.c +++ b/crypto/asn1/p8_pkey.c @@ -78,3 +78,14 @@ int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type, return 1; return 0; } + +int PKCS8_pkey_add1_attr_by_OBJ(PKCS8_PRIV_KEY_INFO *p8, const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len) +{ + return (X509at_add1_attr_by_OBJ(&p8->attributes, obj, type, bytes, len) != NULL); +} + +int PKCS8_pkey_add1_attr(PKCS8_PRIV_KEY_INFO *p8, X509_ATTRIBUTE *attr) +{ + return (X509at_add1_attr(&p8->attributes, attr) != NULL); +} diff --git a/include/openssl/x509.h b/include/openssl/x509.h index 9d8cc03c53..4cd17d24f5 100644 --- a/include/openssl/x509.h +++ b/include/openssl/x509.h @@ -1034,8 +1034,12 @@ int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const STACK_OF(X509_ATTRIBUTE) * PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8); +int PKCS8_pkey_add1_attr(PKCS8_PRIV_KEY_INFO *p8, X509_ATTRIBUTE *attr); int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type, const unsigned char *bytes, int len); +int PKCS8_pkey_add1_attr_by_OBJ(PKCS8_PRIV_KEY_INFO *p8, const ASN1_OBJECT *obj, + int type, const unsigned char *bytes, int len); + int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, int ptype, void *pval, diff --git a/util/libcrypto.num b/util/libcrypto.num index d0443c2f77..439a7a11c7 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4913,3 +4913,5 @@ ASN1_GENERALIZEDTIME_dup ? 3_0_0 EXIST::FUNCTION: RAND_priv_bytes_ex ? 3_0_0 EXIST::FUNCTION: RAND_bytes_ex ? 3_0_0 EXIST::FUNCTION: EVP_PKEY_get_default_digest_name ? 3_0_0 EXIST::FUNCTION: +PKCS8_pkey_add1_attr ? 3_0_0 EXIST::FUNCTION: +PKCS8_pkey_add1_attr_by_OBJ ? 3_0_0 EXIST::FUNCTION: -- GitLab