2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include <openssl/objects.h>
13 #include <openssl/bn.h>
14 #include <openssl/x509v3.h>
15 #include <openssl/ts.h>
18 DEFINE_STACK_OF(ASN1_UTF8STRING)
19 DEFINE_STACK_OF(CONF_VALUE)
21 struct status_map_st {
26 static int ts_status_map_print(BIO *bio, const struct status_map_st *a,
27 const ASN1_BIT_STRING *v);
28 static int ts_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy);
31 int TS_RESP_print_bio(BIO *bio, TS_RESP *a)
33 BIO_printf(bio, "Status info:\n");
34 TS_STATUS_INFO_print_bio(bio, a->status_info);
36 BIO_printf(bio, "\nTST info:\n");
37 if (a->tst_info != NULL)
38 TS_TST_INFO_print_bio(bio, a->tst_info);
40 BIO_printf(bio, "Not included.\n");
45 int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a)
47 static const char *status_map[] = {
49 "Granted with modifications.",
52 "Revocation warning.",
55 static const struct status_map_st failure_map[] = {
57 "unrecognized or unsupported algorithm identifier"},
59 "transaction not permitted or supported"},
60 {TS_INFO_BAD_DATA_FORMAT,
61 "the data submitted has the wrong format"},
62 {TS_INFO_TIME_NOT_AVAILABLE,
63 "the TSA's time source is not available"},
64 {TS_INFO_UNACCEPTED_POLICY,
65 "the requested TSA policy is not supported by the TSA"},
66 {TS_INFO_UNACCEPTED_EXTENSION,
67 "the requested extension is not supported by the TSA"},
68 {TS_INFO_ADD_INFO_NOT_AVAILABLE,
69 "the additional information requested could not be understood "
70 "or is not available"},
71 {TS_INFO_SYSTEM_FAILURE,
72 "the request cannot be handled due to system failure"},
78 BIO_printf(bio, "Status: ");
79 status = ASN1_INTEGER_get(a->status);
80 if (0 <= status && status < (long)OSSL_NELEM(status_map))
81 BIO_printf(bio, "%s\n", status_map[status]);
83 BIO_printf(bio, "out of bounds\n");
85 BIO_printf(bio, "Status description: ");
86 for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i) {
89 ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i), 0);
93 BIO_printf(bio, "unspecified\n");
95 BIO_printf(bio, "Failure info: ");
96 if (a->failure_info != NULL)
97 lines = ts_status_map_print(bio, failure_map, a->failure_info);
99 BIO_printf(bio, "unspecified");
100 BIO_printf(bio, "\n");
105 static int ts_status_map_print(BIO *bio, const struct status_map_st *a,
106 const ASN1_BIT_STRING *v)
110 for (; a->bit >= 0; ++a) {
111 if (ASN1_BIT_STRING_get_bit(v, a->bit)) {
113 BIO_printf(bio, ", ");
114 BIO_printf(bio, "%s", a->text);
121 int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a)
128 v = ASN1_INTEGER_get(a->version);
129 BIO_printf(bio, "Version: %d\n", v);
131 BIO_printf(bio, "Policy OID: ");
132 TS_OBJ_print_bio(bio, a->policy_id);
134 TS_MSG_IMPRINT_print_bio(bio, a->msg_imprint);
136 BIO_printf(bio, "Serial number: ");
137 if (a->serial == NULL)
138 BIO_printf(bio, "unspecified");
140 TS_ASN1_INTEGER_print_bio(bio, a->serial);
141 BIO_write(bio, "\n", 1);
143 BIO_printf(bio, "Time stamp: ");
144 ASN1_GENERALIZEDTIME_print(bio, a->time);
145 BIO_write(bio, "\n", 1);
147 BIO_printf(bio, "Accuracy: ");
148 if (a->accuracy == NULL)
149 BIO_printf(bio, "unspecified");
151 ts_ACCURACY_print_bio(bio, a->accuracy);
152 BIO_write(bio, "\n", 1);
154 BIO_printf(bio, "Ordering: %s\n", a->ordering ? "yes" : "no");
156 BIO_printf(bio, "Nonce: ");
157 if (a->nonce == NULL)
158 BIO_printf(bio, "unspecified");
160 TS_ASN1_INTEGER_print_bio(bio, a->nonce);
161 BIO_write(bio, "\n", 1);
163 BIO_printf(bio, "TSA: ");
165 BIO_printf(bio, "unspecified");
167 STACK_OF(CONF_VALUE) *nval;
168 if ((nval = i2v_GENERAL_NAME(NULL, a->tsa, NULL)))
169 X509V3_EXT_val_prn(bio, nval, 0, 0);
170 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
172 BIO_write(bio, "\n", 1);
174 TS_ext_print_bio(bio, a->extensions);
179 static int ts_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *a)
181 if (a->seconds != NULL)
182 TS_ASN1_INTEGER_print_bio(bio, a->seconds);
184 BIO_printf(bio, "unspecified");
185 BIO_printf(bio, " seconds, ");
186 if (a->millis != NULL)
187 TS_ASN1_INTEGER_print_bio(bio, a->millis);
189 BIO_printf(bio, "unspecified");
190 BIO_printf(bio, " millis, ");
191 if (a->micros != NULL)
192 TS_ASN1_INTEGER_print_bio(bio, a->micros);
194 BIO_printf(bio, "unspecified");
195 BIO_printf(bio, " micros");