x509cset.c 4.1 KB

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