ts_rsp_print.c 7.7 KB

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