ts_rsp_print.c revision 296341
179503Salfred/* crypto/ts/ts_resp_print.c */ 279503Salfred/* 379503Salfred * Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL project 479503Salfred * 2002. 579503Salfred */ 679503Salfred/* ==================================================================== 779503Salfred * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 879503Salfred * 979503Salfred * Redistribution and use in source and binary forms, with or without 1079503Salfred * modification, are permitted provided that the following conditions 1179503Salfred * are met: 1279503Salfred * 1379503Salfred * 1. Redistributions of source code must retain the above copyright 1479503Salfred * notice, this list of conditions and the following disclaimer. 1579503Salfred * 1679503Salfred * 2. Redistributions in binary form must reproduce the above copyright 1779503Salfred * notice, this list of conditions and the following disclaimer in 1879503Salfred * the documentation and/or other materials provided with the 1979503Salfred * distribution. 2079503Salfred * 2179503Salfred * 3. All advertising materials mentioning features or use of this 2279503Salfred * software must display the following acknowledgment: 2379503Salfred * "This product includes software developed by the OpenSSL Project 2479503Salfred * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 2579503Salfred * 2679503Salfred * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 2779503Salfred * endorse or promote products derived from this software without 2879503Salfred * prior written permission. For written permission, please contact 2979503Salfred * licensing@OpenSSL.org. 3079503Salfred * 3179503Salfred * 5. Products derived from this software may not be called "OpenSSL" 3279503Salfred * nor may "OpenSSL" appear in their names without prior written 3379503Salfred * permission of the OpenSSL Project. 3479581Sru * 3579503Salfred * 6. Redistributions of any form whatsoever must retain the following 3679581Sru * acknowledgment: 3788509Sdavidc * "This product includes software developed by the OpenSSL Project 3888509Sdavidc * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 3988509Sdavidc * 4079581Sru * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 4179503Salfred * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4279574Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4379503Salfred * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 4479503Salfred * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4579581Sru * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 4679503Salfred * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4779581Sru * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4879581Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4979581Sru * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 5079503Salfred * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 5179503Salfred * OF THE POSSIBILITY OF SUCH DAMAGE. 5279658Sru * ==================================================================== 5379581Sru * 5479581Sru * This product includes cryptographic software written by Eric Young 5579581Sru * (eay@cryptsoft.com). This product includes software written by Tim 5679581Sru * Hudson (tjh@cryptsoft.com). 5779503Salfred * 5879581Sru */ 5979581Sru 6079581Sru#include <stdio.h> 6179503Salfred#include "cryptlib.h" 6279503Salfred#include <openssl/objects.h> 63147647Shmp#include <openssl/bn.h> 6479654Sru#include <openssl/x509v3.h> 65#include "ts.h" 66 67struct status_map_st { 68 int bit; 69 const char *text; 70}; 71 72/* Local function declarations. */ 73 74static int TS_status_map_print(BIO *bio, struct status_map_st *a, 75 ASN1_BIT_STRING *v); 76static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy); 77 78/* Function definitions. */ 79 80int TS_RESP_print_bio(BIO *bio, TS_RESP *a) 81{ 82 TS_TST_INFO *tst_info; 83 84 BIO_printf(bio, "Status info:\n"); 85 TS_STATUS_INFO_print_bio(bio, TS_RESP_get_status_info(a)); 86 87 BIO_printf(bio, "\nTST info:\n"); 88 tst_info = TS_RESP_get_tst_info(a); 89 if (tst_info != NULL) 90 TS_TST_INFO_print_bio(bio, TS_RESP_get_tst_info(a)); 91 else 92 BIO_printf(bio, "Not included.\n"); 93 94 return 1; 95} 96 97int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a) 98{ 99 static const char *status_map[] = { 100 "Granted.", 101 "Granted with modifications.", 102 "Rejected.", 103 "Waiting.", 104 "Revocation warning.", 105 "Revoked." 106 }; 107 static struct status_map_st failure_map[] = { 108 {TS_INFO_BAD_ALG, 109 "unrecognized or unsupported algorithm identifier"}, 110 {TS_INFO_BAD_REQUEST, 111 "transaction not permitted or supported"}, 112 {TS_INFO_BAD_DATA_FORMAT, 113 "the data submitted has the wrong format"}, 114 {TS_INFO_TIME_NOT_AVAILABLE, 115 "the TSA's time source is not available"}, 116 {TS_INFO_UNACCEPTED_POLICY, 117 "the requested TSA policy is not supported by the TSA"}, 118 {TS_INFO_UNACCEPTED_EXTENSION, 119 "the requested extension is not supported by the TSA"}, 120 {TS_INFO_ADD_INFO_NOT_AVAILABLE, 121 "the additional information requested could not be understood " 122 "or is not available"}, 123 {TS_INFO_SYSTEM_FAILURE, 124 "the request cannot be handled due to system failure"}, 125 {-1, NULL} 126 }; 127 long status; 128 int i, lines = 0; 129 130 /* Printing status code. */ 131 BIO_printf(bio, "Status: "); 132 status = ASN1_INTEGER_get(a->status); 133 if (0 <= status 134 && status < (long)(sizeof(status_map) / sizeof(status_map[0]))) 135 BIO_printf(bio, "%s\n", status_map[status]); 136 else 137 BIO_printf(bio, "out of bounds\n"); 138 139 /* Printing status description. */ 140 BIO_printf(bio, "Status description: "); 141 for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i) { 142 if (i > 0) 143 BIO_puts(bio, "\t"); 144 ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i), 0); 145 BIO_puts(bio, "\n"); 146 } 147 if (i == 0) 148 BIO_printf(bio, "unspecified\n"); 149 150 /* Printing failure information. */ 151 BIO_printf(bio, "Failure info: "); 152 if (a->failure_info != NULL) 153 lines = TS_status_map_print(bio, failure_map, a->failure_info); 154 if (lines == 0) 155 BIO_printf(bio, "unspecified"); 156 BIO_printf(bio, "\n"); 157 158 return 1; 159} 160 161static int TS_status_map_print(BIO *bio, struct status_map_st *a, 162 ASN1_BIT_STRING *v) 163{ 164 int lines = 0; 165 166 for (; a->bit >= 0; ++a) { 167 if (ASN1_BIT_STRING_get_bit(v, a->bit)) { 168 if (++lines > 1) 169 BIO_printf(bio, ", "); 170 BIO_printf(bio, "%s", a->text); 171 } 172 } 173 174 return lines; 175} 176 177int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a) 178{ 179 int v; 180 ASN1_OBJECT *policy_id; 181 const ASN1_INTEGER *serial; 182 const ASN1_GENERALIZEDTIME *gtime; 183 TS_ACCURACY *accuracy; 184 const ASN1_INTEGER *nonce; 185 GENERAL_NAME *tsa_name; 186 187 if (a == NULL) 188 return 0; 189 190 /* Print version. */ 191 v = TS_TST_INFO_get_version(a); 192 BIO_printf(bio, "Version: %d\n", v); 193 194 /* Print policy id. */ 195 BIO_printf(bio, "Policy OID: "); 196 policy_id = TS_TST_INFO_get_policy_id(a); 197 TS_OBJ_print_bio(bio, policy_id); 198 199 /* Print message imprint. */ 200 TS_MSG_IMPRINT_print_bio(bio, TS_TST_INFO_get_msg_imprint(a)); 201 202 /* Print serial number. */ 203 BIO_printf(bio, "Serial number: "); 204 serial = TS_TST_INFO_get_serial(a); 205 if (serial == NULL) 206 BIO_printf(bio, "unspecified"); 207 else 208 TS_ASN1_INTEGER_print_bio(bio, serial); 209 BIO_write(bio, "\n", 1); 210 211 /* Print time stamp. */ 212 BIO_printf(bio, "Time stamp: "); 213 gtime = TS_TST_INFO_get_time(a); 214 ASN1_GENERALIZEDTIME_print(bio, gtime); 215 BIO_write(bio, "\n", 1); 216 217 /* Print accuracy. */ 218 BIO_printf(bio, "Accuracy: "); 219 accuracy = TS_TST_INFO_get_accuracy(a); 220 if (accuracy == NULL) 221 BIO_printf(bio, "unspecified"); 222 else 223 TS_ACCURACY_print_bio(bio, accuracy); 224 BIO_write(bio, "\n", 1); 225 226 /* Print ordering. */ 227 BIO_printf(bio, "Ordering: %s\n", 228 TS_TST_INFO_get_ordering(a) ? "yes" : "no"); 229 230 /* Print nonce. */ 231 BIO_printf(bio, "Nonce: "); 232 nonce = TS_TST_INFO_get_nonce(a); 233 if (nonce == NULL) 234 BIO_printf(bio, "unspecified"); 235 else 236 TS_ASN1_INTEGER_print_bio(bio, nonce); 237 BIO_write(bio, "\n", 1); 238 239 /* Print TSA name. */ 240 BIO_printf(bio, "TSA: "); 241 tsa_name = TS_TST_INFO_get_tsa(a); 242 if (tsa_name == NULL) 243 BIO_printf(bio, "unspecified"); 244 else { 245 STACK_OF(CONF_VALUE) *nval; 246 if ((nval = i2v_GENERAL_NAME(NULL, tsa_name, NULL))) 247 X509V3_EXT_val_prn(bio, nval, 0, 0); 248 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); 249 } 250 BIO_write(bio, "\n", 1); 251 252 /* Print extensions. */ 253 TS_ext_print_bio(bio, TS_TST_INFO_get_exts(a)); 254 255 return 1; 256} 257 258static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy) 259{ 260 const ASN1_INTEGER *seconds = TS_ACCURACY_get_seconds(accuracy); 261 const ASN1_INTEGER *millis = TS_ACCURACY_get_millis(accuracy); 262 const ASN1_INTEGER *micros = TS_ACCURACY_get_micros(accuracy); 263 264 if (seconds != NULL) 265 TS_ASN1_INTEGER_print_bio(bio, seconds); 266 else 267 BIO_printf(bio, "unspecified"); 268 BIO_printf(bio, " seconds, "); 269 if (millis != NULL) 270 TS_ASN1_INTEGER_print_bio(bio, millis); 271 else 272 BIO_printf(bio, "unspecified"); 273 BIO_printf(bio, " millis, "); 274 if (micros != NULL) 275 TS_ASN1_INTEGER_print_bio(bio, micros); 276 else 277 BIO_printf(bio, "unspecified"); 278 BIO_printf(bio, " micros"); 279 280 return 1; 281} 282