x509cset.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright 2001-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. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include "internal/refcount.h"
  12. #include <openssl/asn1.h>
  13. #include <openssl/objects.h>
  14. #include <openssl/evp.h>
  15. #include <openssl/x509.h>
  16. #include "crypto/x509.h"
  17. int X509_CRL_set_version(X509_CRL *x, long version)
  18. {
  19. if (x == NULL)
  20. return 0;
  21. if (x->crl.version == NULL) {
  22. if ((x->crl.version = ASN1_INTEGER_new()) == NULL)
  23. return 0;
  24. }
  25. if (!ASN1_INTEGER_set(x->crl.version, version))
  26. return 0;
  27. x->crl.enc.modified = 1;
  28. return 1;
  29. }
  30. int X509_CRL_set_issuer_name(X509_CRL *x, const X509_NAME *name)
  31. {
  32. if (x == NULL)
  33. return 0;
  34. if (!X509_NAME_set(&x->crl.issuer, name))
  35. return 0;
  36. x->crl.enc.modified = 1;
  37. return 1;
  38. }
  39. int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
  40. {
  41. if (x == NULL || tm == NULL)
  42. return 0;
  43. return ossl_x509_set1_time(&x->crl.enc.modified, &x->crl.lastUpdate, tm);
  44. }
  45. int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm)
  46. {
  47. if (x == NULL)
  48. return 0;
  49. return ossl_x509_set1_time(&x->crl.enc.modified, &x->crl.nextUpdate, tm);
  50. }
  51. int X509_CRL_sort(X509_CRL *c)
  52. {
  53. int i;
  54. X509_REVOKED *r;
  55. /*
  56. * sort the data so it will be written in serial number order
  57. */
  58. sk_X509_REVOKED_sort(c->crl.revoked);
  59. for (i = 0; i < sk_X509_REVOKED_num(c->crl.revoked); i++) {
  60. r = sk_X509_REVOKED_value(c->crl.revoked, i);
  61. r->sequence = i;
  62. }
  63. c->crl.enc.modified = 1;
  64. return 1;
  65. }
  66. int X509_CRL_up_ref(X509_CRL *crl)
  67. {
  68. int i;
  69. if (CRYPTO_UP_REF(&crl->references, &i) <= 0)
  70. return 0;
  71. REF_PRINT_COUNT("X509_CRL", crl);
  72. REF_ASSERT_ISNT(i < 2);
  73. return i > 1;
  74. }
  75. long X509_CRL_get_version(const X509_CRL *crl)
  76. {
  77. return ASN1_INTEGER_get(crl->crl.version);
  78. }
  79. const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl)
  80. {
  81. return crl->crl.lastUpdate;
  82. }
  83. const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl)
  84. {
  85. return crl->crl.nextUpdate;
  86. }
  87. #ifndef OPENSSL_NO_DEPRECATED_1_1_0
  88. ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl)
  89. {
  90. return crl->crl.lastUpdate;
  91. }
  92. ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl)
  93. {
  94. return crl->crl.nextUpdate;
  95. }
  96. #endif
  97. X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl)
  98. {
  99. return crl->crl.issuer;
  100. }
  101. const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl)
  102. {
  103. return crl->crl.extensions;
  104. }
  105. STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl)
  106. {
  107. return crl->crl.revoked;
  108. }
  109. void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
  110. const X509_ALGOR **palg)
  111. {
  112. if (psig != NULL)
  113. *psig = &crl->signature;
  114. if (palg != NULL)
  115. *palg = &crl->sig_alg;
  116. }
  117. int X509_CRL_get_signature_nid(const X509_CRL *crl)
  118. {
  119. return OBJ_obj2nid(crl->sig_alg.algorithm);
  120. }
  121. const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x)
  122. {
  123. return x->revocationDate;
  124. }
  125. int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
  126. {
  127. if (x == NULL || tm == NULL)
  128. return 0;
  129. return ossl_x509_set1_time(NULL, &x->revocationDate, tm);
  130. }
  131. const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x)
  132. {
  133. return &x->serialNumber;
  134. }
  135. int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
  136. {
  137. ASN1_INTEGER *in;
  138. if (x == NULL)
  139. return 0;
  140. in = &x->serialNumber;
  141. if (in != serial)
  142. return ASN1_STRING_copy(in, serial);
  143. return 1;
  144. }
  145. const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const
  146. X509_REVOKED *r)
  147. {
  148. return r->extensions;
  149. }
  150. int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **pp)
  151. {
  152. crl->crl.enc.modified = 1;
  153. return i2d_X509_CRL_INFO(&crl->crl, pp);
  154. }