/src/openssl/crypto/x509/v3_attrmap.c
Line  | Count  | Source  | 
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  |  |  | 
15  |  | ASN1_SEQUENCE(OSSL_ATAV) = { | 
16  |  |     ASN1_SIMPLE(OSSL_ATAV, type, ASN1_OBJECT),  | 
17  |  |     ASN1_SIMPLE(OSSL_ATAV, value, ASN1_ANY)  | 
18  | 0  | } ASN1_SEQUENCE_END(OSSL_ATAV)  | 
19  | 0  | 
  | 
20  | 0  | ASN1_SEQUENCE(OSSL_ATTRIBUTE_TYPE_MAPPING) = { | 
21  | 0  |     ASN1_IMP(OSSL_ATTRIBUTE_TYPE_MAPPING, local, ASN1_OBJECT, 0),  | 
22  | 0  |     ASN1_IMP(OSSL_ATTRIBUTE_TYPE_MAPPING, remote, ASN1_OBJECT, 1),  | 
23  | 0  | } ASN1_SEQUENCE_END(OSSL_ATTRIBUTE_TYPE_MAPPING)  | 
24  | 0  | 
  | 
25  | 0  | ASN1_SEQUENCE(OSSL_ATTRIBUTE_VALUE_MAPPING) = { | 
26  | 0  |     ASN1_IMP(OSSL_ATTRIBUTE_VALUE_MAPPING, local, OSSL_ATAV, 0),  | 
27  | 0  |     ASN1_IMP(OSSL_ATTRIBUTE_VALUE_MAPPING, remote, OSSL_ATAV, 1),  | 
28  | 0  | } ASN1_SEQUENCE_END(OSSL_ATTRIBUTE_VALUE_MAPPING)  | 
29  | 0  | 
  | 
30  | 0  | ASN1_CHOICE(OSSL_ATTRIBUTE_MAPPING) = { | 
31  | 0  |     ASN1_IMP(OSSL_ATTRIBUTE_MAPPING, choice.typeMappings,  | 
32  | 0  |              OSSL_ATTRIBUTE_TYPE_MAPPING, OSSL_ATTR_MAP_TYPE),  | 
33  | 0  |     ASN1_IMP(OSSL_ATTRIBUTE_MAPPING, choice.typeValueMappings,  | 
34  | 0  |              OSSL_ATTRIBUTE_VALUE_MAPPING, OSSL_ATTR_MAP_VALUE),  | 
35  | 0  | } ASN1_CHOICE_END(OSSL_ATTRIBUTE_MAPPING)  | 
36  | 0  | 
  | 
