2 * Copyright 2004-2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 typedef struct X509_POLICY_DATA_st X509_POLICY_DATA;
12 DEFINE_STACK_OF(X509_POLICY_DATA)
14 /* Internal structures */
17 * This structure and the field names correspond to the Policy 'node' of
18 * RFC3280. NB this structure contains no pointers to parent or child data:
19 * X509_POLICY_NODE contains that. This means that the main policy data can
20 * be kept static and cached with the certificate.
23 struct X509_POLICY_DATA_st {
25 /* Policy OID and qualifiers for this data */
26 ASN1_OBJECT *valid_policy;
27 STACK_OF(POLICYQUALINFO) *qualifier_set;
28 STACK_OF(ASN1_OBJECT) *expected_policy_set;
31 /* X509_POLICY_DATA flags values */
34 * This flag indicates the structure has been mapped using a policy mapping
35 * extension. If policy mapping is not active its references get deleted.
38 #define POLICY_DATA_FLAG_MAPPED 0x1
41 * This flag indicates the data doesn't correspond to a policy in Certificate
42 * Policies: it has been mapped to any policy.
45 #define POLICY_DATA_FLAG_MAPPED_ANY 0x2
47 /* AND with flags to see if any mapping has occurred */
49 #define POLICY_DATA_FLAG_MAP_MASK 0x3
51 /* qualifiers are shared and shouldn't be freed */
53 #define POLICY_DATA_FLAG_SHARED_QUALIFIERS 0x4
55 /* Parent node is an extra node and should be freed */
57 #define POLICY_DATA_FLAG_EXTRA_NODE 0x8
59 /* Corresponding CertificatePolicies is critical */
61 #define POLICY_DATA_FLAG_CRITICAL 0x10
63 /* This structure is cached with a certificate */
65 struct X509_POLICY_CACHE_st {
66 /* anyPolicy data or NULL if no anyPolicy */
67 X509_POLICY_DATA *anyPolicy;
68 /* other policy data */
69 STACK_OF(X509_POLICY_DATA) *data;
70 /* If InhibitAnyPolicy present this is its value or -1 if absent. */
73 * If policyConstraints and requireExplicitPolicy present this is its
74 * value or -1 if absent.
78 * If policyConstraints and policyMapping present this is its value or -1
85 * #define POLICY_CACHE_FLAG_CRITICAL POLICY_DATA_FLAG_CRITICAL
88 /* This structure represents the relationship between nodes */
90 struct X509_POLICY_NODE_st {
91 /* node data this refers to */
92 const X509_POLICY_DATA *data;
94 X509_POLICY_NODE *parent;
95 /* Number of child nodes */
99 struct X509_POLICY_LEVEL_st {
100 /* Cert for this level */
102 /* nodes at this level */
103 STACK_OF(X509_POLICY_NODE) *nodes;
105 X509_POLICY_NODE *anyPolicy;
108 * STACK_OF(X509_POLICY_DATA) *extra_data;
113 struct X509_POLICY_TREE_st {
114 /* The number of nodes in the tree */
116 /* The maximum number of nodes in the tree */
119 /* This is the tree 'level' data */
120 X509_POLICY_LEVEL *levels;
123 * Extra policy data when additional nodes (not from the certificate) are
126 STACK_OF(X509_POLICY_DATA) *extra_data;
127 /* This is the authority constrained policy set */
128 STACK_OF(X509_POLICY_NODE) *auth_policies;
129 STACK_OF(X509_POLICY_NODE) *user_policies;
133 /* Set if anyPolicy present in user policies */
134 #define POLICY_FLAG_ANY_POLICY 0x2
138 #define node_data_critical(data) (data->flags & POLICY_DATA_FLAG_CRITICAL)
139 #define node_critical(node) node_data_critical(node->data)
141 /* Internal functions */
143 X509_POLICY_DATA *ossl_policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id,
145 void ossl_policy_data_free(X509_POLICY_DATA *data);
147 X509_POLICY_DATA *ossl_policy_cache_find_data(const X509_POLICY_CACHE *cache,
148 const ASN1_OBJECT *id);
149 int ossl_policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps);
151 STACK_OF(X509_POLICY_NODE) *ossl_policy_node_cmp_new(void);
153 void ossl_policy_cache_free(X509_POLICY_CACHE *cache);
155 X509_POLICY_NODE *ossl_policy_level_find_node(const X509_POLICY_LEVEL *level,
156 const X509_POLICY_NODE *parent,
157 const ASN1_OBJECT *id);
159 X509_POLICY_NODE *ossl_policy_tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk,
160 const ASN1_OBJECT *id);
162 X509_POLICY_NODE *ossl_policy_level_add_node(X509_POLICY_LEVEL *level,
163 X509_POLICY_DATA *data,
164 X509_POLICY_NODE *parent,
165 X509_POLICY_TREE *tree,
167 void ossl_policy_node_free(X509_POLICY_NODE *node);
168 int ossl_policy_node_match(const X509_POLICY_LEVEL *lvl,
169 const X509_POLICY_NODE *node, const ASN1_OBJECT *oid);
171 const X509_POLICY_CACHE *ossl_policy_cache_set(X509 *x);