1160814Ssimon/* pcy_lib.c */ 2280304Sjkim/* 3280304Sjkim * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project 4280304Sjkim * 2004. 5160814Ssimon */ 6160814Ssimon/* ==================================================================== 7160814Ssimon * Copyright (c) 2004 The OpenSSL Project. All rights reserved. 8160814Ssimon * 9160814Ssimon * Redistribution and use in source and binary forms, with or without 10160814Ssimon * modification, are permitted provided that the following conditions 11160814Ssimon * are met: 12160814Ssimon * 13160814Ssimon * 1. Redistributions of source code must retain the above copyright 14280304Sjkim * notice, this list of conditions and the following disclaimer. 15160814Ssimon * 16160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 17160814Ssimon * notice, this list of conditions and the following disclaimer in 18160814Ssimon * the documentation and/or other materials provided with the 19160814Ssimon * distribution. 20160814Ssimon * 21160814Ssimon * 3. All advertising materials mentioning features or use of this 22160814Ssimon * software must display the following acknowledgment: 23160814Ssimon * "This product includes software developed by the OpenSSL Project 24160814Ssimon * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 25160814Ssimon * 26160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27160814Ssimon * endorse or promote products derived from this software without 28160814Ssimon * prior written permission. For written permission, please contact 29160814Ssimon * licensing@OpenSSL.org. 30160814Ssimon * 31160814Ssimon * 5. Products derived from this software may not be called "OpenSSL" 32160814Ssimon * nor may "OpenSSL" appear in their names without prior written 33160814Ssimon * permission of the OpenSSL Project. 34160814Ssimon * 35160814Ssimon * 6. Redistributions of any form whatsoever must retain the following 36160814Ssimon * acknowledgment: 37160814Ssimon * "This product includes software developed by the OpenSSL Project 38160814Ssimon * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 39160814Ssimon * 40160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43160814Ssimon * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE. 52160814Ssimon * ==================================================================== 53160814Ssimon * 54160814Ssimon * This product includes cryptographic software written by Eric Young 55160814Ssimon * (eay@cryptsoft.com). This product includes software written by Tim 56160814Ssimon * Hudson (tjh@cryptsoft.com). 57160814Ssimon * 58160814Ssimon */ 59160814Ssimon 60160814Ssimon#include "cryptlib.h" 61160814Ssimon#include <openssl/x509.h> 62160814Ssimon#include <openssl/x509v3.h> 63160814Ssimon 64160814Ssimon#include "pcy_int.h" 65160814Ssimon 66160814Ssimon/* accessor functions */ 67160814Ssimon 68160814Ssimon/* X509_POLICY_TREE stuff */ 69160814Ssimon 70160814Ssimonint X509_policy_tree_level_count(const X509_POLICY_TREE *tree) 71280304Sjkim{ 72280304Sjkim if (!tree) 73280304Sjkim return 0; 74280304Sjkim return tree->nlevel; 75280304Sjkim} 76160814Ssimon 77280304SjkimX509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, 78280304Sjkim int i) 79280304Sjkim{ 80280304Sjkim if (!tree || (i < 0) || (i >= tree->nlevel)) 81280304Sjkim return NULL; 82280304Sjkim return tree->levels + i; 83280304Sjkim} 84160814Ssimon 85280304SjkimSTACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const 86280304Sjkim X509_POLICY_TREE 87280304Sjkim *tree) 88280304Sjkim{ 89280304Sjkim if (!tree) 90280304Sjkim return NULL; 91280304Sjkim return tree->auth_policies; 92280304Sjkim} 93160814Ssimon 94280304SjkimSTACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const 95280304Sjkim X509_POLICY_TREE 96280304Sjkim *tree) 97280304Sjkim{ 98280304Sjkim if (!tree) 99280304Sjkim return NULL; 100280304Sjkim if (tree->flags & POLICY_FLAG_ANY_POLICY) 101280304Sjkim return tree->auth_policies; 102280304Sjkim else 103280304Sjkim return tree->user_policies; 104280304Sjkim} 105160814Ssimon 106160814Ssimon/* X509_POLICY_LEVEL stuff */ 107160814Ssimon 108160814Ssimonint X509_policy_level_node_count(X509_POLICY_LEVEL *level) 109280304Sjkim{ 110280304Sjkim int n; 111280304Sjkim if (!level) 112280304Sjkim return 0; 113280304Sjkim if (level->anyPolicy) 114280304Sjkim n = 1; 115280304Sjkim else 116280304Sjkim n = 0; 117280304Sjkim if (level->nodes) 118280304Sjkim n += sk_X509_POLICY_NODE_num(level->nodes); 119280304Sjkim return n; 120280304Sjkim} 121160814Ssimon 122160814SsimonX509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i) 123280304Sjkim{ 124280304Sjkim if (!level) 125280304Sjkim return NULL; 126280304Sjkim if (level->anyPolicy) { 127280304Sjkim if (i == 0) 128280304Sjkim return level->anyPolicy; 129280304Sjkim i--; 130280304Sjkim } 131280304Sjkim return sk_X509_POLICY_NODE_value(level->nodes, i); 132280304Sjkim} 133160814Ssimon 134160814Ssimon/* X509_POLICY_NODE stuff */ 135160814Ssimon 136160814Ssimonconst ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node) 137280304Sjkim{ 138280304Sjkim if (!node) 139280304Sjkim return NULL; 140280304Sjkim return node->data->valid_policy; 141280304Sjkim} 142160814Ssimon 143160814Ssimon#if 0 144160814Ssimonint X509_policy_node_get_critical(const X509_POLICY_NODE *node) 145280304Sjkim{ 146280304Sjkim if (node_critical(node)) 147280304Sjkim return 1; 148280304Sjkim return 0; 149280304Sjkim} 150160814Ssimon#endif 151160814Ssimon 152280304SjkimSTACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const 153280304Sjkim X509_POLICY_NODE 154280304Sjkim *node) 155280304Sjkim{ 156280304Sjkim if (!node) 157280304Sjkim return NULL; 158280304Sjkim return node->data->qualifier_set; 159280304Sjkim} 160160814Ssimon 161280304Sjkimconst X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE 162280304Sjkim *node) 163280304Sjkim{ 164280304Sjkim if (!node) 165280304Sjkim return NULL; 166280304Sjkim return node->parent; 167280304Sjkim} 168