ts_rsp_print.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/bn.h>
  13. #include <openssl/x509v3.h>
  14. #include <openssl/ts.h>
  15. #include "ts_lcl.h"
  16. struct status_map_st {
  17. int bit;
  18. const char *text;
  19. };
  20. static int ts_status_map_print(BIO *bio, const struct status_map_st *a,
  21. const ASN1_BIT_STRING *v);
  22. static int ts_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy);
  23. int TS_RESP_print_bio(BIO *bio, TS_RESP *a)
  24. {
  25. BIO_printf(bio, "Status info:\n");
  26. TS_STATUS_INFO_print_bio(bio, a->status_info);
  27. BIO_printf(bio, "\nTST info:\n");
  28. if (a->tst_info != NULL)
  29. TS_TST_INFO_print_bio(bio, a->tst_info);
  30. else
  31. BIO_printf(bio, "Not included.\n");
  32. return 1;
  33. }
  34. int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a)
  35. {
  36. static const char *status_map[] = {
  37. "Granted.",
  38. "Granted with modifications.",
  39. "Rejected.",
  40. "Waiting.",
  41. "Revocation warning.",
  42. "Revoked."
  43. };
  44. static const struct status_map_st failure_map[] = {
  45. {TS_INFO_BAD_ALG,
  46. "unrecognized or unsupported algorithm identifier"},
  47. {TS_INFO_BAD_REQUEST,
  48. "transaction not permitted or supported"},
  49. {TS_INFO_BAD_DATA_FORMAT,
  50. "the data submitted has the wrong format"},
  51. {TS_INFO_TIME_NOT_AVAILABLE,
  52. "the TSA's time source is not available"},
  53. {TS_INFO_UNACCEPTED_POLICY,
  54. "the requested TSA policy is not supported by the TSA"},
  55. {TS_INFO_UNACCEPTED_EXTENSION,
  56. "the requested extension is not supported by the TSA"},
  57. {TS_INFO_ADD_INFO_NOT_AVAILABLE,
  58. "the additional information requested could not be understood "
  59. "or is not available"},
  60. {TS_INFO_SYSTEM_FAILURE,
  61. "the request cannot be handled due to system failure"},
  62. {-1, NULL}
  63. };
  64. long status;
  65. int i, lines = 0;
  66. BIO_printf(bio, "Status: ");
  67. status = ASN1_INTEGER_get(a->status);
  68. if (0 <= status && status < (long)OSSL_NELEM(status_map))
  69. BIO_printf(bio, "%s\n", status_map[status]);
  70. else
  71. BIO_printf(bio, "out of bounds\n");
  72. BIO_printf(bio, "Status description: ");
  73. for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i) {
  74. if (i > 0)
  75. BIO_puts(bio, "\t");
  76. ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i), 0);
  77. BIO_puts(bio, "\n");
  78. }
  79. if (i == 0)
  80. BIO_printf(bio, "unspecified\n");
  81. BIO_printf(bio, "Failure info: ");
  82. if (a->failure_info != NULL)
  83. lines = ts_status_map_print(bio, failure_map, a->failure_info);
  84. if (lines == 0)
  85. BIO_printf(bio, "unspecified");
  86. BIO_printf(bio, "\n");
  87. return 1;
  88. }
  89. static int ts_status_map_print(BIO *bio, const struct status_map_st *a,
  90. const ASN1_BIT_STRING *v)
  91. {
  92. int lines = 0;
  93. for (; a->bit >= 0; ++a) {
  94. if (ASN1_BIT_STRING_get_bit(v, a->bit)) {
  95. if (++lines > 1)
  96. BIO_printf(bio, ", ");
  97. BIO_printf(bio, "%s", a->text);
  98. }
  99. }
  100. return lines;
  101. }
  102. int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a)
  103. {
  104. int v;
  105. if (a == NULL)
  106. return 0;
  107. v = ASN1_INTEGER_get(a->version);
  108. BIO_printf(bio, "Version: %d\n", v);
  109. BIO_printf(bio, "Policy OID: ");
  110. TS_OBJ_print_bio(bio, a->policy_id);
  111. TS_MSG_IMPRINT_print_bio(bio, a->msg_imprint);
  112. BIO_printf(bio, "Serial number: ");
  113. if (a->serial == NULL)
  114. BIO_printf(bio, "unspecified");
  115. else
  116. TS_ASN1_INTEGER_print_bio(bio, a->serial);
  117. BIO_write(bio, "\n", 1);
  118. BIO_printf(bio, "Time stamp: ");
  119. ASN1_GENERALIZEDTIME_print(bio, a->time);
  120. BIO_write(bio, "\n", 1);
  121. BIO_printf(bio, "Accuracy: ");
  122. if (a->accuracy == NULL)
  123. BIO_printf(bio, "unspecified");
  124. else
  125. ts_ACCURACY_print_bio(bio, a->accuracy);
  126. BIO_write(bio, "\n", 1);
  127. BIO_printf(bio, "Ordering: %s\n", a->ordering ? "yes" : "no");
  128. BIO_printf(bio, "Nonce: ");
  129. if (a->nonce == NULL)
  130. BIO_printf(bio, "unspecified");
  131. else
  132. TS_ASN1_INTEGER_print_bio(bio, a->nonce);
  133. BIO_write(bio, "\n", 1);
  134. BIO_printf(bio, "TSA: ");
  135. if (a->tsa == NULL)
  136. BIO_printf(bio, "unspecified");
  137. else {
  138. STACK_OF(CONF_VALUE) *nval;
  139. if ((nval = i2v_GENERAL_NAME(NULL, a->tsa, NULL)))
  140. X509V3_EXT_val_prn(bio, nval, 0, 0);
  141. sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
  142. }
  143. BIO_write(bio, "\n", 1);
  144. TS_ext_print_bio(bio, a->extensions);
  145. return 1;
  146. }
  147. static int ts_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *a)
  148. {
  149. if (a->seconds != NULL)
  150. TS_ASN1_INTEGER_print_bio(bio, a->seconds);
  151. else
  152. BIO_printf(bio, "unspecified");
  153. BIO_printf(bio, " seconds, ");
  154. if (a->millis != NULL)
  155. TS_ASN1_INTEGER_print_bio(bio, a->millis);
  156. else
  157. BIO_printf(bio, "unspecified");
  158. BIO_printf(bio, " millis, ");
  159. if (a->micros != NULL)
  160. TS_ASN1_INTEGER_print_bio(bio, a->micros);
  161. else
  162. BIO_printf(bio, "unspecified");
  163. BIO_printf(bio, " micros");
  164. return 1;
  165. }