x509cset.c 4.0 KB

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