2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2021-04-08 20:04:41 +08:00
|
|
|
* Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2004-03-23 22:14:35 +08:00
|
|
|
*
|
2018-12-06 21:00:54 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:26 +08:00
|
|
|
* 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 22:14:35 +08:00
|
|
|
*/
|
|
|
|
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2004-03-23 22:14:35 +08:00
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/x509v3.h>
|
|
|
|
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "pcy_local.h"
|
2004-03-23 22:14:35 +08:00
|
|
|
|
|
|
|
/* Policy Node routines */
|
|
|
|
|
2021-03-09 11:23:45 +08:00
|
|
|
void ossl_policy_data_free(X509_POLICY_DATA *data)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-05-29 19:08:26 +08:00
|
|
|
if (data == NULL)
|
2015-05-02 02:37:16 +08:00
|
|
|
return;
|
2015-01-22 11:40:55 +08: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 22:14:35 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2016-06-15 05:02:16 +08:00
|
|
|
* Create a data based on an existing policy. If 'id' is NULL use the OID in
|
2015-01-22 11:40:55 +08:00
|
|
|
* the policy, otherwise use 'id'. This behaviour covers the two types of
|
2016-06-15 05:02:16 +08:00
|
|
|
* data in RFC3280: data with from a CertificatePolicies extension and
|
2015-01-22 11:40:55 +08:00
|
|
|
* additional data with just the qualifiers of anyPolicy and ID from another
|
|
|
|
* source.
|
2004-03-23 22:14:35 +08:00
|
|
|
*/
|
|
|
|
|
2021-03-09 11:23:45 +08:00
|
|
|
X509_POLICY_DATA *ossl_policy_data_new(POLICYINFO *policy,
|
|
|
|
const ASN1_OBJECT *cid, int crit)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
X509_POLICY_DATA *ret;
|
|
|
|
ASN1_OBJECT *id;
|
2018-03-29 04:32:31 +08:00
|
|
|
|
2017-05-29 19:08:26 +08:00
|
|
|
if (policy == NULL && cid == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
if (cid) {
|
|
|
|
id = OBJ_dup(cid);
|
2017-05-29 19:08:26 +08:00
|
|
|
if (id == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
} else
|
|
|
|
id = NULL;
|
2015-09-03 21:15:26 +08:00
|
|
|
ret = OPENSSL_zalloc(sizeof(*ret));
|
2018-03-29 04:32:31 +08:00
|
|
|
if (ret == NULL) {
|
2020-08-04 10:34:22 +08:00
|
|
|
ASN1_OBJECT_free(id);
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
2018-03-29 04:32:31 +08:00
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
ret->expected_policy_set = sk_ASN1_OBJECT_new_null();
|
2015-10-30 19:12:26 +08:00
|
|
|
if (ret->expected_policy_set == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
OPENSSL_free(ret);
|
2015-03-24 19:52:24 +08:00
|
|
|
ASN1_OBJECT_free(id);
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-23 22:14:35 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (crit)
|
|
|
|
ret->flags = POLICY_DATA_FLAG_CRITICAL;
|
2004-03-23 22:14:35 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (id)
|
|
|
|
ret->valid_policy = id;
|
|
|
|
else {
|
|
|
|
ret->valid_policy = policy->policyid;
|
|
|
|
policy->policyid = NULL;
|
|
|
|
}
|
2004-03-23 22:14:35 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (policy) {
|
|
|
|
ret->qualifier_set = policy->qualifiers;
|
|
|
|
policy->qualifiers = NULL;
|
2015-09-03 21:15:26 +08:00
|
|
|
}
|
2004-03-23 22:14:35 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
return ret;
|
|
|
|
}
|