1160814Ssimon/* pcy_int.h */ 2296465Sdelphij/* 3296465Sdelphij * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project 4296465Sdelphij * 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 14296465Sdelphij * 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 60160814SsimonDECLARE_STACK_OF(X509_POLICY_DATA) 61160814SsimonDECLARE_STACK_OF(X509_POLICY_REF) 62160814SsimonDECLARE_STACK_OF(X509_POLICY_NODE) 63160814Ssimon 64160814Ssimontypedef struct X509_POLICY_DATA_st X509_POLICY_DATA; 65160814Ssimontypedef struct X509_POLICY_REF_st X509_POLICY_REF; 66160814Ssimon 67160814Ssimon/* Internal structures */ 68160814Ssimon 69296465Sdelphij/* 70296465Sdelphij * This structure and the field names correspond to the Policy 'node' of 71296465Sdelphij * RFC3280. NB this structure contains no pointers to parent or child data: 72296465Sdelphij * X509_POLICY_NODE contains that. This means that the main policy data can 73296465Sdelphij * be kept static and cached with the certificate. 74160814Ssimon */ 75160814Ssimon 76296465Sdelphijstruct X509_POLICY_DATA_st { 77296465Sdelphij unsigned int flags; 78296465Sdelphij /* Policy OID and qualifiers for this data */ 79296465Sdelphij ASN1_OBJECT *valid_policy; 80296465Sdelphij STACK_OF(POLICYQUALINFO) *qualifier_set; 81296465Sdelphij STACK_OF(ASN1_OBJECT) *expected_policy_set; 82296465Sdelphij}; 83160814Ssimon 84160814Ssimon/* X509_POLICY_DATA flags values */ 85160814Ssimon 86296465Sdelphij/* 87296465Sdelphij * This flag indicates the structure has been mapped using a policy mapping 88296465Sdelphij * extension. If policy mapping is not active its references get deleted. 89160814Ssimon */ 90160814Ssimon 91296465Sdelphij#define POLICY_DATA_FLAG_MAPPED 0x1 92160814Ssimon 93296465Sdelphij/* 94296465Sdelphij * This flag indicates the data doesn't correspond to a policy in Certificate 95160814Ssimon * Policies: it has been mapped to any policy. 96160814Ssimon */ 97160814Ssimon 98296465Sdelphij#define POLICY_DATA_FLAG_MAPPED_ANY 0x2 99160814Ssimon 100160814Ssimon/* AND with flags to see if any mapping has occurred */ 101160814Ssimon 102296465Sdelphij#define POLICY_DATA_FLAG_MAP_MASK 0x3 103160814Ssimon 104160814Ssimon/* qualifiers are shared and shouldn't be freed */ 105160814Ssimon 106296465Sdelphij#define POLICY_DATA_FLAG_SHARED_QUALIFIERS 0x4 107160814Ssimon 108160814Ssimon/* Parent node is an extra node and should be freed */ 109160814Ssimon 110296465Sdelphij#define POLICY_DATA_FLAG_EXTRA_NODE 0x8 111160814Ssimon 112160814Ssimon/* Corresponding CertificatePolicies is critical */ 113160814Ssimon 114296465Sdelphij#define POLICY_DATA_FLAG_CRITICAL 0x10 115160814Ssimon 116296465Sdelphij/* 117296465Sdelphij * This structure is an entry from a table of mapped policies which cross 118296465Sdelphij * reference the policy it refers to. 119160814Ssimon */ 120160814Ssimon 121296465Sdelphijstruct X509_POLICY_REF_st { 122296465Sdelphij ASN1_OBJECT *subjectDomainPolicy; 123296465Sdelphij const X509_POLICY_DATA *data; 124296465Sdelphij}; 125160814Ssimon 126160814Ssimon/* This structure is cached with a certificate */ 127160814Ssimon 128160814Ssimonstruct X509_POLICY_CACHE_st { 129296465Sdelphij /* anyPolicy data or NULL if no anyPolicy */ 130296465Sdelphij X509_POLICY_DATA *anyPolicy; 131296465Sdelphij /* other policy data */ 132296465Sdelphij STACK_OF(X509_POLICY_DATA) *data; 133296465Sdelphij /* If policyMappings extension present a table of mapped policies */ 134296465Sdelphij STACK_OF(X509_POLICY_REF) *maps; 135296465Sdelphij /* If InhibitAnyPolicy present this is its value or -1 if absent. */ 136296465Sdelphij long any_skip; 137296465Sdelphij /* 138296465Sdelphij * If policyConstraints and requireExplicitPolicy present this is its 139296465Sdelphij * value or -1 if absent. 140296465Sdelphij */ 141296465Sdelphij long explicit_skip; 142296465Sdelphij /* 143296465Sdelphij * If policyConstraints and policyMapping present this is its value or -1 144296465Sdelphij * if absent. 145296465Sdelphij */ 146296465Sdelphij long map_skip; 147296465Sdelphij}; 148160814Ssimon 149296465Sdelphij/* 150296465Sdelphij * #define POLICY_CACHE_FLAG_CRITICAL POLICY_DATA_FLAG_CRITICAL 151296465Sdelphij */ 152160814Ssimon 153160814Ssimon/* This structure represents the relationship between nodes */ 154160814Ssimon 155296465Sdelphijstruct X509_POLICY_NODE_st { 156296465Sdelphij /* node data this refers to */ 157296465Sdelphij const X509_POLICY_DATA *data; 158296465Sdelphij /* Parent node */ 159296465Sdelphij X509_POLICY_NODE *parent; 160296465Sdelphij /* Number of child nodes */ 161296465Sdelphij int nchild; 162296465Sdelphij}; 163160814Ssimon 164296465Sdelphijstruct X509_POLICY_LEVEL_st { 165296465Sdelphij /* Cert for this level */ 166296465Sdelphij X509 *cert; 167296465Sdelphij /* nodes at this level */ 168296465Sdelphij STACK_OF(X509_POLICY_NODE) *nodes; 169296465Sdelphij /* anyPolicy node */ 170296465Sdelphij X509_POLICY_NODE *anyPolicy; 171296465Sdelphij /* Extra data */ 172296465Sdelphij /* 173296465Sdelphij * STACK_OF(X509_POLICY_DATA) *extra_data; 174296465Sdelphij */ 175296465Sdelphij unsigned int flags; 176296465Sdelphij}; 177160814Ssimon 178296465Sdelphijstruct X509_POLICY_TREE_st { 179296465Sdelphij /* This is the tree 'level' data */ 180296465Sdelphij X509_POLICY_LEVEL *levels; 181296465Sdelphij int nlevel; 182296465Sdelphij /* 183296465Sdelphij * Extra policy data when additional nodes (not from the certificate) are 184296465Sdelphij * required. 185296465Sdelphij */ 186296465Sdelphij STACK_OF(X509_POLICY_DATA) *extra_data; 187296465Sdelphij /* This is the authority constained policy set */ 188296465Sdelphij STACK_OF(X509_POLICY_NODE) *auth_policies; 189296465Sdelphij STACK_OF(X509_POLICY_NODE) *user_policies; 190296465Sdelphij unsigned int flags; 191296465Sdelphij}; 192160814Ssimon 193160814Ssimon/* Set if anyPolicy present in user policies */ 194296465Sdelphij#define POLICY_FLAG_ANY_POLICY 0x2 195160814Ssimon 196160814Ssimon/* Useful macros */ 197160814Ssimon 198160814Ssimon#define node_data_critical(data) (data->flags & POLICY_DATA_FLAG_CRITICAL) 199160814Ssimon#define node_critical(node) node_data_critical(node->data) 200160814Ssimon 201160814Ssimon/* Internal functions */ 202160814Ssimon 203160814SsimonX509_POLICY_DATA *policy_data_new(POLICYINFO *policy, ASN1_OBJECT *id, 204296465Sdelphij int crit); 205160814Ssimonvoid policy_data_free(X509_POLICY_DATA *data); 206160814Ssimon 207160814SsimonX509_POLICY_DATA *policy_cache_find_data(const X509_POLICY_CACHE *cache, 208296465Sdelphij const ASN1_OBJECT *id); 209160814Ssimonint policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps); 210160814Ssimon 211160814SsimonSTACK_OF(X509_POLICY_NODE) *policy_node_cmp_new(void); 212160814Ssimon 213160814Ssimonvoid policy_cache_init(void); 214160814Ssimon 215160814Ssimonvoid policy_cache_free(X509_POLICY_CACHE *cache); 216160814Ssimon 217160814SsimonX509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level, 218296465Sdelphij const ASN1_OBJECT *id); 219160814Ssimon 220160814SsimonX509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk, 221296465Sdelphij const ASN1_OBJECT *id); 222160814Ssimon 223160814SsimonX509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level, 224296465Sdelphij X509_POLICY_DATA *data, 225296465Sdelphij X509_POLICY_NODE *parent, 226296465Sdelphij X509_POLICY_TREE *tree); 227160814Ssimonvoid policy_node_free(X509_POLICY_NODE *node); 228160814Ssimon 229160814Ssimonconst X509_POLICY_CACHE *policy_cache_set(X509 *x); 230