2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2018-05-01 12:34:30 +00:00
|
|
|
* Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2004-03-23 14:14:35 +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
|
2004-03-23 14:14:35 +00:00
|
|
|
*/
|
|
|
|
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2004-03-23 14:14:35 +00:00
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/x509v3.h>
|
|
|
|
|
2019-09-27 21:58:06 +00:00
|
|
|
#include "pcy_local.h"
|
2004-03-23 14:14:35 +00:00
|
|
|
|
|
|
|
/* Policy Node routines */
|
|
|
|
|
|
|
|
void policy_data_free(X509_POLICY_DATA *data)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-05-29 11:08:26 +00:00
|
|
|
if (data == NULL)
|
2015-05-01 18:37:16 +00:00
|
|
|
return;
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_OBJECT_free(data->valid_policy);
|
|
|
|
/* Don't free qualifiers if shared */
|
|
|
|
if (!(data->flags & POLICY_DATA_FLAG_SHARED_QUALIFIERS))
|
|
|
|
sk_POLICYQUALINFO_pop_free(data->qualifier_set, POLICYQUALINFO_free);
|
|
|
|
sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free);
|
|
|
|
OPENSSL_free(data);
|
|
|
|
}
|
2004-03-23 14:14:35 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-06-14 21:02:16 +00:00
|
|
|
* Create a data based on an existing policy. If 'id' is NULL use the OID in
|
2015-01-22 03:40:55 +00:00
|
|
|
* the policy, otherwise use 'id'. This behaviour covers the two types of
|
2016-06-14 21:02:16 +00:00
|
|
|
* data in RFC3280: data with from a CertificatePolicies extension and
|
2015-01-22 03:40:55 +00:00
|
|
|
* additional data with just the qualifiers of anyPolicy and ID from another
|
|
|
|
* source.
|
2004-03-23 14:14:35 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-12 10:32:56 +00:00
|
|
|
X509_POLICY_DATA *policy_data_new(POLICYINFO *policy,
|
2015-01-22 03:40:55 +00:00
|
|
|
const ASN1_OBJECT *cid, int crit)
|
|
|
|
{
|
|
|
|
X509_POLICY_DATA *ret;
|
|
|
|
ASN1_OBJECT *id;
|
2018-03-28 20:32:31 +00:00
|
|
|
|
2017-05-29 11:08:26 +00:00
|
|
|
if (policy == NULL && cid == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
|
|
|
if (cid) {
|
|
|
|
id = OBJ_dup(cid);
|
2017-05-29 11:08:26 +00:00
|
|
|
if (id == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
|
|
|
} else
|
|
|
|
id = NULL;
|
2015-09-03 13:15:26 +00:00
|
|
|
ret = OPENSSL_zalloc(sizeof(*ret));
|
2018-03-28 20:32:31 +00:00
|
|
|
if (ret == NULL) {
|
|
|
|
X509V3err(X509V3_F_POLICY_DATA_NEW, ERR_R_MALLOC_FAILURE);
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
2018-03-28 20:32:31 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
ret->expected_policy_set = sk_ASN1_OBJECT_new_null();
|
2015-10-30 11:12:26 +00:00
|
|
|
if (ret->expected_policy_set == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(ret);
|
2015-03-24 11:52:24 +00:00
|
|
|
ASN1_OBJECT_free(id);
|
2018-03-28 20:32:31 +00:00
|
|
|
X509V3err(X509V3_F_POLICY_DATA_NEW, ERR_R_MALLOC_FAILURE);
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-23 14:14:35 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (crit)
|
|
|
|
ret->flags = POLICY_DATA_FLAG_CRITICAL;
|
2004-03-23 14:14:35 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (id)
|
|
|
|
ret->valid_policy = id;
|
|
|
|
else {
|
|
|
|
ret->valid_policy = policy->policyid;
|
|
|
|
policy->policyid = NULL;
|
|
|
|
}
|
2004-03-23 14:14:35 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (policy) {
|
|
|
|
ret->qualifier_set = policy->qualifiers;
|
|
|
|
policy->qualifiers = NULL;
|
2015-09-03 13:15:26 +00:00
|
|
|
}
|
2004-03-23 14:14:35 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|