/src/boringssl/crypto/x509/v3_pmaps.cc
Line | Count | Source |
1 | | // Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <stdio.h> |
16 | | |
17 | | #include <openssl/asn1t.h> |
18 | | #include <openssl/conf.h> |
19 | | #include <openssl/err.h> |
20 | | #include <openssl/obj.h> |
21 | | #include <openssl/x509.h> |
22 | | |
23 | | #include "internal.h" |
24 | | |
25 | | |
26 | | static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, |
27 | | const X509V3_CTX *ctx, |
28 | | const STACK_OF(CONF_VALUE) *nval); |
29 | | static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS( |
30 | | const X509V3_EXT_METHOD *method, void *pmps, STACK_OF(CONF_VALUE) *extlist); |
31 | | |
32 | | const X509V3_EXT_METHOD v3_policy_mappings = { |
33 | | NID_policy_mappings, |
34 | | 0, |
35 | | ASN1_ITEM_ref(POLICY_MAPPINGS), |
36 | | nullptr, |
37 | | nullptr, |
38 | | nullptr, |
39 | | nullptr, |
40 | | nullptr, |
41 | | nullptr, |
42 | | i2v_POLICY_MAPPINGS, |
43 | | v2i_POLICY_MAPPINGS, |
44 | | nullptr, |
45 | | nullptr, |
46 | | nullptr, |
47 | | }; |
48 | | |
49 | | ASN1_SEQUENCE(POLICY_MAPPING) = { |
50 | | ASN1_SIMPLE(POLICY_MAPPING, issuerDomainPolicy, ASN1_OBJECT), |
51 | | ASN1_SIMPLE(POLICY_MAPPING, subjectDomainPolicy, ASN1_OBJECT), |
52 | | } ASN1_SEQUENCE_END(POLICY_MAPPING) |
53 | | |
54 | | ASN1_ITEM_TEMPLATE(POLICY_MAPPINGS) = ASN1_EX_TEMPLATE_TYPE( |
55 | | ASN1_TFLG_SEQUENCE_OF, 0, POLICY_MAPPINGS, POLICY_MAPPING) |
56 | | ASN1_ITEM_TEMPLATE_END(POLICY_MAPPINGS) |
57 | | |
58 | | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) |
59 | | |
60 | | static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS( |
61 | 62 | const X509V3_EXT_METHOD *method, void *a, STACK_OF(CONF_VALUE) *ext_list) { |
62 | 62 | const POLICY_MAPPINGS *pmaps = reinterpret_cast<POLICY_MAPPINGS *>(a); |
63 | 127 | for (size_t i = 0; i < sk_POLICY_MAPPING_num(pmaps); i++) { |
64 | 65 | const POLICY_MAPPING *pmap = sk_POLICY_MAPPING_value(pmaps, i); |
65 | 65 | char obj_tmp1[80], obj_tmp2[80]; |
66 | 65 | i2t_ASN1_OBJECT(obj_tmp1, 80, pmap->issuerDomainPolicy); |
67 | 65 | i2t_ASN1_OBJECT(obj_tmp2, 80, pmap->subjectDomainPolicy); |
68 | 65 | X509V3_add_value(obj_tmp1, obj_tmp2, &ext_list); |
69 | 65 | } |
70 | 62 | return ext_list; |
71 | 62 | } |
72 | | |
73 | | static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, |
74 | | const X509V3_CTX *ctx, |
75 | 85 | const STACK_OF(CONF_VALUE) *nval) { |
76 | 85 | POLICY_MAPPINGS *pmaps = sk_POLICY_MAPPING_new_null(); |
77 | 85 | if (pmaps == nullptr) { |
78 | 0 | return nullptr; |
79 | 0 | } |
80 | | |
81 | 456 | for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
82 | 429 | const CONF_VALUE *val = sk_CONF_VALUE_value(nval, i); |
83 | 429 | if (!val->value || !val->name) { |
84 | 15 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER); |
85 | 15 | X509V3_conf_err(val); |
86 | 15 | goto err; |
87 | 15 | } |
88 | | |
89 | 414 | POLICY_MAPPING *pmap = POLICY_MAPPING_new(); |
90 | 414 | if (pmap == nullptr || !sk_POLICY_MAPPING_push(pmaps, pmap)) { |
91 | 0 | POLICY_MAPPING_free(pmap); |
92 | 0 | goto err; |
93 | 0 | } |
94 | | |
95 | 414 | pmap->issuerDomainPolicy = OBJ_txt2obj(val->name, 0); |
96 | 414 | pmap->subjectDomainPolicy = OBJ_txt2obj(val->value, 0); |
97 | 414 | if (!pmap->issuerDomainPolicy || !pmap->subjectDomainPolicy) { |
98 | 43 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER); |
99 | 43 | X509V3_conf_err(val); |
100 | 43 | goto err; |
101 | 43 | } |
102 | 414 | } |
103 | 27 | return pmaps; |
104 | | |
105 | 58 | err: |
106 | 58 | sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free); |
107 | 58 | return nullptr; |
108 | 85 | } |