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