1160814Ssimon/* pcy_data.c */ 2194206Ssimon/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3160814Ssimon * project 2004. 4160814Ssimon */ 5160814Ssimon/* ==================================================================== 6160814Ssimon * Copyright (c) 2004 The OpenSSL Project. All rights reserved. 7160814Ssimon * 8160814Ssimon * Redistribution and use in source and binary forms, with or without 9160814Ssimon * modification, are permitted provided that the following conditions 10160814Ssimon * are met: 11160814Ssimon * 12160814Ssimon * 1. Redistributions of source code must retain the above copyright 13160814Ssimon * notice, this list of conditions and the following disclaimer. 14160814Ssimon * 15160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 16160814Ssimon * notice, this list of conditions and the following disclaimer in 17160814Ssimon * the documentation and/or other materials provided with the 18160814Ssimon * distribution. 19160814Ssimon * 20160814Ssimon * 3. All advertising materials mentioning features or use of this 21160814Ssimon * software must display the following acknowledgment: 22160814Ssimon * "This product includes software developed by the OpenSSL Project 23160814Ssimon * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24160814Ssimon * 25160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26160814Ssimon * endorse or promote products derived from this software without 27160814Ssimon * prior written permission. For written permission, please contact 28160814Ssimon * licensing@OpenSSL.org. 29160814Ssimon * 30160814Ssimon * 5. Products derived from this software may not be called "OpenSSL" 31160814Ssimon * nor may "OpenSSL" appear in their names without prior written 32160814Ssimon * permission of the OpenSSL Project. 33160814Ssimon * 34160814Ssimon * 6. Redistributions of any form whatsoever must retain the following 35160814Ssimon * acknowledgment: 36160814Ssimon * "This product includes software developed by the OpenSSL Project 37160814Ssimon * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 38160814Ssimon * 39160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42160814Ssimon * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE. 51160814Ssimon * ==================================================================== 52160814Ssimon * 53160814Ssimon * This product includes cryptographic software written by Eric Young 54160814Ssimon * (eay@cryptsoft.com). This product includes software written by Tim 55160814Ssimon * Hudson (tjh@cryptsoft.com). 56160814Ssimon * 57160814Ssimon */ 58160814Ssimon 59160814Ssimon#include "cryptlib.h" 60160814Ssimon#include <openssl/x509.h> 61160814Ssimon#include <openssl/x509v3.h> 62160814Ssimon 63160814Ssimon#include "pcy_int.h" 64160814Ssimon 65160814Ssimon/* Policy Node routines */ 66160814Ssimon 67160814Ssimonvoid policy_data_free(X509_POLICY_DATA *data) 68160814Ssimon { 69160814Ssimon ASN1_OBJECT_free(data->valid_policy); 70160814Ssimon /* Don't free qualifiers if shared */ 71160814Ssimon if (!(data->flags & POLICY_DATA_FLAG_SHARED_QUALIFIERS)) 72160814Ssimon sk_POLICYQUALINFO_pop_free(data->qualifier_set, 73160814Ssimon POLICYQUALINFO_free); 74160814Ssimon sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free); 75160814Ssimon OPENSSL_free(data); 76160814Ssimon } 77160814Ssimon 78160814Ssimon/* Create a data based on an existing policy. If 'id' is NULL use the 79160814Ssimon * oid in the policy, otherwise use 'id'. This behaviour covers the two 80160814Ssimon * types of data in RFC3280: data with from a CertificatePolcies extension 81160814Ssimon * and additional data with just the qualifiers of anyPolicy and ID from 82160814Ssimon * another source. 83160814Ssimon */ 84160814Ssimon 85238405SjkimX509_POLICY_DATA *policy_data_new(POLICYINFO *policy, 86238405Sjkim const ASN1_OBJECT *cid, int crit) 87160814Ssimon { 88160814Ssimon X509_POLICY_DATA *ret; 89238405Sjkim ASN1_OBJECT *id; 90238405Sjkim if (!policy && !cid) 91160814Ssimon return NULL; 92238405Sjkim if (cid) 93194206Ssimon { 94238405Sjkim id = OBJ_dup(cid); 95194206Ssimon if (!id) 96194206Ssimon return NULL; 97194206Ssimon } 98238405Sjkim else 99238405Sjkim id = NULL; 100160814Ssimon ret = OPENSSL_malloc(sizeof(X509_POLICY_DATA)); 101160814Ssimon if (!ret) 102160814Ssimon return NULL; 103160814Ssimon ret->expected_policy_set = sk_ASN1_OBJECT_new_null(); 104160814Ssimon if (!ret->expected_policy_set) 105160814Ssimon { 106160814Ssimon OPENSSL_free(ret); 107194206Ssimon if (id) 108194206Ssimon ASN1_OBJECT_free(id); 109160814Ssimon return NULL; 110160814Ssimon } 111160814Ssimon 112160814Ssimon if (crit) 113160814Ssimon ret->flags = POLICY_DATA_FLAG_CRITICAL; 114160814Ssimon else 115160814Ssimon ret->flags = 0; 116160814Ssimon 117160814Ssimon if (id) 118160814Ssimon ret->valid_policy = id; 119160814Ssimon else 120160814Ssimon { 121160814Ssimon ret->valid_policy = policy->policyid; 122160814Ssimon policy->policyid = NULL; 123160814Ssimon } 124160814Ssimon 125160814Ssimon if (policy) 126160814Ssimon { 127160814Ssimon ret->qualifier_set = policy->qualifiers; 128160814Ssimon policy->qualifiers = NULL; 129160814Ssimon } 130160814Ssimon else 131160814Ssimon ret->qualifier_set = NULL; 132160814Ssimon 133160814Ssimon return ret; 134160814Ssimon } 135160814Ssimon 136