diff options
| author | tb <> | 2024-07-15 15:43:25 +0000 |
|---|---|---|
| committer | tb <> | 2024-07-15 15:43:25 +0000 |
| commit | beafda5998db0cbb734723cf1f2897bbf6046bdb (patch) | |
| tree | 321ed5770aad74f9650a8659f9105bbbac10ed1f | |
| parent | 2559a9bfe12a58a7e0e7cd03ecc37b5722e8f7ef (diff) | |
| download | openbsd-beafda5998db0cbb734723cf1f2897bbf6046bdb.tar.gz openbsd-beafda5998db0cbb734723cf1f2897bbf6046bdb.tar.bz2 openbsd-beafda5998db0cbb734723cf1f2897bbf6046bdb.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.c | 27 |
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 | ||
| 66 | static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, | 69 | static 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, | |||
| 69 | static int | 72 | static int |
| 70 | copy_bag_attr(PKCS12_SAFEBAG *bag, EVP_PKEY *pkey, int nid) | 73 | copy_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; |
