2 * Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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
11 #include "internal/cryptlib.h"
12 #include <openssl/asn1t.h>
13 #include <openssl/conf.h>
14 #include <openssl/x509v3.h>
17 static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
18 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
19 static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD
20 *method, void *pmps, STACK_OF(CONF_VALUE)
23 const X509V3_EXT_METHOD v3_policy_mappings = {
24 NID_policy_mappings, 0,
25 ASN1_ITEM_ref(POLICY_MAPPINGS),
34 ASN1_SEQUENCE(POLICY_MAPPING) = {
35 ASN1_SIMPLE(POLICY_MAPPING, issuerDomainPolicy, ASN1_OBJECT),
36 ASN1_SIMPLE(POLICY_MAPPING, subjectDomainPolicy, ASN1_OBJECT)
37 } ASN1_SEQUENCE_END(POLICY_MAPPING)
39 ASN1_ITEM_TEMPLATE(POLICY_MAPPINGS) =
40 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, POLICY_MAPPINGS,
42 ASN1_ITEM_TEMPLATE_END(POLICY_MAPPINGS)
44 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING)
46 static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD
47 *method, void *a, STACK_OF(CONF_VALUE)
50 POLICY_MAPPINGS *pmaps = a;
56 for (i = 0; i < sk_POLICY_MAPPING_num(pmaps); i++) {
57 pmap = sk_POLICY_MAPPING_value(pmaps, i);
58 i2t_ASN1_OBJECT(obj_tmp1, 80, pmap->issuerDomainPolicy);
59 i2t_ASN1_OBJECT(obj_tmp2, 80, pmap->subjectDomainPolicy);
60 X509V3_add_value(obj_tmp1, obj_tmp2, &ext_list);
65 static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
66 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
68 POLICY_MAPPING *pmap = NULL;
69 ASN1_OBJECT *obj1 = NULL, *obj2 = NULL;
71 POLICY_MAPPINGS *pmaps;
72 const int num = sk_CONF_VALUE_num(nval);
75 if ((pmaps = sk_POLICY_MAPPING_new_reserve(NULL, num)) == NULL) {
76 X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE);
80 for (i = 0; i < num; i++) {
81 val = sk_CONF_VALUE_value(nval, i);
82 if (!val->value || !val->name) {
83 X509V3err(X509V3_F_V2I_POLICY_MAPPINGS,
84 X509V3_R_INVALID_OBJECT_IDENTIFIER);
88 obj1 = OBJ_txt2obj(val->name, 0);
89 obj2 = OBJ_txt2obj(val->value, 0);
91 X509V3err(X509V3_F_V2I_POLICY_MAPPINGS,
92 X509V3_R_INVALID_OBJECT_IDENTIFIER);
96 pmap = POLICY_MAPPING_new();
98 X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE);
101 pmap->issuerDomainPolicy = obj1;
102 pmap->subjectDomainPolicy = obj2;
104 sk_POLICY_MAPPING_push(pmaps, pmap); /* no failure as it was reserved */
108 ASN1_OBJECT_free(obj1);
109 ASN1_OBJECT_free(obj2);
110 sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free);