2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-05-17 18:51:26 +00:00
|
|
|
* Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2003-03-20 17:26:44 +00:00
|
|
|
*
|
2016-05-17 18:51:26 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2003-03-20 17:26:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2003-03-20 17:26:44 +00:00
|
|
|
#include <openssl/asn1t.h>
|
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/x509v3.h>
|
2015-09-05 12:32:58 +00:00
|
|
|
#include "ext_dat.h"
|
2003-03-20 17:26:44 +00:00
|
|
|
|
2008-10-12 14:32:47 +00:00
|
|
|
static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
|
2015-01-22 03:40:55 +00:00
|
|
|
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
|
|
|
|
static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD
|
|
|
|
*method, void *pmps, STACK_OF(CONF_VALUE)
|
|
|
|
*extlist);
|
2003-03-20 17:26:44 +00:00
|
|
|
|
2007-01-21 13:07:17 +00:00
|
|
|
const X509V3_EXT_METHOD v3_policy_mappings = {
|
2015-01-22 03:40:55 +00:00
|
|
|
NID_policy_mappings, 0,
|
|
|
|
ASN1_ITEM_ref(POLICY_MAPPINGS),
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0,
|
|
|
|
i2v_POLICY_MAPPINGS,
|
|
|
|
v2i_POLICY_MAPPINGS,
|
|
|
|
0, 0,
|
|
|
|
NULL
|
2003-03-20 17:26:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ASN1_SEQUENCE(POLICY_MAPPING) = {
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_SIMPLE(POLICY_MAPPING, issuerDomainPolicy, ASN1_OBJECT),
|
|
|
|
ASN1_SIMPLE(POLICY_MAPPING, subjectDomainPolicy, ASN1_OBJECT)
|
2003-03-20 17:26:44 +00:00
|
|
|
} ASN1_SEQUENCE_END(POLICY_MAPPING)
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_ITEM_TEMPLATE(POLICY_MAPPINGS) =
|
|
|
|
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, POLICY_MAPPINGS,
|
|
|
|
POLICY_MAPPING)
|
2003-03-20 17:26:44 +00:00
|
|
|
ASN1_ITEM_TEMPLATE_END(POLICY_MAPPINGS)
|
|
|
|
|
2003-03-20 17:58:33 +00:00
|
|
|
IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING)
|
2003-03-20 17:26:44 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD
|
|
|
|
*method, void *a, STACK_OF(CONF_VALUE)
|
|
|
|
*ext_list)
|
2003-03-20 17:26:44 +00:00
|
|
|
{
|
2015-01-22 03:40:55 +00:00
|
|
|
POLICY_MAPPINGS *pmaps = a;
|
|
|
|
POLICY_MAPPING *pmap;
|
|
|
|
int i;
|
|
|
|
char obj_tmp1[80];
|
|
|
|
char obj_tmp2[80];
|
2017-09-28 21:30:22 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
for (i = 0; i < sk_POLICY_MAPPING_num(pmaps); i++) {
|
|
|
|
pmap = sk_POLICY_MAPPING_value(pmaps, i);
|
|
|
|
i2t_ASN1_OBJECT(obj_tmp1, 80, pmap->issuerDomainPolicy);
|
|
|
|
i2t_ASN1_OBJECT(obj_tmp2, 80, pmap->subjectDomainPolicy);
|
|
|
|
X509V3_add_value(obj_tmp1, obj_tmp2, &ext_list);
|
|
|
|
}
|
|
|
|
return ext_list;
|
2003-03-20 17:26:44 +00:00
|
|
|
}
|
|
|
|
|
2008-10-12 14:32:47 +00:00
|
|
|
static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method,
|
2015-01-22 03:40:55 +00:00
|
|
|
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
|
2003-03-20 17:26:44 +00:00
|
|
|
{
|
2016-04-27 15:50:14 +00:00
|
|
|
POLICY_MAPPING *pmap = NULL;
|
|
|
|
ASN1_OBJECT *obj1 = NULL, *obj2 = NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
CONF_VALUE *val;
|
2017-09-28 21:30:22 +00:00
|
|
|
POLICY_MAPPINGS *pmaps;
|
|
|
|
const int num = sk_CONF_VALUE_num(nval);
|
2015-01-22 03:40:55 +00:00
|
|
|
int i;
|
2003-03-20 17:26:44 +00:00
|
|
|
|
2017-10-26 17:56:14 +00:00
|
|
|
if ((pmaps = sk_POLICY_MAPPING_new_reserve(NULL, num)) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-03-20 17:26:44 +00:00
|
|
|
|
2017-09-28 21:30:22 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2015-01-22 03:40:55 +00:00
|
|
|
val = sk_CONF_VALUE_value(nval, i);
|
|
|
|
if (!val->value || !val->name) {
|
|
|
|
X509V3err(X509V3_F_V2I_POLICY_MAPPINGS,
|
|
|
|
X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
|
|
|
X509V3_conf_err(val);
|
2016-04-27 15:50:14 +00:00
|
|
|
goto err;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
obj1 = OBJ_txt2obj(val->name, 0);
|
|
|
|
obj2 = OBJ_txt2obj(val->value, 0);
|
|
|
|
if (!obj1 || !obj2) {
|
|
|
|
X509V3err(X509V3_F_V2I_POLICY_MAPPINGS,
|
|
|
|
X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
|
|
|
X509V3_conf_err(val);
|
2016-04-27 15:50:14 +00:00
|
|
|
goto err;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
pmap = POLICY_MAPPING_new();
|
2015-10-30 11:12:26 +00:00
|
|
|
if (pmap == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE);
|
2016-04-27 15:50:14 +00:00
|
|
|
goto err;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
pmap->issuerDomainPolicy = obj1;
|
|
|
|
pmap->subjectDomainPolicy = obj2;
|
2016-04-27 15:50:14 +00:00
|
|
|
obj1 = obj2 = NULL;
|
2017-09-28 21:30:22 +00:00
|
|
|
sk_POLICY_MAPPING_push(pmaps, pmap); /* no failure as it was reserved */
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
return pmaps;
|
2016-04-27 15:50:14 +00:00
|
|
|
err:
|
|
|
|
ASN1_OBJECT_free(obj1);
|
|
|
|
ASN1_OBJECT_free(obj2);
|
|
|
|
sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free);
|
|
|
|
return NULL;
|
2003-03-20 17:26:44 +00:00
|
|
|
}
|