/src/libressl/crypto/ts/ts_rsp_print.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* $OpenBSD: ts_rsp_print.c,v 1.6 2022/07/24 08:16:47 tb Exp $ */ |
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 | | |
59 | | #include <stdio.h> |
60 | | |
61 | | #include <openssl/bn.h> |
62 | | #include <openssl/objects.h> |
63 | | #include <openssl/ts.h> |
64 | | #include <openssl/x509v3.h> |
65 | | |
66 | | #include "ts_local.h" |
67 | | |
68 | | struct status_map_st { |
69 | | int bit; |
70 | | const char *text; |
71 | | }; |
72 | | |
73 | | /* Local function declarations. */ |
74 | | |
75 | | static int TS_status_map_print(BIO *bio, struct status_map_st *a, |
76 | | ASN1_BIT_STRING *v); |
77 | | static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy); |
78 | | |
79 | | /* Function definitions. */ |
80 | | |
81 | | int |
82 | | TS_RESP_print_bio(BIO *bio, TS_RESP *a) |
83 | 112 | { |
84 | 112 | TS_TST_INFO *tst_info; |
85 | | |
86 | 112 | BIO_printf(bio, "Status info:\n"); |
87 | 112 | TS_STATUS_INFO_print_bio(bio, TS_RESP_get_status_info(a)); |
88 | | |
89 | 112 | BIO_printf(bio, "\nTST info:\n"); |
90 | 112 | tst_info = TS_RESP_get_tst_info(a); |
91 | 112 | if (tst_info != NULL) |
92 | 0 | TS_TST_INFO_print_bio(bio, TS_RESP_get_tst_info(a)); |
93 | 112 | else |
94 | 112 | BIO_printf(bio, "Not included.\n"); |
95 | | |
96 | 112 | return 1; |
97 | 112 | } |
98 | | |
99 | | int |
100 | | TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a) |
101 | 579 | { |
102 | 579 | static const char *status_map[] = { |
103 | 579 | "Granted.", |
104 | 579 | "Granted with modifications.", |
105 | 579 | "Rejected.", |
106 | 579 | "Waiting.", |
107 | 579 | "Revocation warning.", |
108 | 579 | "Revoked." |
109 | 579 | }; |
110 | 579 | static struct status_map_st failure_map[] = { |
111 | 579 | { |
112 | 579 | TS_INFO_BAD_ALG, |
113 | 579 | "unrecognized or unsupported algorithm identifier" |
114 | 579 | }, |
115 | 579 | { |
116 | 579 | TS_INFO_BAD_REQUEST, |
117 | 579 | "transaction not permitted or supported" |
118 | 579 | }, |
119 | 579 | { |
120 | 579 | TS_INFO_BAD_DATA_FORMAT, |
121 | 579 | "the data submitted has the wrong format" |
122 | 579 | }, |
123 | 579 | { |
124 | 579 | TS_INFO_TIME_NOT_AVAILABLE, |
125 | 579 | "the TSA's time source is not available" |
126 | 579 | }, |
127 | 579 | { |
128 | 579 | TS_INFO_UNACCEPTED_POLICY, |
129 | 579 | "the requested TSA policy is not supported by the TSA" |
130 | 579 | }, |
131 | 579 | { |
132 | 579 | TS_INFO_UNACCEPTED_EXTENSION, |
133 | 579 | "the requested extension is not supported by the TSA" |
134 | 579 | }, |
135 | 579 | { |
136 | 579 | TS_INFO_ADD_INFO_NOT_AVAILABLE, |
137 | 579 | "the additional information requested could not be understood " |
138 | 579 | "or is not available" |
139 | 579 | }, |
140 | 579 | { |
141 | 579 | TS_INFO_SYSTEM_FAILURE, |
142 | 579 | "the request cannot be handled due to system failure" |
143 | 579 | }, |
144 | 579 | { -1, NULL } |
145 | 579 | }; |
146 | 579 | long status; |
147 | 579 | int i, lines = 0; |
148 | | |
149 | | /* Printing status code. */ |
150 | 579 | BIO_printf(bio, "Status: "); |
151 | 579 | status = ASN1_INTEGER_get(a->status); |
152 | 579 | if (0 <= status && |
153 | 579 | status < (long)(sizeof(status_map) / sizeof(status_map[0]))) |
154 | 16 | BIO_printf(bio, "%s\n", status_map[status]); |
155 | 563 | else |
156 | 563 | BIO_printf(bio, "out of bounds\n"); |
157 | | |
158 | | /* Printing status description. */ |
159 | 579 | BIO_printf(bio, "Status description: "); |
160 | 3.04k | for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i) { |
161 | 2.46k | if (i > 0) |
162 | 2.26k | BIO_puts(bio, "\t"); |
163 | 2.46k | ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i), |
164 | 2.46k | 0); |
165 | 2.46k | BIO_puts(bio, "\n"); |
166 | 2.46k | } |
167 | 579 | if (i == 0) |
168 | 381 | BIO_printf(bio, "unspecified\n"); |
169 | | |
170 | | /* Printing failure information. */ |
171 | 579 | BIO_printf(bio, "Failure info: "); |
172 | 579 | if (a->failure_info != NULL) |
173 | 26 | lines = TS_status_map_print(bio, failure_map, a->failure_info); |
174 | 579 | if (lines == 0) |
175 | 554 | BIO_printf(bio, "unspecified"); |
176 | 579 | BIO_printf(bio, "\n"); |
177 | | |
178 | 579 | return 1; |
179 | 579 | } |
180 | | |
181 | | static int |
182 | | TS_status_map_print(BIO *bio, struct status_map_st *a, ASN1_BIT_STRING *v) |
183 | 26 | { |
184 | 26 | int lines = 0; |
185 | | |
186 | 234 | for (; a->bit >= 0; ++a) { |
187 | 208 | if (ASN1_BIT_STRING_get_bit(v, a->bit)) { |
188 | 117 | if (++lines > 1) |
189 | 92 | BIO_printf(bio, ", "); |
190 | 117 | BIO_printf(bio, "%s", a->text); |
191 | 117 | } |
192 | 208 | } |
193 | | |
194 | 26 | return lines; |
195 | 26 | } |
196 | | |
197 | | int |
198 | | TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a) |
199 | 0 | { |
200 | 0 | int v; |
201 | 0 | ASN1_OBJECT *policy_id; |
202 | 0 | const ASN1_INTEGER *serial; |
203 | 0 | const ASN1_GENERALIZEDTIME *gtime; |
204 | 0 | TS_ACCURACY *accuracy; |
205 | 0 | const ASN1_INTEGER *nonce; |
206 | 0 | GENERAL_NAME *tsa_name; |
207 | |
|
208 | 0 | if (a == NULL) |
209 | 0 | return 0; |
210 | | |
211 | | /* Print version. */ |
212 | 0 | v = TS_TST_INFO_get_version(a); |
213 | 0 | BIO_printf(bio, "Version: %d\n", v); |
214 | | |
215 | | /* Print policy id. */ |
216 | 0 | BIO_printf(bio, "Policy OID: "); |
217 | 0 | policy_id = TS_TST_INFO_get_policy_id(a); |
218 | 0 | TS_OBJ_print_bio(bio, policy_id); |
219 | | |
220 | | /* Print message imprint. */ |
221 | 0 | TS_MSG_IMPRINT_print_bio(bio, TS_TST_INFO_get_msg_imprint(a)); |
222 | | |
223 | | /* Print serial number. */ |
224 | 0 | BIO_printf(bio, "Serial number: "); |
225 | 0 | serial = TS_TST_INFO_get_serial(a); |
226 | 0 | if (serial == NULL) |
227 | 0 | BIO_printf(bio, "unspecified"); |
228 | 0 | else |
229 | 0 | TS_ASN1_INTEGER_print_bio(bio, serial); |
230 | 0 | BIO_write(bio, "\n", 1); |
231 | | |
232 | | /* Print time stamp. */ |
233 | 0 | BIO_printf(bio, "Time stamp: "); |
234 | 0 | gtime = TS_TST_INFO_get_time(a); |
235 | 0 | ASN1_GENERALIZEDTIME_print(bio, gtime); |
236 | 0 | BIO_write(bio, "\n", 1); |
237 | | |
238 | | /* Print accuracy. */ |
239 | 0 | BIO_printf(bio, "Accuracy: "); |
240 | 0 | accuracy = TS_TST_INFO_get_accuracy(a); |
241 | 0 | if (accuracy == NULL) |
242 | 0 | BIO_printf(bio, "unspecified"); |
243 | 0 | else |
244 | 0 | TS_ACCURACY_print_bio(bio, accuracy); |
245 | 0 | BIO_write(bio, "\n", 1); |
246 | | |
247 | | /* Print ordering. */ |
248 | 0 | BIO_printf(bio, "Ordering: %s\n", |
249 | 0 | TS_TST_INFO_get_ordering(a) ? "yes" : "no"); |
250 | | |
251 | | /* Print nonce. */ |
252 | 0 | BIO_printf(bio, "Nonce: "); |
253 | 0 | nonce = TS_TST_INFO_get_nonce(a); |
254 | 0 | if (nonce == NULL) |
255 | 0 | BIO_printf(bio, "unspecified"); |
256 | 0 | else |
257 | 0 | TS_ASN1_INTEGER_print_bio(bio, nonce); |
258 | 0 | BIO_write(bio, "\n", 1); |
259 | | |
260 | | /* Print TSA name. */ |
261 | 0 | BIO_printf(bio, "TSA: "); |
262 | 0 | tsa_name = TS_TST_INFO_get_tsa(a); |
263 | 0 | if (tsa_name == NULL) |
264 | 0 | BIO_printf(bio, "unspecified"); |
265 | 0 | else { |
266 | 0 | STACK_OF(CONF_VALUE) *nval; |
267 | 0 | if ((nval = i2v_GENERAL_NAME(NULL, tsa_name, NULL))) |
268 | 0 | X509V3_EXT_val_prn(bio, nval, 0, 0); |
269 | 0 | sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); |
270 | 0 | } |
271 | 0 | BIO_write(bio, "\n", 1); |
272 | | |
273 | | /* Print extensions. */ |
274 | 0 | TS_ext_print_bio(bio, TS_TST_INFO_get_exts(a)); |
275 | |
|
276 | 0 | return 1; |
277 | 0 | } |
278 | | |
279 | | static int |
280 | | TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy) |
281 | 0 | { |
282 | 0 | const ASN1_INTEGER *seconds = TS_ACCURACY_get_seconds(accuracy); |
283 | 0 | const ASN1_INTEGER *millis = TS_ACCURACY_get_millis(accuracy); |
284 | 0 | const ASN1_INTEGER *micros = TS_ACCURACY_get_micros(accuracy); |
285 | |
|
286 | 0 | if (seconds != NULL) |
287 | 0 | TS_ASN1_INTEGER_print_bio(bio, seconds); |
288 | 0 | else |
289 | 0 | BIO_printf(bio, "unspecified"); |
290 | 0 | BIO_printf(bio, " seconds, "); |
291 | 0 | if (millis != NULL) |
292 | 0 | TS_ASN1_INTEGER_print_bio(bio, millis); |
293 | 0 | else |
294 | 0 | BIO_printf(bio, "unspecified"); |
295 | 0 | BIO_printf(bio, " millis, "); |
296 | 0 | if (micros != NULL) |
297 | 0 | TS_ASN1_INTEGER_print_bio(bio, micros); |
298 | 0 | else |
299 | 0 | BIO_printf(bio, "unspecified"); |
300 | 0 | BIO_printf(bio, " micros"); |
301 | |
|
302 | 0 | return 1; |
303 | 0 | } |