Skip to content

Commit d66e034

Browse files
Merge pull request #31 from TrustedComputingGroup/print_attrs_in_acert
print platcert attrs in attr cert
2 parents 66966e5 + 85ed21e commit d66e034

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

crypto/x509/t_acert.c

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,41 @@
1313
#include <openssl/bn.h>
1414
#include <openssl/objects.h>
1515
#include <openssl/x509_acert.h>
16+
#include <openssl/x509.h>
1617

17-
static int print_attribute(BIO *bp, X509_ATTRIBUTE *a)
18+
static int print_attribute(BIO *bp, X509_ATTRIBUTE *a, int indent)
1819
{
1920
ASN1_TYPE *at;
20-
ASN1_BIT_STRING *bs = NULL;
2121
ASN1_OBJECT *aobj;
22-
int i, j, type = 0, count = 0;
22+
int nid, i, j, count = 0;
2323
int ret = 0;
2424

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-
3225
count = X509_ATTRIBUTE_count(a);
3326
if (count == 0) {
3427
ERR_raise(ERR_LIB_X509, X509_R_INVALID_ATTRIBUTES);
3528
goto err;
3629
}
3730

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)
3935
goto err;
4036

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)
4241
goto err;
4342

4443
for (i = 0; i < count; i++) {
4544
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);
7246
}
47+
48+
if (BIO_puts(bp, "\n") <= 0)
49+
goto err;
50+
7351
ret = 1;
7452
err:
7553
return ret;
@@ -228,7 +206,7 @@ int X509_ACERT_print_ex(BIO *bp, X509_ACERT *x, unsigned long nmflags,
228206
goto err;
229207
} else {
230208
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)
232210
goto err;
233211
}
234212
}

0 commit comments

Comments
 (0)