summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2024-07-15 15:43:25 +0000
committertb <>2024-07-15 15:43:25 +0000
commit53175e6c86545b45b6cf609b53a853b1177a9dec (patch)
tree321ed5770aad74f9650a8659f9105bbbac10ed1f
parentcc7031b63a6f84ab84ffe44284b3c9c68500be07 (diff)
downloadopenbsd-53175e6c86545b45b6cf609b53a853b1177a9dec.tar.gz
openbsd-53175e6c86545b45b6cf609b53a853b1177a9dec.tar.bz2
openbsd-53175e6c86545b45b6cf609b53a853b1177a9dec.zip
Fix PKCS12_create()
This tries to copy some microsoft attributes which are not usually present and chokes on the now disabled EVP_PKEY_*attr* API. Instead of reviving about four layers of traps and indirection, just inline the two functions in a way that should be more obvious. found by anton via the ruby-openssl tests ok jsing
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crt.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c
index 3d3ae733c8..55fb7fd638 100644
--- a/src/lib/libcrypto/pkcs12/p12_crt.c
+++ b/src/lib/libcrypto/pkcs12/p12_crt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_crt.c,v 1.24 2024/03/24 06:48:03 tb Exp $ */ 1/* $OpenBSD: p12_crt.c,v 1.25 2024/07/15 15:43:25 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. 3 * project.
4 */ 4 */
@@ -60,8 +60,11 @@
60 60
61#include <openssl/err.h> 61#include <openssl/err.h>
62#include <openssl/pkcs12.h> 62#include <openssl/pkcs12.h>
63#include <openssl/x509.h>
63 64
65#include "evp_local.h"
64#include "pkcs12_local.h" 66#include "pkcs12_local.h"
67#include "x509_local.h"
65 68
66static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, 69static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags,
67 PKCS12_SAFEBAG *bag); 70 PKCS12_SAFEBAG *bag);
@@ -69,13 +72,25 @@ static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags,
69static int 72static int
70copy_bag_attr(PKCS12_SAFEBAG *bag, EVP_PKEY *pkey, int nid) 73copy_bag_attr(PKCS12_SAFEBAG *bag, EVP_PKEY *pkey, int nid)
71{ 74{
72 int idx; 75 X509_ATTRIBUTE *attr = NULL;
73 X509_ATTRIBUTE *attr; 76 const ASN1_OBJECT *obj;
77 int i;
74 78
75 idx = EVP_PKEY_get_attr_by_NID(pkey, nid, -1); 79 if ((obj = OBJ_nid2obj(nid)) == NULL) {
76 if (idx < 0) 80 /* XXX - this seems wrong but preserves behavior. */
77 return 1; 81 return 1;
78 attr = EVP_PKEY_get_attr(pkey, idx); 82 }
83
84 for (i = 0; i < sk_X509_ATTRIBUTE_num(pkey->attributes); i++) {
85 attr = sk_X509_ATTRIBUTE_value(pkey->attributes, i);
86 if (OBJ_cmp(attr->object, obj) == 0)
87 break;
88 attr = NULL;
89 }
90
91 if (attr == NULL)
92 return 1;
93
79 if (!X509at_add1_attr(&bag->attrib, attr)) 94 if (!X509at_add1_attr(&bag->attrib, attr))
80 return 0; 95 return 0;
81 return 1; 96 return 1;