Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1 | /* |
Matt Caswell | 6ec5fce | 2018-05-01 13:34:30 +0100 | [diff] [blame] | 2 | * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 3 | * |
Rich Salz | d2e9e32 | 2016-05-17 14:51:26 -0400 | [diff] [blame] | 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 |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Richard Levitte | b39fc56 | 2015-05-14 16:56:48 +0200 | [diff] [blame] | 10 | #include "internal/cryptlib.h" |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 11 | #include <openssl/x509.h> |
| 12 | #include <openssl/x509v3.h> |
| 13 | |
| 14 | #include "pcy_int.h" |
| 15 | |
| 16 | /* Policy Node routines */ |
| 17 | |
| 18 | void policy_data_free(X509_POLICY_DATA *data) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 19 | { |
HorimotoYasuhiro | 3f23390 | 2017-05-29 20:08:26 +0900 | [diff] [blame] | 20 | if (data == NULL) |
Rich Salz | 25aaa98 | 2015-05-01 14:37:16 -0400 | [diff] [blame] | 21 | return; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 22 | ASN1_OBJECT_free(data->valid_policy); |
| 23 | /* Don't free qualifiers if shared */ |
| 24 | if (!(data->flags & POLICY_DATA_FLAG_SHARED_QUALIFIERS)) |
| 25 | sk_POLICYQUALINFO_pop_free(data->qualifier_set, POLICYQUALINFO_free); |
| 26 | sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free); |
| 27 | OPENSSL_free(data); |
| 28 | } |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 29 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 30 | /* |
FdaSilvaYY | 0ad69cd | 2016-06-14 23:02:16 +0200 | [diff] [blame] | 31 | * Create a data based on an existing policy. If 'id' is NULL use the OID in |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 32 | * the policy, otherwise use 'id'. This behaviour covers the two types of |
FdaSilvaYY | 0ad69cd | 2016-06-14 23:02:16 +0200 | [diff] [blame] | 33 | * data in RFC3280: data with from a CertificatePolicies extension and |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 34 | * additional data with just the qualifiers of anyPolicy and ID from another |
| 35 | * source. |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 36 | */ |
| 37 | |
Dr. Stephen Henson | 002e66c | 2008-08-12 10:32:56 +0000 | [diff] [blame] | 38 | X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 39 | const ASN1_OBJECT *cid, int crit) |
| 40 | { |
| 41 | X509_POLICY_DATA *ret; |
| 42 | ASN1_OBJECT *id; |
FdaSilvaYY | 7fcdbd8 | 2018-03-28 22:32:31 +0200 | [diff] [blame] | 43 | |
HorimotoYasuhiro | 3f23390 | 2017-05-29 20:08:26 +0900 | [diff] [blame] | 44 | if (policy == NULL && cid == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 45 | return NULL; |
| 46 | if (cid) { |
| 47 | id = OBJ_dup(cid); |
HorimotoYasuhiro | 3f23390 | 2017-05-29 20:08:26 +0900 | [diff] [blame] | 48 | if (id == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 49 | return NULL; |
| 50 | } else |
| 51 | id = NULL; |
Rich Salz | 64b2575 | 2015-09-03 09:15:26 -0400 | [diff] [blame] | 52 | ret = OPENSSL_zalloc(sizeof(*ret)); |
FdaSilvaYY | 7fcdbd8 | 2018-03-28 22:32:31 +0200 | [diff] [blame] | 53 | if (ret == NULL) { |
| 54 | X509V3err(X509V3_F_POLICY_DATA_NEW, ERR_R_MALLOC_FAILURE); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 55 | return NULL; |
FdaSilvaYY | 7fcdbd8 | 2018-03-28 22:32:31 +0200 | [diff] [blame] | 56 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 57 | ret->expected_policy_set = sk_ASN1_OBJECT_new_null(); |
Matt Caswell | 90945fa | 2015-10-30 11:12:26 +0000 | [diff] [blame] | 58 | if (ret->expected_policy_set == NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 59 | OPENSSL_free(ret); |
Rich Salz | 0dfb939 | 2015-03-24 07:52:24 -0400 | [diff] [blame] | 60 | ASN1_OBJECT_free(id); |
FdaSilvaYY | 7fcdbd8 | 2018-03-28 22:32:31 +0200 | [diff] [blame] | 61 | X509V3err(X509V3_F_POLICY_DATA_NEW, ERR_R_MALLOC_FAILURE); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 62 | return NULL; |
| 63 | } |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 64 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 65 | if (crit) |
| 66 | ret->flags = POLICY_DATA_FLAG_CRITICAL; |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 67 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 68 | if (id) |
| 69 | ret->valid_policy = id; |
| 70 | else { |
| 71 | ret->valid_policy = policy->policyid; |
| 72 | policy->policyid = NULL; |
| 73 | } |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 74 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 75 | if (policy) { |
| 76 | ret->qualifier_set = policy->qualifiers; |
| 77 | policy->qualifiers = NULL; |
Rich Salz | 64b2575 | 2015-09-03 09:15:26 -0400 | [diff] [blame] | 78 | } |
Dr. Stephen Henson | 4acc3e9 | 2004-03-23 14:14:35 +0000 | [diff] [blame] | 79 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 80 | return ret; |
| 81 | } |