]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
454afd98 | 2 | * Copyright 2003-2020 The OpenSSL Project Authors. All Rights Reserved. |
a1d12dae | 3 | * |
4286ca47 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
d2e9e320 RS |
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 | |
a1d12dae DSH |
8 | */ |
9 | ||
a1d12dae | 10 | #include <stdio.h> |
b39fc560 | 11 | #include "internal/cryptlib.h" |
a1d12dae DSH |
12 | #include <openssl/asn1t.h> |
13 | #include <openssl/conf.h> | |
14 | #include <openssl/x509v3.h> | |
df2ee0e2 | 15 | #include "ext_dat.h" |
a1d12dae | 16 | |
852c2ed2 RS |
17 | DEFINE_STACK_OF(POLICY_MAPPING) |
18 | DEFINE_STACK_OF(CONF_VALUE) | |
19 | ||
babb3798 | 20 | static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, |
0f113f3e MC |
21 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); |
22 | static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD | |
23 | *method, void *pmps, STACK_OF(CONF_VALUE) | |
24 | *extlist); | |
a1d12dae | 25 | |
560b79cb | 26 | const X509V3_EXT_METHOD v3_policy_mappings = { |
0f113f3e MC |
27 | NID_policy_mappings, 0, |
28 | ASN1_ITEM_ref(POLICY_MAPPINGS), | |
29 | 0, 0, 0, 0, | |
30 | 0, 0, | |
31 | i2v_POLICY_MAPPINGS, | |
32 | v2i_POLICY_MAPPINGS, | |
33 | 0, 0, | |
34 | NULL | |
a1d12dae DSH |
35 | }; |
36 | ||
37 | ASN1_SEQUENCE(POLICY_MAPPING) = { | |
0f113f3e MC |
38 | ASN1_SIMPLE(POLICY_MAPPING, issuerDomainPolicy, ASN1_OBJECT), |
39 | ASN1_SIMPLE(POLICY_MAPPING, subjectDomainPolicy, ASN1_OBJECT) | |
a1d12dae DSH |
40 | } ASN1_SEQUENCE_END(POLICY_MAPPING) |
41 | ||
0f113f3e MC |
42 | ASN1_ITEM_TEMPLATE(POLICY_MAPPINGS) = |
43 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, POLICY_MAPPINGS, | |
44 | POLICY_MAPPING) | |
a1d12dae DSH |
45 | ASN1_ITEM_TEMPLATE_END(POLICY_MAPPINGS) |
46 | ||
ea3675b5 | 47 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) |
a1d12dae | 48 | |
0f113f3e MC |
49 | static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD |
50 | *method, void *a, STACK_OF(CONF_VALUE) | |
51 | *ext_list) | |
a1d12dae | 52 | { |
0f113f3e MC |
53 | POLICY_MAPPINGS *pmaps = a; |
54 | POLICY_MAPPING *pmap; | |
55 | int i; | |
56 | char obj_tmp1[80]; | |
57 | char obj_tmp2[80]; | |
270a4bba | 58 | |
0f113f3e MC |
59 | for (i = 0; i < sk_POLICY_MAPPING_num(pmaps); i++) { |
60 | pmap = sk_POLICY_MAPPING_value(pmaps, i); | |
61 | i2t_ASN1_OBJECT(obj_tmp1, 80, pmap->issuerDomainPolicy); | |
62 | i2t_ASN1_OBJECT(obj_tmp2, 80, pmap->subjectDomainPolicy); | |
63 | X509V3_add_value(obj_tmp1, obj_tmp2, &ext_list); | |
64 | } | |
65 | return ext_list; | |
a1d12dae DSH |
66 | } |
67 | ||
babb3798 | 68 | static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, |
0f113f3e | 69 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) |
a1d12dae | 70 | { |
379a8ed1 MC |
71 | POLICY_MAPPING *pmap = NULL; |
72 | ASN1_OBJECT *obj1 = NULL, *obj2 = NULL; | |
0f113f3e | 73 | CONF_VALUE *val; |
270a4bba F |
74 | POLICY_MAPPINGS *pmaps; |
75 | const int num = sk_CONF_VALUE_num(nval); | |
0f113f3e | 76 | int i; |
a1d12dae | 77 | |
7a908204 | 78 | if ((pmaps = sk_POLICY_MAPPING_new_reserve(NULL, num)) == NULL) { |
0f113f3e MC |
79 | X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE); |
80 | return NULL; | |
81 | } | |
a1d12dae | 82 | |
270a4bba | 83 | for (i = 0; i < num; i++) { |
0f113f3e MC |
84 | val = sk_CONF_VALUE_value(nval, i); |
85 | if (!val->value || !val->name) { | |
0f113f3e MC |
86 | X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, |
87 | X509V3_R_INVALID_OBJECT_IDENTIFIER); | |
88 | X509V3_conf_err(val); | |
379a8ed1 | 89 | goto err; |
0f113f3e MC |
90 | } |
91 | obj1 = OBJ_txt2obj(val->name, 0); | |
92 | obj2 = OBJ_txt2obj(val->value, 0); | |
93 | if (!obj1 || !obj2) { | |
0f113f3e MC |
94 | X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, |
95 | X509V3_R_INVALID_OBJECT_IDENTIFIER); | |
96 | X509V3_conf_err(val); | |
379a8ed1 | 97 | goto err; |
0f113f3e MC |
98 | } |
99 | pmap = POLICY_MAPPING_new(); | |
90945fa3 | 100 | if (pmap == NULL) { |
0f113f3e | 101 | X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE); |
379a8ed1 | 102 | goto err; |
0f113f3e MC |
103 | } |
104 | pmap->issuerDomainPolicy = obj1; | |
105 | pmap->subjectDomainPolicy = obj2; | |
379a8ed1 | 106 | obj1 = obj2 = NULL; |
270a4bba | 107 | sk_POLICY_MAPPING_push(pmaps, pmap); /* no failure as it was reserved */ |
0f113f3e MC |
108 | } |
109 | return pmaps; | |
379a8ed1 MC |
110 | err: |
111 | ASN1_OBJECT_free(obj1); | |
112 | ASN1_OBJECT_free(obj2); | |
113 | sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free); | |
114 | return NULL; | |
a1d12dae | 115 | } |