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