]>
Commit | Line | Data |
---|---|---|
0f113f3e MC |
1 | /* |
2 | * Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL project | |
3 | * 2002. | |
c7235be6 UM |
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 | |
0f113f3e | 13 | * notice, this list of conditions and the following disclaimer. |
c7235be6 UM |
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> | |
b39fc560 | 60 | #include "internal/cryptlib.h" |
c7235be6 UM |
61 | #include <openssl/objects.h> |
62 | #include <openssl/bn.h> | |
63 | #include <openssl/x509v3.h> | |
e52a3c3d | 64 | #include <openssl/ts.h> |
ca4a494c | 65 | #include "ts_lcl.h" |
c7235be6 | 66 | |
0f113f3e MC |
67 | struct status_map_st { |
68 | int bit; | |
69 | const char *text; | |
70 | }; | |
c7235be6 | 71 | |
9c422b5b | 72 | static int ts_status_map_print(BIO *bio, const struct status_map_st *a, |
0f113f3e | 73 | const ASN1_BIT_STRING *v); |
9c422b5b | 74 | static int ts_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy); |
c7235be6 | 75 | |
c7235be6 UM |
76 | |
77 | int TS_RESP_print_bio(BIO *bio, TS_RESP *a) | |
0f113f3e | 78 | { |
0f113f3e | 79 | BIO_printf(bio, "Status info:\n"); |
ca4a494c | 80 | TS_STATUS_INFO_print_bio(bio, a->status_info); |
0f113f3e MC |
81 | |
82 | BIO_printf(bio, "\nTST info:\n"); | |
ca4a494c RS |
83 | if (a->tst_info != NULL) |
84 | TS_TST_INFO_print_bio(bio, a->tst_info); | |
0f113f3e MC |
85 | else |
86 | BIO_printf(bio, "Not included.\n"); | |
87 | ||
88 | return 1; | |
89 | } | |
c7235be6 UM |
90 | |
91 | int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a) | |
0f113f3e MC |
92 | { |
93 | static const char *status_map[] = { | |
94 | "Granted.", | |
95 | "Granted with modifications.", | |
96 | "Rejected.", | |
97 | "Waiting.", | |
98 | "Revocation warning.", | |
99 | "Revoked." | |
100 | }; | |
101 | static const struct status_map_st failure_map[] = { | |
102 | {TS_INFO_BAD_ALG, | |
103 | "unrecognized or unsupported algorithm identifier"}, | |
104 | {TS_INFO_BAD_REQUEST, | |
105 | "transaction not permitted or supported"}, | |
106 | {TS_INFO_BAD_DATA_FORMAT, | |
107 | "the data submitted has the wrong format"}, | |
108 | {TS_INFO_TIME_NOT_AVAILABLE, | |
109 | "the TSA's time source is not available"}, | |
110 | {TS_INFO_UNACCEPTED_POLICY, | |
111 | "the requested TSA policy is not supported by the TSA"}, | |
112 | {TS_INFO_UNACCEPTED_EXTENSION, | |
113 | "the requested extension is not supported by the TSA"}, | |
114 | {TS_INFO_ADD_INFO_NOT_AVAILABLE, | |
115 | "the additional information requested could not be understood " | |
116 | "or is not available"}, | |
117 | {TS_INFO_SYSTEM_FAILURE, | |
118 | "the request cannot be handled due to system failure"}, | |
119 | {-1, NULL} | |
120 | }; | |
121 | long status; | |
122 | int i, lines = 0; | |
123 | ||
0f113f3e MC |
124 | BIO_printf(bio, "Status: "); |
125 | status = ASN1_INTEGER_get(a->status); | |
b6eb9827 | 126 | if (0 <= status && status < (long)OSSL_NELEM(status_map)) |
0f113f3e MC |
127 | BIO_printf(bio, "%s\n", status_map[status]); |
128 | else | |
129 | BIO_printf(bio, "out of bounds\n"); | |
130 | ||
0f113f3e MC |
131 | BIO_printf(bio, "Status description: "); |
132 | for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i) { | |
133 | if (i > 0) | |
134 | BIO_puts(bio, "\t"); | |
135 | ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i), 0); | |
136 | BIO_puts(bio, "\n"); | |
137 | } | |
138 | if (i == 0) | |
139 | BIO_printf(bio, "unspecified\n"); | |
140 | ||
0f113f3e MC |
141 | BIO_printf(bio, "Failure info: "); |
142 | if (a->failure_info != NULL) | |
9c422b5b | 143 | lines = ts_status_map_print(bio, failure_map, a->failure_info); |
0f113f3e MC |
144 | if (lines == 0) |
145 | BIO_printf(bio, "unspecified"); | |
146 | BIO_printf(bio, "\n"); | |
147 | ||
148 | return 1; | |
149 | } | |
c7235be6 | 150 | |
9c422b5b | 151 | static int ts_status_map_print(BIO *bio, const struct status_map_st *a, |
0f113f3e MC |
152 | const ASN1_BIT_STRING *v) |
153 | { | |
154 | int lines = 0; | |
155 | ||
156 | for (; a->bit >= 0; ++a) { | |
157 | if (ASN1_BIT_STRING_get_bit(v, a->bit)) { | |
158 | if (++lines > 1) | |
159 | BIO_printf(bio, ", "); | |
160 | BIO_printf(bio, "%s", a->text); | |
161 | } | |
162 | } | |
163 | ||
164 | return lines; | |
165 | } | |
c7235be6 UM |
166 | |
167 | int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a) | |
0f113f3e MC |
168 | { |
169 | int v; | |
0f113f3e MC |
170 | |
171 | if (a == NULL) | |
172 | return 0; | |
173 | ||
ca4a494c | 174 | v = ASN1_INTEGER_get(a->version); |
0f113f3e MC |
175 | BIO_printf(bio, "Version: %d\n", v); |
176 | ||
0f113f3e | 177 | BIO_printf(bio, "Policy OID: "); |
ca4a494c | 178 | TS_OBJ_print_bio(bio, a->policy_id); |
0f113f3e | 179 | |
ca4a494c | 180 | TS_MSG_IMPRINT_print_bio(bio, a->msg_imprint); |
0f113f3e | 181 | |
0f113f3e | 182 | BIO_printf(bio, "Serial number: "); |
ca4a494c | 183 | if (a->serial == NULL) |
0f113f3e MC |
184 | BIO_printf(bio, "unspecified"); |
185 | else | |
ca4a494c | 186 | TS_ASN1_INTEGER_print_bio(bio, a->serial); |
0f113f3e MC |
187 | BIO_write(bio, "\n", 1); |
188 | ||
0f113f3e | 189 | BIO_printf(bio, "Time stamp: "); |
ca4a494c | 190 | ASN1_GENERALIZEDTIME_print(bio, a->time); |
0f113f3e MC |
191 | BIO_write(bio, "\n", 1); |
192 | ||
0f113f3e | 193 | BIO_printf(bio, "Accuracy: "); |
ca4a494c | 194 | if (a->accuracy == NULL) |
0f113f3e MC |
195 | BIO_printf(bio, "unspecified"); |
196 | else | |
ca4a494c | 197 | ts_ACCURACY_print_bio(bio, a->accuracy); |
0f113f3e MC |
198 | BIO_write(bio, "\n", 1); |
199 | ||
ca4a494c | 200 | BIO_printf(bio, "Ordering: %s\n", a->ordering ? "yes" : "no"); |
0f113f3e | 201 | |
0f113f3e | 202 | BIO_printf(bio, "Nonce: "); |
ca4a494c | 203 | if (a->nonce == NULL) |
0f113f3e MC |
204 | BIO_printf(bio, "unspecified"); |
205 | else | |
ca4a494c | 206 | TS_ASN1_INTEGER_print_bio(bio, a->nonce); |
0f113f3e MC |
207 | BIO_write(bio, "\n", 1); |
208 | ||
0f113f3e | 209 | BIO_printf(bio, "TSA: "); |
ca4a494c | 210 | if (a->tsa == NULL) |
0f113f3e MC |
211 | BIO_printf(bio, "unspecified"); |
212 | else { | |
213 | STACK_OF(CONF_VALUE) *nval; | |
ca4a494c | 214 | if ((nval = i2v_GENERAL_NAME(NULL, a->tsa, NULL))) |
0f113f3e MC |
215 | X509V3_EXT_val_prn(bio, nval, 0, 0); |
216 | sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); | |
217 | } | |
218 | BIO_write(bio, "\n", 1); | |
219 | ||
ca4a494c | 220 | TS_ext_print_bio(bio, a->extensions); |
0f113f3e MC |
221 | |
222 | return 1; | |
223 | } | |
c7235be6 | 224 | |
ca4a494c | 225 | static int ts_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *a) |
0f113f3e | 226 | { |
ca4a494c RS |
227 | if (a->seconds != NULL) |
228 | TS_ASN1_INTEGER_print_bio(bio, a->seconds); | |
0f113f3e MC |
229 | else |
230 | BIO_printf(bio, "unspecified"); | |
231 | BIO_printf(bio, " seconds, "); | |
ca4a494c RS |
232 | if (a->millis != NULL) |
233 | TS_ASN1_INTEGER_print_bio(bio, a->millis); | |
0f113f3e MC |
234 | else |
235 | BIO_printf(bio, "unspecified"); | |
236 | BIO_printf(bio, " millis, "); | |
ca4a494c RS |
237 | if (a->micros != NULL) |
238 | TS_ASN1_INTEGER_print_bio(bio, a->micros); | |
0f113f3e MC |
239 | else |
240 | BIO_printf(bio, "unspecified"); | |
241 | BIO_printf(bio, " micros"); | |
242 | ||
243 | return 1; | |
244 | } |