|
13 | 13 | #include <openssl/bn.h>
|
14 | 14 | #include <openssl/objects.h>
|
15 | 15 | #include <openssl/x509_acert.h>
|
| 16 | +#include <openssl/x509.h> |
16 | 17 |
|
17 |
| -static int print_attribute(BIO *bp, X509_ATTRIBUTE *a) |
| 18 | +static int print_attribute(BIO *bp, X509_ATTRIBUTE *a, int indent) |
18 | 19 | {
|
19 | 20 | ASN1_TYPE *at;
|
20 |
| - ASN1_BIT_STRING *bs = NULL; |
21 | 21 | ASN1_OBJECT *aobj;
|
22 |
| - int i, j, type = 0, count = 0; |
| 22 | + int nid, i, j, count = 0; |
23 | 23 | int ret = 0;
|
24 | 24 |
|
25 |
| - aobj = X509_ATTRIBUTE_get0_object(a); |
26 |
| - if (BIO_printf(bp, "%12s", "") <= 0) |
27 |
| - goto err; |
28 |
| - |
29 |
| - if ((j = i2a_ASN1_OBJECT(bp, aobj)) <= 0) |
30 |
| - goto err; |
31 |
| - |
32 | 25 | count = X509_ATTRIBUTE_count(a);
|
33 | 26 | if (count == 0) {
|
34 | 27 | ERR_raise(ERR_LIB_X509, X509_R_INVALID_ATTRIBUTES);
|
35 | 28 | goto err;
|
36 | 29 | }
|
37 | 30 |
|
38 |
| - if (BIO_printf(bp, "%*s", 25 - j, " ") <= 0) |
| 31 | + aobj = X509_ATTRIBUTE_get0_object(a); |
| 32 | + nid = OBJ_obj2nid(aobj); |
| 33 | + |
| 34 | + if (BIO_printf(bp, "%*s", indent, "") <= 0) |
39 | 35 | goto err;
|
40 | 36 |
|
41 |
| - if (BIO_puts(bp, ":") <= 0) |
| 37 | + if ((j = i2a_ASN1_OBJECT(bp, aobj)) <= 0) |
| 38 | + goto err; |
| 39 | + |
| 40 | + if (BIO_puts(bp, ":\n") <= 0) |
42 | 41 | goto err;
|
43 | 42 |
|
44 | 43 | for (i = 0; i < count; i++) {
|
45 | 44 | at = X509_ATTRIBUTE_get0_type(a, i);
|
46 |
| - type = at->type; |
47 |
| - bs = at->value.asn1_string; |
48 |
| - |
49 |
| - switch (type) { |
50 |
| - case V_ASN1_PRINTABLESTRING: |
51 |
| - case V_ASN1_T61STRING: |
52 |
| - case V_ASN1_NUMERICSTRING: |
53 |
| - case V_ASN1_UTF8STRING: |
54 |
| - case V_ASN1_IA5STRING: |
55 |
| - bs = at->value.asn1_string; |
56 |
| - if (BIO_write(bp, (char *)bs->data, bs->length) != bs->length) |
57 |
| - goto err; |
58 |
| - if (BIO_puts(bp, "\n") <= 0) |
59 |
| - goto err; |
60 |
| - break; |
61 |
| - case V_ASN1_SEQUENCE: |
62 |
| - if (BIO_puts(bp, "\n") <= 0) |
63 |
| - goto err; |
64 |
| - ASN1_parse_dump(bp, at->value.sequence->data, |
65 |
| - at->value.sequence->length, i, 1); |
66 |
| - break; |
67 |
| - default: |
68 |
| - if (BIO_puts(bp, "unable to print attribute\n") <= 0) |
69 |
| - goto err; |
70 |
| - break; |
71 |
| - } |
| 45 | + print_attribute_value(bp, nid, at, indent + 4); |
72 | 46 | }
|
| 47 | + |
| 48 | + if (BIO_puts(bp, "\n") <= 0) |
| 49 | + goto err; |
| 50 | + |
73 | 51 | ret = 1;
|
74 | 52 | err:
|
75 | 53 | return ret;
|
@@ -228,7 +206,7 @@ int X509_ACERT_print_ex(BIO *bp, X509_ACERT *x, unsigned long nmflags,
|
228 | 206 | goto err;
|
229 | 207 | } else {
|
230 | 208 | for (i = 0; i < X509_ACERT_get_attr_count(x); i++) {
|
231 |
| - if (print_attribute(bp, X509_ACERT_get_attr(x, i)) == 0) |
| 209 | + if (print_attribute(bp, X509_ACERT_get_attr(x, i), 12) == 0) |
232 | 210 | goto err;
|
233 | 211 | }
|
234 | 212 | }
|
|
0 commit comments