37  | 0  | ASN1_ITEM_TEMPLATE(OSSL_ATTRIBUTE_MAPPINGS) =  | 
38  | 0  |     ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, OSSL_ATTRIBUTE_MAPPINGS, OSSL_ATTRIBUTE_MAPPING)  | 
39  | 0  | ASN1_ITEM_TEMPLATE_END(OSSL_ATTRIBUTE_MAPPINGS)  | 
40  |  |  | 
41  |  | IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATAV)  | 
42  |  | IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_TYPE_MAPPING)  | 
43  |  | IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_VALUE_MAPPING)  | 
44  |  | IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_MAPPING)  | 
45  |  | IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_MAPPINGS)  | 
46  |  |  | 
47  |  | static int i2r_ATTRIBUTE_MAPPING(X509V3_EXT_METHOD *method,  | 
48  |  |                                  OSSL_ATTRIBUTE_MAPPING *am,  | 
49  |  |                                  BIO *out, int indent)  | 
50  | 0  | { | 
51  | 0  |     ASN1_OBJECT *local_type, *remote_type;  | 
52  | 0  |     int local_attr_nid, remote_attr_nid;  | 
53  | 0  |     ASN1_TYPE *local_val, *remote_val;  | 
54  |  | 
  | 
55  | 0  |     switch (am->type) { | 
56  | 0  |     case (OSSL_ATTR_MAP_TYPE):  | 
57  | 0  |         if (i2a_ASN1_OBJECT(out, am->choice.typeMappings->local) <= 0)  | 
58  | 0  |             return 0;  | 
59  | 0  |         if (BIO_puts(out, " == ") <= 0)  | 
60  | 0  |             return 0;  | 
61  | 0  |         return i2a_ASN1_OBJECT(out, am->choice.typeMappings->remote);  | 
62  | 0  |     case (OSSL_ATTR_MAP_VALUE):  | 
63  | 0  |         local_type = am->choice.typeValueMappings->local->type;  | 
64  | 0  |         remote_type = am->choice.typeValueMappings->remote->type;  | 
65  | 0  |         local_val = am->choice.typeValueMappings->local->value;  | 
66  | 0  |         remote_val = am->choice.typeValueMappings->remote->value;  | 
67  | 0  |         local_attr_nid = OBJ_obj2nid(local_type);  | 
68  | 0  |         remote_attr_nid = OBJ_obj2nid(remote_type);  | 
69  | 0  |         if (i2a_ASN1_OBJECT(out, local_type) <= 0)  | 
70  | 0  |             return 0;  | 
71  | 0  |         if (BIO_puts(out, ":") <= 0)  | 
72  | 0  |             return 0;  | 
73  | 0  |         if (ossl_print_attribute_value(out, local_attr_nid, local_val, 0) <= 0)  | 
74  | 0  |             return 0;  | 
75  | 0  |         if (BIO_puts(out, " == ") <= 0)  | 
76  | 0  |             return 0;  | 
77  | 0  |         if (i2a_ASN1_OBJECT(out, remote_type) <= 0)  | 
78  | 0  |             return 0;  | 
79  | 0  |         if (BIO_puts(out, ":") <= 0)  | 
80  | 0  |             return 0;  | 
81  | 0  |         return ossl_print_attribute_value(out, remote_attr_nid, remote_val, 0);  | 
82  | 0  |     default:  | 
83  | 0  |         return 0;  | 
84  | 0  |     }  | 
85  | 0  |     return 1;  | 
86  | 0  | }  | 
87  |  |  | 
88  |  | static int i2r_ATTRIBUTE_MAPPINGS(X509V3_EXT_METHOD *method,  | 
89  |  |                                   OSSL_ATTRIBUTE_MAPPINGS *ams,  | 
90  |  |                                   BIO *out, int indent)  | 
91  | 0  | { | 
92  | 0  |     int i;  | 
93  | 0  |     OSSL_ATTRIBUTE_MAPPING *am;  | 
94  |  | 
  | 
95  | 0  |     for (i = 0; i < sk_OSSL_ATTRIBUTE_MAPPING_num(ams); i++) { | 
96  | 0  |         am = sk_OSSL_ATTRIBUTE_MAPPING_value(ams, i);  | 
97  | 0  |         if (BIO_printf(out, "%*s", indent, "") <= 0)  | 
98  | 0  |             return 0;  | 
99  | 0  |         if (i2r_ATTRIBUTE_MAPPING(method, am, out, indent + 4) <= 0)  | 
100  | 0  |             return 0;  | 
101  | 0  |         if (BIO_puts(out, "\n") <= 0)  | 
102  | 0  |             return 0;  | 
103  | 0  |     }  | 
104  | 0  |     return 1;  | 
105  | 0  | }  | 
106  |  |  | 
107  |  | const X509V3_EXT_METHOD ossl_v3_attribute_mappings = { | 
108  |  |     NID_attribute_mappings, X509V3_EXT_MULTILINE,  | 
109  |  |     ASN1_ITEM_ref(OSSL_ATTRIBUTE_MAPPINGS),  | 
110  |  |     0, 0, 0, 0,  | 
111  |  |     0, 0,  | 
112  |  |     0,  | 
113  |  |     0,  | 
114  |  |     (X509V3_EXT_I2R)i2r_ATTRIBUTE_MAPPINGS,  | 
115  |  |     0,  | 
116  |  |     NULL  | 
117  |  | };  |