ts_rsp_utils.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * Copyright 2006-2016 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 <openssl/objects.h>
  12. #include <openssl/ts.h>
  13. #include <openssl/pkcs7.h>
  14. #include "ts_lcl.h"
  15. int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
  16. {
  17. TS_STATUS_INFO *new_status_info;
  18. if (a->status_info == status_info)
  19. return 1;
  20. new_status_info = TS_STATUS_INFO_dup(status_info);
  21. if (new_status_info == NULL) {
  22. TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
  23. return 0;
  24. }
  25. TS_STATUS_INFO_free(a->status_info);
  26. a->status_info = new_status_info;
  27. return 1;
  28. }
  29. TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a)
  30. {
  31. return a->status_info;
  32. }
  33. /* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
  34. void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
  35. {
  36. PKCS7_free(a->token);
  37. a->token = p7;
  38. TS_TST_INFO_free(a->tst_info);
  39. a->tst_info = tst_info;
  40. }
  41. PKCS7 *TS_RESP_get_token(TS_RESP *a)
  42. {
  43. return a->token;
  44. }
  45. TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a)
  46. {
  47. return a->tst_info;
  48. }
  49. int TS_TST_INFO_set_version(TS_TST_INFO *a, long version)
  50. {
  51. return ASN1_INTEGER_set(a->version, version);
  52. }
  53. long TS_TST_INFO_get_version(const TS_TST_INFO *a)
  54. {
  55. return ASN1_INTEGER_get(a->version);
  56. }
  57. int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
  58. {
  59. ASN1_OBJECT *new_policy;
  60. if (a->policy_id == policy)
  61. return 1;
  62. new_policy = OBJ_dup(policy);
  63. if (new_policy == NULL) {
  64. TSerr(TS_F_TS_TST_INFO_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
  65. return 0;
  66. }
  67. ASN1_OBJECT_free(a->policy_id);
  68. a->policy_id = new_policy;
  69. return 1;
  70. }
  71. ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a)
  72. {
  73. return a->policy_id;
  74. }
  75. int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
  76. {
  77. TS_MSG_IMPRINT *new_msg_imprint;
  78. if (a->msg_imprint == msg_imprint)
  79. return 1;
  80. new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
  81. if (new_msg_imprint == NULL) {
  82. TSerr(TS_F_TS_TST_INFO_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
  83. return 0;
  84. }
  85. TS_MSG_IMPRINT_free(a->msg_imprint);
  86. a->msg_imprint = new_msg_imprint;
  87. return 1;
  88. }
  89. TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a)
  90. {
  91. return a->msg_imprint;
  92. }
  93. int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
  94. {
  95. ASN1_INTEGER *new_serial;
  96. if (a->serial == serial)
  97. return 1;
  98. new_serial = ASN1_INTEGER_dup(serial);
  99. if (new_serial == NULL) {
  100. TSerr(TS_F_TS_TST_INFO_SET_SERIAL, ERR_R_MALLOC_FAILURE);
  101. return 0;
  102. }
  103. ASN1_INTEGER_free(a->serial);
  104. a->serial = new_serial;
  105. return 1;
  106. }
  107. const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a)
  108. {
  109. return a->serial;
  110. }
  111. int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
  112. {
  113. ASN1_GENERALIZEDTIME *new_time;
  114. if (a->time == gtime)
  115. return 1;
  116. new_time = ASN1_STRING_dup(gtime);
  117. if (new_time == NULL) {
  118. TSerr(TS_F_TS_TST_INFO_SET_TIME, ERR_R_MALLOC_FAILURE);
  119. return 0;
  120. }
  121. ASN1_GENERALIZEDTIME_free(a->time);
  122. a->time = new_time;
  123. return 1;
  124. }
  125. const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a)
  126. {
  127. return a->time;
  128. }
  129. int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
  130. {
  131. TS_ACCURACY *new_accuracy;
  132. if (a->accuracy == accuracy)
  133. return 1;
  134. new_accuracy = TS_ACCURACY_dup(accuracy);
  135. if (new_accuracy == NULL) {
  136. TSerr(TS_F_TS_TST_INFO_SET_ACCURACY, ERR_R_MALLOC_FAILURE);
  137. return 0;
  138. }
  139. TS_ACCURACY_free(a->accuracy);
  140. a->accuracy = new_accuracy;
  141. return 1;
  142. }
  143. TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a)
  144. {
  145. return a->accuracy;
  146. }
  147. int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
  148. {
  149. ASN1_INTEGER *new_seconds;
  150. if (a->seconds == seconds)
  151. return 1;
  152. new_seconds = ASN1_INTEGER_dup(seconds);
  153. if (new_seconds == NULL) {
  154. TSerr(TS_F_TS_ACCURACY_SET_SECONDS, ERR_R_MALLOC_FAILURE);
  155. return 0;
  156. }
  157. ASN1_INTEGER_free(a->seconds);
  158. a->seconds = new_seconds;
  159. return 1;
  160. }
  161. const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a)
  162. {
  163. return a->seconds;
  164. }
  165. int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
  166. {
  167. ASN1_INTEGER *new_millis = NULL;
  168. if (a->millis == millis)
  169. return 1;
  170. if (millis != NULL) {
  171. new_millis = ASN1_INTEGER_dup(millis);
  172. if (new_millis == NULL) {
  173. TSerr(TS_F_TS_ACCURACY_SET_MILLIS, ERR_R_MALLOC_FAILURE);
  174. return 0;
  175. }
  176. }
  177. ASN1_INTEGER_free(a->millis);
  178. a->millis = new_millis;
  179. return 1;
  180. }
  181. const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a)
  182. {
  183. return a->millis;
  184. }
  185. int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
  186. {
  187. ASN1_INTEGER *new_micros = NULL;
  188. if (a->micros == micros)
  189. return 1;
  190. if (micros != NULL) {
  191. new_micros = ASN1_INTEGER_dup(micros);
  192. if (new_micros == NULL) {
  193. TSerr(TS_F_TS_ACCURACY_SET_MICROS, ERR_R_MALLOC_FAILURE);
  194. return 0;
  195. }
  196. }
  197. ASN1_INTEGER_free(a->micros);
  198. a->micros = new_micros;
  199. return 1;
  200. }
  201. const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a)
  202. {
  203. return a->micros;
  204. }
  205. int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering)
  206. {
  207. a->ordering = ordering ? 0xFF : 0x00;
  208. return 1;
  209. }
  210. int TS_TST_INFO_get_ordering(const TS_TST_INFO *a)
  211. {
  212. return a->ordering ? 1 : 0;
  213. }
  214. int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
  215. {
  216. ASN1_INTEGER *new_nonce;
  217. if (a->nonce == nonce)
  218. return 1;
  219. new_nonce = ASN1_INTEGER_dup(nonce);
  220. if (new_nonce == NULL) {
  221. TSerr(TS_F_TS_TST_INFO_SET_NONCE, ERR_R_MALLOC_FAILURE);
  222. return 0;
  223. }
  224. ASN1_INTEGER_free(a->nonce);
  225. a->nonce = new_nonce;
  226. return 1;
  227. }
  228. const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a)
  229. {
  230. return a->nonce;
  231. }
  232. int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
  233. {
  234. GENERAL_NAME *new_tsa;
  235. if (a->tsa == tsa)
  236. return 1;
  237. new_tsa = GENERAL_NAME_dup(tsa);
  238. if (new_tsa == NULL) {
  239. TSerr(TS_F_TS_TST_INFO_SET_TSA, ERR_R_MALLOC_FAILURE);
  240. return 0;
  241. }
  242. GENERAL_NAME_free(a->tsa);
  243. a->tsa = new_tsa;
  244. return 1;
  245. }
  246. GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a)
  247. {
  248. return a->tsa;
  249. }
  250. STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a)
  251. {
  252. return a->extensions;
  253. }
  254. void TS_TST_INFO_ext_free(TS_TST_INFO *a)
  255. {
  256. if (!a)
  257. return;
  258. sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
  259. a->extensions = NULL;
  260. }
  261. int TS_TST_INFO_get_ext_count(TS_TST_INFO *a)
  262. {
  263. return X509v3_get_ext_count(a->extensions);
  264. }
  265. int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos)
  266. {
  267. return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
  268. }
  269. int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, const ASN1_OBJECT *obj, int lastpos)
  270. {
  271. return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
  272. }
  273. int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos)
  274. {
  275. return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
  276. }
  277. X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc)
  278. {
  279. return X509v3_get_ext(a->extensions, loc);
  280. }
  281. X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc)
  282. {
  283. return X509v3_delete_ext(a->extensions, loc);
  284. }
  285. int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc)
  286. {
  287. return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
  288. }
  289. void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx)
  290. {
  291. return X509V3_get_d2i(a->extensions, nid, crit, idx);
  292. }
  293. int TS_STATUS_INFO_set_status(TS_STATUS_INFO *a, int i)
  294. {
  295. return ASN1_INTEGER_set(a->status, i);
  296. }
  297. const ASN1_INTEGER *TS_STATUS_INFO_get0_status(const TS_STATUS_INFO *a)
  298. {
  299. return a->status;
  300. }
  301. const STACK_OF(ASN1_UTF8STRING) *
  302. TS_STATUS_INFO_get0_text(const TS_STATUS_INFO *a)
  303. {
  304. return a->text;
  305. }
  306. const ASN1_BIT_STRING *TS_STATUS_INFO_get0_failure_info(const TS_STATUS_INFO *a)
  307. {
  308. return a->failure_info;
  309. }