Debian Codegraph @

debian/rust-vendor/openssl-src/openssl/crypto/x509/v3_aaa.c

raw
1 /*
2 * Copyright 2024-2025 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 <openssl/x509.h>
13 #include <crypto/x509.h>
14 #include "ext_dat.h"
15
16 ASN1_CHOICE(OSSL_ALLOWED_ATTRIBUTES_CHOICE) = {
17 ASN1_IMP(OSSL_ALLOWED_ATTRIBUTES_CHOICE, choice.attributeType, ASN1_OBJECT,
18 OSSL_AAA_ATTRIBUTE_TYPE),
19 ASN1_IMP(OSSL_ALLOWED_ATTRIBUTES_CHOICE, choice.attributeTypeandValues,
20 X509_ATTRIBUTE, OSSL_AAA_ATTRIBUTE_VALUES),
21 } ASN1_CHOICE_END(OSSL_ALLOWED_ATTRIBUTES_CHOICE)
22
23 ASN1_SEQUENCE(OSSL_ALLOWED_ATTRIBUTES_ITEM) = {
24 ASN1_IMP_SET_OF(OSSL_ALLOWED_ATTRIBUTES_ITEM, attributes,
25 OSSL_ALLOWED_ATTRIBUTES_CHOICE, 0),
26 /* This MUST be EXPLICIT, because it contains a CHOICE. */
27 ASN1_EXP(OSSL_ALLOWED_ATTRIBUTES_ITEM, holderDomain, GENERAL_NAME, 1),
28 } ASN1_SEQUENCE_END(OSSL_ALLOWED_ATTRIBUTES_ITEM)
29
30 ASN1_ITEM_TEMPLATE(OSSL_ALLOWED_ATTRIBUTES_SYNTAX) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, OSSL_ALLOWED_ATTRIBUTES_SYNTAX,
31 OSSL_ALLOWED_ATTRIBUTES_ITEM)
32 ASN1_ITEM_TEMPLATE_END(OSSL_ALLOWED_ATTRIBUTES_SYNTAX)
33
34 IMPLEMENT_ASN1_FUNCTIONS(OSSL_ALLOWED_ATTRIBUTES_CHOICE)
35 IMPLEMENT_ASN1_FUNCTIONS(OSSL_ALLOWED_ATTRIBUTES_ITEM)
36 IMPLEMENT_ASN1_FUNCTIONS(OSSL_ALLOWED_ATTRIBUTES_SYNTAX)
37
38 static int i2r_ALLOWED_ATTRIBUTES_CHOICE(X509V3_EXT_METHOD *method,
39 OSSL_ALLOWED_ATTRIBUTES_CHOICE *a,
40 BIO *out, int indent)
41 {
42 ASN1_OBJECT *attr_obj;
43 int attr_nid, j;
44 X509_ATTRIBUTE *attr;
45 ASN1_TYPE *av;
46
47 switch (a->type) {
48 case (OSSL_AAA_ATTRIBUTE_TYPE):
49 if (BIO_printf(out, "%*sAttribute Type: ", indent, "") <= 0)
50 return 0;
51 if (i2a_ASN1_OBJECT(out, a->choice.attributeType) <= 0)
52 return 0;
53 return BIO_puts(out, "\n") > 0;
54 case (OSSL_AAA_ATTRIBUTE_VALUES):
55 attr = a->choice.attributeTypeandValues;
56 attr_obj = X509_ATTRIBUTE_get0_object(attr);
57 attr_nid = OBJ_obj2nid(attr_obj);
58 if (BIO_printf(out, "%*sAttribute Values: ", indent, "") <= 0)
59 return 0;
60 if (i2a_ASN1_OBJECT(out, attr_obj) <= 0)
61 return 0;
62 if (BIO_puts(out, "\n") <= 0)
63 return 0;
64 for (j = 0; j < X509_ATTRIBUTE_count(attr); j++) {
65 av = X509_ATTRIBUTE_get0_type(attr, j);
66 if (ossl_print_attribute_value(out, attr_nid, av, indent + 4) <= 0)
67 return 0;
68 if (BIO_puts(out, "\n") <= 0)
69 return 0;
70 }
71 break;
72 default:
73 return 0;
74 }
75 return 1;
76 }
77
78 static int i2r_ALLOWED_ATTRIBUTES_ITEM(X509V3_EXT_METHOD *method,
79 OSSL_ALLOWED_ATTRIBUTES_ITEM *aai,
80 BIO *out, int indent)
81 {
82 int i;
83 OSSL_ALLOWED_ATTRIBUTES_CHOICE *a;
84
85 for (i = 0; i < sk_OSSL_ALLOWED_ATTRIBUTES_CHOICE_num(aai->attributes); i++) {
86 if (BIO_printf(out, "%*sAllowed Attribute Type or Values:\n", indent, "") <= 0)
87 return 0;
88 a = sk_OSSL_ALLOWED_ATTRIBUTES_CHOICE_value(aai->attributes, i);
89 if (i2r_ALLOWED_ATTRIBUTES_CHOICE(method, a, out, indent + 4) <= 0)
90 return 0;
91 }
92 if (BIO_printf(out, "%*sHolder Domain: ", indent, "") <= 0)
93 return 0;
94 if (GENERAL_NAME_print(out, aai->holderDomain) <= 0)
95 return 0;
96 if (BIO_puts(out, "\n") <= 0)
97 return 0;
98 return 1;
99 }
100
101 static int i2r_ALLOWED_ATTRIBUTES_SYNTAX(X509V3_EXT_METHOD *method,
102 OSSL_ALLOWED_ATTRIBUTES_SYNTAX *aaa,
103 BIO *out, int indent)
104 {
105 int i;
106 OSSL_ALLOWED_ATTRIBUTES_ITEM *aai;
107
108 for (i = 0; i < sk_OSSL_ALLOWED_ATTRIBUTES_ITEM_num(aaa); i++) {
109 if (BIO_printf(out, "%*sAllowed Attributes:\n", indent, "") <= 0)
110 return 0;
111 aai = sk_OSSL_ALLOWED_ATTRIBUTES_ITEM_value(aaa, i);
112 if (i2r_ALLOWED_ATTRIBUTES_ITEM(method, aai, out, indent + 4) <= 0)
113 return 0;
114 }
115 return 1;
116 }
117
118 const X509V3_EXT_METHOD ossl_v3_allowed_attribute_assignments = {
119 NID_allowed_attribute_assignments, 0,
120 ASN1_ITEM_ref(OSSL_ALLOWED_ATTRIBUTES_SYNTAX),
121 0, 0, 0, 0,
122 0, 0,
123 0,
124 0,
125 (X509V3_EXT_I2R)i2r_ALLOWED_ATTRIBUTES_SYNTAX,
126 0,
127 NULL
128 };