summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-07-14 16:06:31 +0000
committertb <>2024-07-14 16:06:31 +0000
commitaf6f53ce34e25fae6da69e0ff987be9d0cfbebe8 (patch)
tree4f9db2a9c4d2139d596628ff29034af3b7fe03a4 /src
parent068d0f16a0c01c1282b13eee497c555ff6c37d01 (diff)
downloadopenbsd-af6f53ce34e25fae6da69e0ff987be9d0cfbebe8.tar.gz
openbsd-af6f53ce34e25fae6da69e0ff987be9d0cfbebe8.tar.bz2
openbsd-af6f53ce34e25fae6da69e0ff987be9d0cfbebe8.zip
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 'src')
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
index 655ec107ff..f9100e2268 100644
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_pkey.c,v 1.29 2024/07/14 16:04:10 tb Exp $ */ 1/* $OpenBSD: evp_pkey.c,v 1.30 2024/07/14 16:06:31 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -142,6 +142,46 @@ error:
142LCRYPTO_ALIAS(EVP_PKEY2PKCS8); 142LCRYPTO_ALIAS(EVP_PKEY2PKCS8);
143 143
144/* 144/*
145 * XXX - This is only used by openssl(1) pkcs12 for the Microsoft-specific
146 * NID_ms_csp_name and NID_LocalKeySet. This turns out to be the only reason
147 * why attributes hangs off the EVP_PKEY struct.
148 */
149int
150EVP_PKEY_add1_attr_by_NID(EVP_PKEY *pkey, int nid, int type,
151 const unsigned char *bytes, int len)
152{
153 STACK_OF(X509_ATTRIBUTE) *attrs = NULL;
154 X509_ATTRIBUTE *attr = NULL;
155 int ret = 0;
156
157 if ((attr = X509_ATTRIBUTE_create_by_NID(NULL, nid, type,
158 bytes, len)) == NULL)
159 goto err;
160
161 if ((attrs = pkey->attributes) == NULL)
162 attrs = sk_X509_ATTRIBUTE_new_null();
163 if (attrs == NULL)
164 goto err;
165
166 if (sk_X509_ATTRIBUTE_push(attrs, attr) <= 0)
167 goto err;
168 attr = NULL;
169
170 pkey->attributes = attrs;
171 attrs = NULL;
172
173 ret = 1;
174
175 err:
176 X509_ATTRIBUTE_free(attr);
177 if (attrs != pkey->attributes)
178 sk_X509_ATTRIBUTE_pop_free(attrs, X509_ATTRIBUTE_free);
179
180 return ret;
181}
182LCRYPTO_ALIAS(EVP_PKEY_add1_attr_by_NID);
183
184/*
145 * XXX - delete all the garbage below in the next bump. 185 * XXX - delete all the garbage below in the next bump.
146 */ 186 */
147 187
@@ -204,16 +244,6 @@ EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, const ASN1_OBJECT *obj, int type,
204LCRYPTO_ALIAS(EVP_PKEY_add1_attr_by_OBJ); 244LCRYPTO_ALIAS(EVP_PKEY_add1_attr_by_OBJ);
205 245
206int 246int
207EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, int nid, int type,
208 const unsigned char *bytes, int len)
209{
210 if (X509at_add1_attr_by_NID(&key->attributes, nid, type, bytes, len))
211 return 1;
212 return 0;
213}
214LCRYPTO_ALIAS(EVP_PKEY_add1_attr_by_NID);
215
216int
217EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, const char *attrname, int type, 247EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, const char *attrname, int type,
218 const unsigned char *bytes, int len) 248 const unsigned char *bytes, int len)
219{ 249{