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