1 /*
2 * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <openssl/asn1t.h>
11 #include <openssl/x509v3.h>
12 #include <crypto/x509.h>
13 #include "ext_dat.h"
14
ASN1_ITEM_TEMPLATE(OSSL_ATTRIBUTES_SYNTAX)15 ASN1_ITEM_TEMPLATE(OSSL_ATTRIBUTES_SYNTAX) =
16 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Attributes, X509_ATTRIBUTE)
17 ASN1_ITEM_TEMPLATE_END(OSSL_ATTRIBUTES_SYNTAX)
18
19 IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTES_SYNTAX)
20
21 static int i2r_ATTRIBUTES_SYNTAX(X509V3_EXT_METHOD *method,
22 OSSL_ATTRIBUTES_SYNTAX *attrlst,
23 BIO *out, int indent)
24 {
25 X509_ATTRIBUTE *attr;
26 ASN1_TYPE *av;
27 int i, j, attr_nid;
28
29 if (!attrlst) {
30 if (BIO_printf(out, "<No Attributes>\n") <= 0)
31 return 0;
32 return 1;
33 }
34 if (!sk_X509_ATTRIBUTE_num(attrlst)) {
35 if (BIO_printf(out, "<Empty Attributes>\n") <= 0)
36 return 0;
37 return 1;
38 }
39
40 for (i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {
41 ASN1_OBJECT *attr_obj;
42 attr = sk_X509_ATTRIBUTE_value(attrlst, i);
43 attr_obj = X509_ATTRIBUTE_get0_object(attr);
44 attr_nid = OBJ_obj2nid(attr_obj);
45 if (indent && BIO_printf(out, "%*s", indent, "") <= 0)
46 return 0;
47 if (attr_nid == NID_undef) {
48 if (i2a_ASN1_OBJECT(out, attr_obj) <= 0)
49 return 0;
50 if (BIO_puts(out, ":\n") <= 0)
51 return 0;
52 } else if (BIO_printf(out, "%s:\n", OBJ_nid2ln(attr_nid)) <= 0) {
53 return 0;
54 }
55
56 if (X509_ATTRIBUTE_count(attr)) {
57 for (j = 0; j < X509_ATTRIBUTE_count(attr); j++)
58 {
59 av = X509_ATTRIBUTE_get0_type(attr, j);
60 if (ossl_print_attribute_value(out, attr_nid, av, indent + 4) <= 0)
61 return 0;
62 if (BIO_puts(out, "\n") <= 0)
63 return 0;
64 }
65 } else if (BIO_printf(out, "%*s<No Values>\n", indent + 4, "") <= 0) {
66 return 0;
67 }
68 }
69 return 1;
70 }
71
72 const X509V3_EXT_METHOD ossl_v3_subj_dir_attrs = {
73 NID_subject_directory_attributes, X509V3_EXT_MULTILINE,
74 ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX),
75 0, 0, 0, 0,
76 0, 0, 0, 0,
77 (X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX,
78 0,
79 NULL
80 };
81
82 const X509V3_EXT_METHOD ossl_v3_associated_info = {
83 NID_associated_information, X509V3_EXT_MULTILINE,
84 ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX),
85 0, 0, 0, 0,
86 0, 0, 0, 0,
87 (X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX,
88 0,
89 NULL
90 };
91