ts_req_utils.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright 2006-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 <openssl/objects.h>
  12. #include <openssl/x509v3.h>
  13. #include <openssl/ts.h>
  14. #include "ts_local.h"
  15. int TS_REQ_set_version(TS_REQ *a, long version)
  16. {
  17. return ASN1_INTEGER_set(a->version, version);
  18. }
  19. long TS_REQ_get_version(const TS_REQ *a)
  20. {
  21. return ASN1_INTEGER_get(a->version);
  22. }
  23. int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint)
  24. {
  25. TS_MSG_IMPRINT *new_msg_imprint;
  26. if (a->msg_imprint == msg_imprint)
  27. return 1;
  28. new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
  29. if (new_msg_imprint == NULL) {
  30. ERR_raise(ERR_LIB_TS, ERR_R_TS_LIB);
  31. return 0;
  32. }
  33. TS_MSG_IMPRINT_free(a->msg_imprint);
  34. a->msg_imprint = new_msg_imprint;
  35. return 1;
  36. }
  37. TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a)
  38. {
  39. return a->msg_imprint;
  40. }
  41. int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg)
  42. {
  43. X509_ALGOR *new_alg;
  44. if (a->hash_algo == alg)
  45. return 1;
  46. new_alg = X509_ALGOR_dup(alg);
  47. if (new_alg == NULL) {
  48. ERR_raise(ERR_LIB_TS, ERR_R_ASN1_LIB);
  49. return 0;
  50. }
  51. X509_ALGOR_free(a->hash_algo);
  52. a->hash_algo = new_alg;
  53. return 1;
  54. }
  55. X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a)
  56. {
  57. return a->hash_algo;
  58. }
  59. int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len)
  60. {
  61. return ASN1_OCTET_STRING_set(a->hashed_msg, d, len);
  62. }
  63. ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a)
  64. {
  65. return a->hashed_msg;
  66. }
  67. int TS_REQ_set_policy_id(TS_REQ *a, const ASN1_OBJECT *policy)
  68. {
  69. ASN1_OBJECT *new_policy;
  70. if (a->policy_id == policy)
  71. return 1;
  72. new_policy = OBJ_dup(policy);
  73. if (new_policy == NULL) {
  74. ERR_raise(ERR_LIB_TS, ERR_R_OBJ_LIB);
  75. return 0;
  76. }
  77. ASN1_OBJECT_free(a->policy_id);
  78. a->policy_id = new_policy;
  79. return 1;
  80. }
  81. ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a)
  82. {
  83. return a->policy_id;
  84. }
  85. int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce)
  86. {
  87. ASN1_INTEGER *new_nonce;
  88. if (a->nonce == nonce)
  89. return 1;
  90. new_nonce = ASN1_INTEGER_dup(nonce);
  91. if (new_nonce == NULL) {
  92. ERR_raise(ERR_LIB_TS, ERR_R_ASN1_LIB);
  93. return 0;
  94. }
  95. ASN1_INTEGER_free(a->nonce);
  96. a->nonce = new_nonce;
  97. return 1;
  98. }
  99. const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a)
  100. {
  101. return a->nonce;
  102. }
  103. int TS_REQ_set_cert_req(TS_REQ *a, int cert_req)
  104. {
  105. a->cert_req = cert_req ? 0xFF : 0x00;
  106. return 1;
  107. }
  108. int TS_REQ_get_cert_req(const TS_REQ *a)
  109. {
  110. return a->cert_req ? 1 : 0;
  111. }
  112. STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a)
  113. {
  114. return a->extensions;
  115. }
  116. void TS_REQ_ext_free(TS_REQ *a)
  117. {
  118. if (!a)
  119. return;
  120. sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
  121. a->extensions = NULL;
  122. }
  123. int TS_REQ_get_ext_count(TS_REQ *a)
  124. {
  125. return X509v3_get_ext_count(a->extensions);
  126. }
  127. int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos)
  128. {
  129. return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
  130. }
  131. int TS_REQ_get_ext_by_OBJ(TS_REQ *a, const ASN1_OBJECT *obj, int lastpos)
  132. {
  133. return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
  134. }
  135. int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos)
  136. {
  137. return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
  138. }
  139. X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc)
  140. {
  141. return X509v3_get_ext(a->extensions, loc);
  142. }
  143. X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc)
  144. {
  145. return X509v3_delete_ext(a->extensions, loc);
  146. }
  147. int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc)
  148. {
  149. return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
  150. }
  151. void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx)
  152. {
  153. return X509V3_get_d2i(a->extensions, nid, crit, idx);
  154. }