pcy_local.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright 2004-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  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
  8. */
  9. typedef struct X509_POLICY_DATA_st X509_POLICY_DATA;
  10. DEFINE_STACK_OF(X509_POLICY_DATA)
  11. /* Internal structures */
  12. /*
  13. * This structure and the field names correspond to the Policy 'node' of
  14. * RFC3280. NB this structure contains no pointers to parent or child data:
  15. * X509_POLICY_NODE contains that. This means that the main policy data can
  16. * be kept static and cached with the certificate.
  17. */
  18. struct X509_POLICY_DATA_st {
  19. unsigned int flags;
  20. /* Policy OID and qualifiers for this data */
  21. ASN1_OBJECT *valid_policy;
  22. STACK_OF(POLICYQUALINFO) *qualifier_set;
  23. STACK_OF(ASN1_OBJECT) *expected_policy_set;
  24. };
  25. /* X509_POLICY_DATA flags values */
  26. /*
  27. * This flag indicates the structure has been mapped using a policy mapping
  28. * extension. If policy mapping is not active its references get deleted.
  29. */
  30. #define POLICY_DATA_FLAG_MAPPED 0x1
  31. /*
  32. * This flag indicates the data doesn't correspond to a policy in Certificate
  33. * Policies: it has been mapped to any policy.
  34. */
  35. #define POLICY_DATA_FLAG_MAPPED_ANY 0x2
  36. /* AND with flags to see if any mapping has occurred */
  37. #define POLICY_DATA_FLAG_MAP_MASK 0x3
  38. /* qualifiers are shared and shouldn't be freed */
  39. #define POLICY_DATA_FLAG_SHARED_QUALIFIERS 0x4
  40. /* Parent node is an extra node and should be freed */
  41. #define POLICY_DATA_FLAG_EXTRA_NODE 0x8
  42. /* Corresponding CertificatePolicies is critical */
  43. #define POLICY_DATA_FLAG_CRITICAL 0x10
  44. /* This structure is cached with a certificate */
  45. struct X509_POLICY_CACHE_st {
  46. /* anyPolicy data or NULL if no anyPolicy */
  47. X509_POLICY_DATA *anyPolicy;
  48. /* other policy data */
  49. STACK_OF(X509_POLICY_DATA) *data;
  50. /* If InhibitAnyPolicy present this is its value or -1 if absent. */
  51. long any_skip;
  52. /*
  53. * If policyConstraints and requireExplicitPolicy present this is its
  54. * value or -1 if absent.
  55. */
  56. long explicit_skip;
  57. /*
  58. * If policyConstraints and policyMapping present this is its value or -1
  59. * if absent.
  60. */
  61. long map_skip;
  62. };
  63. /*
  64. * #define POLICY_CACHE_FLAG_CRITICAL POLICY_DATA_FLAG_CRITICAL
  65. */
  66. /* This structure represents the relationship between nodes */
  67. struct X509_POLICY_NODE_st {
  68. /* node data this refers to */
  69. const X509_POLICY_DATA *data;
  70. /* Parent node */
  71. X509_POLICY_NODE *parent;
  72. /* Number of child nodes */
  73. int nchild;
  74. };
  75. struct X509_POLICY_LEVEL_st {
  76. /* Cert for this level */
  77. X509 *cert;
  78. /* nodes at this level */
  79. STACK_OF(X509_POLICY_NODE) *nodes;
  80. /* anyPolicy node */
  81. X509_POLICY_NODE *anyPolicy;
  82. /* Extra data */
  83. /*
  84. * STACK_OF(X509_POLICY_DATA) *extra_data;
  85. */
  86. unsigned int flags;
  87. };
  88. struct X509_POLICY_TREE_st {
  89. /* The number of nodes in the tree */
  90. size_t node_count;
  91. /* The maximum number of nodes in the tree */
  92. size_t node_maximum;
  93. /* This is the tree 'level' data */
  94. X509_POLICY_LEVEL *levels;
  95. int nlevel;
  96. /*
  97. * Extra policy data when additional nodes (not from the certificate) are
  98. * required.
  99. */
  100. STACK_OF(X509_POLICY_DATA) *extra_data;
  101. /* This is the authority constrained policy set */
  102. STACK_OF(X509_POLICY_NODE) *auth_policies;
  103. STACK_OF(X509_POLICY_NODE) *user_policies;
  104. unsigned int flags;
  105. };
  106. /* Set if anyPolicy present in user policies */
  107. #define POLICY_FLAG_ANY_POLICY 0x2
  108. /* Useful macros */
  109. #define node_data_critical(data) (data->flags & POLICY_DATA_FLAG_CRITICAL)
  110. #define node_critical(node) node_data_critical(node->data)
  111. /* Internal functions */
  112. X509_POLICY_DATA *ossl_policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id,
  113. int crit);
  114. void ossl_policy_data_free(X509_POLICY_DATA *data);
  115. X509_POLICY_DATA *ossl_policy_cache_find_data(const X509_POLICY_CACHE *cache,
  116. const ASN1_OBJECT *id);
  117. int ossl_policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps);
  118. STACK_OF(X509_POLICY_NODE) *ossl_policy_node_cmp_new(void);
  119. void ossl_policy_cache_free(X509_POLICY_CACHE *cache);
  120. X509_POLICY_NODE *ossl_policy_level_find_node(const X509_POLICY_LEVEL *level,
  121. const X509_POLICY_NODE *parent,
  122. const ASN1_OBJECT *id);
  123. X509_POLICY_NODE *ossl_policy_tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk,
  124. const ASN1_OBJECT *id);
  125. X509_POLICY_NODE *ossl_policy_level_add_node(X509_POLICY_LEVEL *level,
  126. X509_POLICY_DATA *data,
  127. X509_POLICY_NODE *parent,
  128. X509_POLICY_TREE *tree,
  129. int extra_data);
  130. void ossl_policy_node_free(X509_POLICY_NODE *node);
  131. int ossl_policy_node_match(const X509_POLICY_LEVEL *lvl,
  132. const X509_POLICY_NODE *node, const ASN1_OBJECT *oid);
  133. const X509_POLICY_CACHE *ossl_policy_cache_set(X509 *x);