2
0

pcy_data.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2004-2021 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. #include "internal/cryptlib.h"
  10. #include <openssl/x509.h>
  11. #include <openssl/x509v3.h>
  12. #include "pcy_local.h"
  13. /* Policy Node routines */
  14. void ossl_policy_data_free(X509_POLICY_DATA *data)
  15. {
  16. if (data == NULL)
  17. return;
  18. ASN1_OBJECT_free(data->valid_policy);
  19. /* Don't free qualifiers if shared */
  20. if (!(data->flags & POLICY_DATA_FLAG_SHARED_QUALIFIERS))
  21. sk_POLICYQUALINFO_pop_free(data->qualifier_set, POLICYQUALINFO_free);
  22. sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free);
  23. OPENSSL_free(data);
  24. }
  25. /*
  26. * Create a data based on an existing policy. If 'id' is NULL use the OID in
  27. * the policy, otherwise use 'id'. This behaviour covers the two types of
  28. * data in RFC3280: data with from a CertificatePolicies extension and
  29. * additional data with just the qualifiers of anyPolicy and ID from another
  30. * source.
  31. */
  32. X509_POLICY_DATA *ossl_policy_data_new(POLICYINFO *policy,
  33. const ASN1_OBJECT *cid, int crit)
  34. {
  35. X509_POLICY_DATA *ret;
  36. ASN1_OBJECT *id;
  37. if (policy == NULL && cid == NULL)
  38. return NULL;
  39. if (cid) {
  40. id = OBJ_dup(cid);
  41. if (id == NULL)
  42. return NULL;
  43. } else
  44. id = NULL;
  45. ret = OPENSSL_zalloc(sizeof(*ret));
  46. if (ret == NULL) {
  47. ASN1_OBJECT_free(id);
  48. return NULL;
  49. }
  50. ret->expected_policy_set = sk_ASN1_OBJECT_new_null();
  51. if (ret->expected_policy_set == NULL) {
  52. OPENSSL_free(ret);
  53. ASN1_OBJECT_free(id);
  54. ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB);
  55. return NULL;
  56. }
  57. if (crit)
  58. ret->flags = POLICY_DATA_FLAG_CRITICAL;
  59. if (id)
  60. ret->valid_policy = id;
  61. else {
  62. ret->valid_policy = policy->policyid;
  63. policy->policyid = NULL;
  64. }
  65. if (policy) {
  66. ret->qualifier_set = policy->qualifiers;
  67. policy->qualifiers = NULL;
  68. }
  69. return ret;
  70. }