2
0

ts_rsp_print.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* crypto/ts/ts_resp_print.c */
  2. /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
  3. * project 2002.
  4. */
  5. /* ====================================================================
  6. * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. All advertising materials mentioning features or use of this
  21. * software must display the following acknowledgment:
  22. * "This product includes software developed by the OpenSSL Project
  23. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  24. *
  25. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  26. * endorse or promote products derived from this software without
  27. * prior written permission. For written permission, please contact
  28. * licensing@OpenSSL.org.
  29. *
  30. * 5. Products derived from this software may not be called "OpenSSL"
  31. * nor may "OpenSSL" appear in their names without prior written
  32. * permission of the OpenSSL Project.
  33. *
  34. * 6. Redistributions of any form whatsoever must retain the following
  35. * acknowledgment:
  36. * "This product includes software developed by the OpenSSL Project
  37. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  38. *
  39. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  40. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  41. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  43. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  45. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  46. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  48. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  50. * OF THE POSSIBILITY OF SUCH DAMAGE.
  51. * ====================================================================
  52. *
  53. * This product includes cryptographic software written by Eric Young
  54. * (eay@cryptsoft.com). This product includes software written by Tim
  55. * Hudson (tjh@cryptsoft.com).
  56. *
  57. */
  58. #include <stdio.h>
  59. #include "cryptlib.h"
  60. #include <openssl/objects.h>
  61. #include <openssl/bn.h>
  62. #include <openssl/x509v3.h>
  63. #include "ts.h"
  64. struct status_map_st
  65. {
  66. int bit;
  67. const char *text;
  68. };
  69. /* Local function declarations. */
  70. static int TS_status_map_print(BIO *bio, struct status_map_st *a,
  71. ASN1_BIT_STRING *v);
  72. static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy);
  73. /* Function definitions. */
  74. int TS_RESP_print_bio(BIO *bio, TS_RESP *a)
  75. {
  76. TS_TST_INFO *tst_info;
  77. BIO_printf(bio, "Status info:\n");
  78. TS_STATUS_INFO_print_bio(bio, TS_RESP_get_status_info(a));
  79. BIO_printf(bio, "\nTST info:\n");
  80. tst_info = TS_RESP_get_tst_info(a);
  81. if (tst_info != NULL)
  82. TS_TST_INFO_print_bio(bio, TS_RESP_get_tst_info(a));
  83. else
  84. BIO_printf(bio, "Not included.\n");
  85. return 1;
  86. }
  87. int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a)
  88. {
  89. static const char *status_map[] =
  90. {
  91. "Granted.",
  92. "Granted with modifications.",
  93. "Rejected.",
  94. "Waiting.",
  95. "Revocation warning.",
  96. "Revoked."
  97. };
  98. static struct status_map_st failure_map[] =
  99. {
  100. { TS_INFO_BAD_ALG,
  101. "unrecognized or unsupported algorithm identifier" },
  102. { TS_INFO_BAD_REQUEST,
  103. "transaction not permitted or supported" },
  104. { TS_INFO_BAD_DATA_FORMAT,
  105. "the data submitted has the wrong format" },
  106. { TS_INFO_TIME_NOT_AVAILABLE,
  107. "the TSA's time source is not available" },
  108. { TS_INFO_UNACCEPTED_POLICY,
  109. "the requested TSA policy is not supported by the TSA" },
  110. { TS_INFO_UNACCEPTED_EXTENSION,
  111. "the requested extension is not supported by the TSA" },
  112. { TS_INFO_ADD_INFO_NOT_AVAILABLE,
  113. "the additional information requested could not be understood "
  114. "or is not available" },
  115. { TS_INFO_SYSTEM_FAILURE,
  116. "the request cannot be handled due to system failure" },
  117. { -1, NULL }
  118. };
  119. long status;
  120. int i, lines = 0;
  121. /* Printing status code. */
  122. BIO_printf(bio, "Status: ");
  123. status = ASN1_INTEGER_get(a->status);
  124. if (0 <= status && status < (long)(sizeof(status_map)/sizeof(status_map[0])))
  125. BIO_printf(bio, "%s\n", status_map[status]);
  126. else
  127. BIO_printf(bio, "out of bounds\n");
  128. /* Printing status description. */
  129. BIO_printf(bio, "Status description: ");
  130. for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i)
  131. {
  132. if (i > 0)
  133. BIO_puts(bio, "\t");
  134. ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i),
  135. 0);
  136. BIO_puts(bio, "\n");
  137. }
  138. if (i == 0)
  139. BIO_printf(bio, "unspecified\n");
  140. /* Printing failure information. */
  141. BIO_printf(bio, "Failure info: ");
  142. if (a->failure_info != NULL)
  143. lines = TS_status_map_print(bio, failure_map,
  144. a->failure_info);
  145. if (lines == 0)
  146. BIO_printf(bio, "unspecified");
  147. BIO_printf(bio, "\n");
  148. return 1;
  149. }
  150. static int TS_status_map_print(BIO *bio, struct status_map_st *a,
  151. ASN1_BIT_STRING *v)
  152. {
  153. int lines = 0;
  154. for (; a->bit >= 0; ++a)
  155. {
  156. if (ASN1_BIT_STRING_get_bit(v, a->bit))
  157. {
  158. if (++lines > 1)
  159. BIO_printf(bio, ", ");
  160. BIO_printf(bio, "%s", a->text);
  161. }
  162. }
  163. return lines;
  164. }
  165. int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a)
  166. {
  167. int v;
  168. ASN1_OBJECT *policy_id;
  169. const ASN1_INTEGER *serial;
  170. const ASN1_GENERALIZEDTIME *gtime;
  171. TS_ACCURACY *accuracy;
  172. const ASN1_INTEGER *nonce;
  173. GENERAL_NAME *tsa_name;
  174. if (a == NULL) return 0;
  175. /* Print version. */
  176. v = TS_TST_INFO_get_version(a);
  177. BIO_printf(bio, "Version: %d\n", v);
  178. /* Print policy id. */
  179. BIO_printf(bio, "Policy OID: ");
  180. policy_id = TS_TST_INFO_get_policy_id(a);
  181. TS_OBJ_print_bio(bio, policy_id);
  182. /* Print message imprint. */
  183. TS_MSG_IMPRINT_print_bio(bio, TS_TST_INFO_get_msg_imprint(a));
  184. /* Print serial number. */
  185. BIO_printf(bio, "Serial number: ");
  186. serial = TS_TST_INFO_get_serial(a);
  187. if (serial == NULL)
  188. BIO_printf(bio, "unspecified");
  189. else
  190. TS_ASN1_INTEGER_print_bio(bio, serial);
  191. BIO_write(bio, "\n", 1);
  192. /* Print time stamp. */
  193. BIO_printf(bio, "Time stamp: ");
  194. gtime = TS_TST_INFO_get_time(a);
  195. ASN1_GENERALIZEDTIME_print(bio, gtime);
  196. BIO_write(bio, "\n", 1);
  197. /* Print accuracy. */
  198. BIO_printf(bio, "Accuracy: ");
  199. accuracy = TS_TST_INFO_get_accuracy(a);
  200. if (accuracy == NULL)
  201. BIO_printf(bio, "unspecified");
  202. else
  203. TS_ACCURACY_print_bio(bio, accuracy);
  204. BIO_write(bio, "\n", 1);
  205. /* Print ordering. */
  206. BIO_printf(bio, "Ordering: %s\n",
  207. TS_TST_INFO_get_ordering(a) ? "yes" : "no");
  208. /* Print nonce. */
  209. BIO_printf(bio, "Nonce: ");
  210. nonce = TS_TST_INFO_get_nonce(a);
  211. if (nonce == NULL)
  212. BIO_printf(bio, "unspecified");
  213. else
  214. TS_ASN1_INTEGER_print_bio(bio, nonce);
  215. BIO_write(bio, "\n", 1);
  216. /* Print TSA name. */
  217. BIO_printf(bio, "TSA: ");
  218. tsa_name = TS_TST_INFO_get_tsa(a);
  219. if (tsa_name == NULL)
  220. BIO_printf(bio, "unspecified");
  221. else
  222. {
  223. STACK_OF(CONF_VALUE) *nval;
  224. if ((nval = i2v_GENERAL_NAME(NULL, tsa_name, NULL)))
  225. X509V3_EXT_val_prn(bio, nval, 0, 0);
  226. sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
  227. }
  228. BIO_write(bio, "\n", 1);
  229. /* Print extensions. */
  230. TS_ext_print_bio(bio, TS_TST_INFO_get_exts(a));
  231. return 1;
  232. }
  233. static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy)
  234. {
  235. const ASN1_INTEGER *seconds = TS_ACCURACY_get_seconds(accuracy);
  236. const ASN1_INTEGER *millis = TS_ACCURACY_get_millis(accuracy);
  237. const ASN1_INTEGER *micros = TS_ACCURACY_get_micros(accuracy);
  238. if (seconds != NULL)
  239. TS_ASN1_INTEGER_print_bio(bio, seconds);
  240. else
  241. BIO_printf(bio, "unspecified");
  242. BIO_printf(bio, " seconds, ");
  243. if (millis != NULL)
  244. TS_ASN1_INTEGER_print_bio(bio, millis);
  245. else
  246. BIO_printf(bio, "unspecified");
  247. BIO_printf(bio, " millis, ");
  248. if (micros != NULL)
  249. TS_ASN1_INTEGER_print_bio(bio, micros);
  250. else
  251. BIO_printf(bio, "unspecified");
  252. BIO_printf(bio, " micros");
  253. return 1;
  254. }