pcy_local.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright 2004-2016 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. /* This is the tree 'level' data */
  90. X509_POLICY_LEVEL *levels;
  91. int nlevel;
  92. /*
  93. * Extra policy data when additional nodes (not from the certificate) are
  94. * required.
  95. */
  96. STACK_OF(X509_POLICY_DATA) *extra_data;
  97. /* This is the authority constrained policy set */
  98. STACK_OF(X509_POLICY_NODE) *auth_policies;
  99. STACK_OF(X509_POLICY_NODE) *user_policies;
  100. unsigned int flags;
  101. };
  102. /* Set if anyPolicy present in user policies */
  103. #define POLICY_FLAG_ANY_POLICY 0x2
  104. /* Useful macros */
  105. #define node_data_critical(data) (data->flags & POLICY_DATA_FLAG_CRITICAL)
  106. #define node_critical(node) node_data_critical(node->data)
  107. /* Internal functions */
  108. X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id,
  109. int crit);
  110. void policy_data_free(X509_POLICY_DATA *data);
  111. X509_POLICY_DATA *policy_cache_find_data(const X509_POLICY_CACHE *cache,
  112. const ASN1_OBJECT *id);
  113. int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps);
  114. STACK_OF(X509_POLICY_NODE) *policy_node_cmp_new(void);
  115. void policy_cache_init(void);
  116. void policy_cache_free(X509_POLICY_CACHE *cache);
  117. X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level,
  118. const X509_POLICY_NODE *parent,
  119. const ASN1_OBJECT *id);
  120. X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk,
  121. const ASN1_OBJECT *id);
  122. X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
  123. X509_POLICY_DATA *data,
  124. X509_POLICY_NODE *parent,
  125. X509_POLICY_TREE *tree);
  126. void policy_node_free(X509_POLICY_NODE *node);
  127. int policy_node_match(const X509_POLICY_LEVEL *lvl,
  128. const X509_POLICY_NODE *node, const ASN1_OBJECT *oid);
  129. const X509_POLICY_CACHE *policy_cache_set(X509 *x);