diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-07-14 16:06:32 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-07-14 16:06:32 +0000 |
commit | 28f86a2544e372a7a0d4fb74f7ed051b763a6366 (patch) | |
tree | 8a5b5704f47560466ca64ce25c9077ff19a9c48c /lib/libcrypto | |
parent | ff41ea9616d98b8c66fefb0d92b12d1d826866d2 (diff) |
Rewrite EVP_PKEY_add1_attr_by_NID()
Instead of jumping through many layers that cause headache, we can achieve
the same in an entirely straightforward way without losing clarity.
ok jsing
Diffstat (limited to 'lib/libcrypto')
-rw-r--r-- | lib/libcrypto/evp/evp_pkey.c | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/lib/libcrypto/evp/evp_pkey.c b/lib/libcrypto/evp/evp_pkey.c index 655ec107ff5..f9100e22682 100644 --- a/lib/libcrypto/evp/evp_pkey.c +++ b/lib/libcrypto/evp/evp_pkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_pkey.c,v 1.29 2024/07/14 16:04:10 tb Exp $ */ +/* $OpenBSD: evp_pkey.c,v 1.30 2024/07/14 16:06:31 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 1999. */ @@ -142,6 +142,46 @@ error: LCRYPTO_ALIAS(EVP_PKEY2PKCS8); /* + * XXX - This is only used by openssl(1) pkcs12 for the Microsoft-specific + * NID_ms_csp_name and NID_LocalKeySet. This turns out to be the only reason + * why attributes hangs off the EVP_PKEY struct. + */ +int +EVP_PKEY_add1_attr_by_NID(EVP_PKEY *pkey, int nid, int type, + const unsigned char *bytes, int len) +{ + STACK_OF(X509_ATTRIBUTE) *attrs = NULL; + X509_ATTRIBUTE *attr = NULL; + int ret = 0; + + if ((attr = X509_ATTRIBUTE_create_by_NID(NULL, nid, type, + bytes, len)) == NULL) + goto err; + + if ((attrs = pkey->attributes) == NULL) + attrs = sk_X509_ATTRIBUTE_new_null(); + if (attrs == NULL) + goto err; + + if (sk_X509_ATTRIBUTE_push(attrs, attr) <= 0) + goto err; + attr = NULL; + + pkey->attributes = attrs; + attrs = NULL; + + ret = 1; + + err: + X509_ATTRIBUTE_free(attr); + if (attrs != pkey->attributes) + sk_X509_ATTRIBUTE_pop_free(attrs, X509_ATTRIBUTE_free); + + return ret; +} +LCRYPTO_ALIAS(EVP_PKEY_add1_attr_by_NID); + +/* * XXX - delete all the garbage below in the next bump. */ @@ -204,16 +244,6 @@ EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, const ASN1_OBJECT *obj, int type, LCRYPTO_ALIAS(EVP_PKEY_add1_attr_by_OBJ); int -EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, int nid, int type, - const unsigned char *bytes, int len) -{ - if (X509at_add1_attr_by_NID(&key->attributes, nid, type, bytes, len)) - return 1; - return 0; -} -LCRYPTO_ALIAS(EVP_PKEY_add1_attr_by_NID); - -int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, const char *attrname, int type, const unsigned char *bytes, int len) { |