1238384Sjkim/* crypto/ts/ts_resp_print.c */ 2280304Sjkim/* 3280304Sjkim * Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL project 4280304Sjkim * 2002. 5238384Sjkim */ 6238384Sjkim/* ==================================================================== 7238384Sjkim * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 8238384Sjkim * 9238384Sjkim * Redistribution and use in source and binary forms, with or without 10238384Sjkim * modification, are permitted provided that the following conditions 11238384Sjkim * are met: 12238384Sjkim * 13238384Sjkim * 1. Redistributions of source code must retain the above copyright 14280304Sjkim * notice, this list of conditions and the following disclaimer. 15238384Sjkim * 16238384Sjkim * 2. Redistributions in binary form must reproduce the above copyright 17238384Sjkim * notice, this list of conditions and the following disclaimer in 18238384Sjkim * the documentation and/or other materials provided with the 19238384Sjkim * distribution. 20238384Sjkim * 21238384Sjkim * 3. All advertising materials mentioning features or use of this 22238384Sjkim * software must display the following acknowledgment: 23238384Sjkim * "This product includes software developed by the OpenSSL Project 24238384Sjkim * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 25238384Sjkim * 26238384Sjkim * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27238384Sjkim * endorse or promote products derived from this software without 28238384Sjkim * prior written permission. For written permission, please contact 29238384Sjkim * licensing@OpenSSL.org. 30238384Sjkim * 31238384Sjkim * 5. Products derived from this software may not be called "OpenSSL" 32238384Sjkim * nor may "OpenSSL" appear in their names without prior written 33238384Sjkim * permission of the OpenSSL Project. 34238384Sjkim * 35238384Sjkim * 6. Redistributions of any form whatsoever must retain the following 36238384Sjkim * acknowledgment: 37238384Sjkim * "This product includes software developed by the OpenSSL Project 38238384Sjkim * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 39238384Sjkim * 40238384Sjkim * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41238384Sjkim * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42238384Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43238384Sjkim * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44238384Sjkim * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45238384Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46238384Sjkim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47238384Sjkim * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48238384Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49238384Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50238384Sjkim * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51238384Sjkim * OF THE POSSIBILITY OF SUCH DAMAGE. 52238384Sjkim * ==================================================================== 53238384Sjkim * 54238384Sjkim * This product includes cryptographic software written by Eric Young 55238384Sjkim * (eay@cryptsoft.com). This product includes software written by Tim 56238384Sjkim * Hudson (tjh@cryptsoft.com). 57238384Sjkim * 58238384Sjkim */ 59238384Sjkim 60238384Sjkim#include <stdio.h> 61238384Sjkim#include "cryptlib.h" 62238384Sjkim#include <openssl/objects.h> 63238384Sjkim#include <openssl/bn.h> 64238384Sjkim#include <openssl/x509v3.h> 65238384Sjkim#include "ts.h" 66238384Sjkim 67280304Sjkimstruct status_map_st { 68280304Sjkim int bit; 69280304Sjkim const char *text; 70280304Sjkim}; 71238384Sjkim 72238384Sjkim/* Local function declarations. */ 73238384Sjkim 74238384Sjkimstatic int TS_status_map_print(BIO *bio, struct status_map_st *a, 75280304Sjkim ASN1_BIT_STRING *v); 76238384Sjkimstatic int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy); 77238384Sjkim 78238384Sjkim/* Function definitions. */ 79238384Sjkim 80238384Sjkimint TS_RESP_print_bio(BIO *bio, TS_RESP *a) 81280304Sjkim{ 82280304Sjkim TS_TST_INFO *tst_info; 83238384Sjkim 84280304Sjkim BIO_printf(bio, "Status info:\n"); 85280304Sjkim TS_STATUS_INFO_print_bio(bio, TS_RESP_get_status_info(a)); 86238384Sjkim 87280304Sjkim BIO_printf(bio, "\nTST info:\n"); 88280304Sjkim tst_info = TS_RESP_get_tst_info(a); 89280304Sjkim if (tst_info != NULL) 90280304Sjkim TS_TST_INFO_print_bio(bio, TS_RESP_get_tst_info(a)); 91280304Sjkim else 92280304Sjkim BIO_printf(bio, "Not included.\n"); 93238384Sjkim 94280304Sjkim return 1; 95280304Sjkim} 96280304Sjkim 97238384Sjkimint TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a) 98280304Sjkim{ 99280304Sjkim static const char *status_map[] = { 100280304Sjkim "Granted.", 101280304Sjkim "Granted with modifications.", 102280304Sjkim "Rejected.", 103280304Sjkim "Waiting.", 104280304Sjkim "Revocation warning.", 105280304Sjkim "Revoked." 106280304Sjkim }; 107280304Sjkim static struct status_map_st failure_map[] = { 108280304Sjkim {TS_INFO_BAD_ALG, 109280304Sjkim "unrecognized or unsupported algorithm identifier"}, 110280304Sjkim {TS_INFO_BAD_REQUEST, 111280304Sjkim "transaction not permitted or supported"}, 112280304Sjkim {TS_INFO_BAD_DATA_FORMAT, 113280304Sjkim "the data submitted has the wrong format"}, 114280304Sjkim {TS_INFO_TIME_NOT_AVAILABLE, 115280304Sjkim "the TSA's time source is not available"}, 116280304Sjkim {TS_INFO_UNACCEPTED_POLICY, 117280304Sjkim "the requested TSA policy is not supported by the TSA"}, 118280304Sjkim {TS_INFO_UNACCEPTED_EXTENSION, 119280304Sjkim "the requested extension is not supported by the TSA"}, 120280304Sjkim {TS_INFO_ADD_INFO_NOT_AVAILABLE, 121280304Sjkim "the additional information requested could not be understood " 122280304Sjkim "or is not available"}, 123280304Sjkim {TS_INFO_SYSTEM_FAILURE, 124280304Sjkim "the request cannot be handled due to system failure"}, 125280304Sjkim {-1, NULL} 126280304Sjkim }; 127280304Sjkim long status; 128280304Sjkim int i, lines = 0; 129238384Sjkim 130280304Sjkim /* Printing status code. */ 131280304Sjkim BIO_printf(bio, "Status: "); 132280304Sjkim status = ASN1_INTEGER_get(a->status); 133280304Sjkim if (0 <= status 134280304Sjkim && status < (long)(sizeof(status_map) / sizeof(status_map[0]))) 135280304Sjkim BIO_printf(bio, "%s\n", status_map[status]); 136280304Sjkim else 137280304Sjkim BIO_printf(bio, "out of bounds\n"); 138238384Sjkim 139280304Sjkim /* Printing status description. */ 140280304Sjkim BIO_printf(bio, "Status description: "); 141280304Sjkim for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i) { 142280304Sjkim if (i > 0) 143280304Sjkim BIO_puts(bio, "\t"); 144280304Sjkim ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i), 0); 145280304Sjkim BIO_puts(bio, "\n"); 146280304Sjkim } 147280304Sjkim if (i == 0) 148280304Sjkim BIO_printf(bio, "unspecified\n"); 149238384Sjkim 150280304Sjkim /* Printing failure information. */ 151280304Sjkim BIO_printf(bio, "Failure info: "); 152280304Sjkim if (a->failure_info != NULL) 153280304Sjkim lines = TS_status_map_print(bio, failure_map, a->failure_info); 154280304Sjkim if (lines == 0) 155280304Sjkim BIO_printf(bio, "unspecified"); 156280304Sjkim BIO_printf(bio, "\n"); 157238384Sjkim 158280304Sjkim return 1; 159280304Sjkim} 160280304Sjkim 161238384Sjkimstatic int TS_status_map_print(BIO *bio, struct status_map_st *a, 162280304Sjkim ASN1_BIT_STRING *v) 163280304Sjkim{ 164280304Sjkim int lines = 0; 165238384Sjkim 166280304Sjkim for (; a->bit >= 0; ++a) { 167280304Sjkim if (ASN1_BIT_STRING_get_bit(v, a->bit)) { 168280304Sjkim if (++lines > 1) 169280304Sjkim BIO_printf(bio, ", "); 170280304Sjkim BIO_printf(bio, "%s", a->text); 171280304Sjkim } 172280304Sjkim } 173238384Sjkim 174280304Sjkim return lines; 175280304Sjkim} 176238384Sjkim 177238384Sjkimint TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a) 178280304Sjkim{ 179280304Sjkim int v; 180280304Sjkim ASN1_OBJECT *policy_id; 181280304Sjkim const ASN1_INTEGER *serial; 182280304Sjkim const ASN1_GENERALIZEDTIME *gtime; 183280304Sjkim TS_ACCURACY *accuracy; 184280304Sjkim const ASN1_INTEGER *nonce; 185280304Sjkim GENERAL_NAME *tsa_name; 186238384Sjkim 187280304Sjkim if (a == NULL) 188280304Sjkim return 0; 189238384Sjkim 190280304Sjkim /* Print version. */ 191280304Sjkim v = TS_TST_INFO_get_version(a); 192280304Sjkim BIO_printf(bio, "Version: %d\n", v); 193238384Sjkim 194280304Sjkim /* Print policy id. */ 195280304Sjkim BIO_printf(bio, "Policy OID: "); 196280304Sjkim policy_id = TS_TST_INFO_get_policy_id(a); 197280304Sjkim TS_OBJ_print_bio(bio, policy_id); 198238384Sjkim 199280304Sjkim /* Print message imprint. */ 200280304Sjkim TS_MSG_IMPRINT_print_bio(bio, TS_TST_INFO_get_msg_imprint(a)); 201238384Sjkim 202280304Sjkim /* Print serial number. */ 203280304Sjkim BIO_printf(bio, "Serial number: "); 204280304Sjkim serial = TS_TST_INFO_get_serial(a); 205280304Sjkim if (serial == NULL) 206280304Sjkim BIO_printf(bio, "unspecified"); 207280304Sjkim else 208280304Sjkim TS_ASN1_INTEGER_print_bio(bio, serial); 209280304Sjkim BIO_write(bio, "\n", 1); 210238384Sjkim 211280304Sjkim /* Print time stamp. */ 212280304Sjkim BIO_printf(bio, "Time stamp: "); 213280304Sjkim gtime = TS_TST_INFO_get_time(a); 214280304Sjkim ASN1_GENERALIZEDTIME_print(bio, gtime); 215280304Sjkim BIO_write(bio, "\n", 1); 216238384Sjkim 217280304Sjkim /* Print accuracy. */ 218280304Sjkim BIO_printf(bio, "Accuracy: "); 219280304Sjkim accuracy = TS_TST_INFO_get_accuracy(a); 220280304Sjkim if (accuracy == NULL) 221280304Sjkim BIO_printf(bio, "unspecified"); 222280304Sjkim else 223280304Sjkim TS_ACCURACY_print_bio(bio, accuracy); 224280304Sjkim BIO_write(bio, "\n", 1); 225238384Sjkim 226280304Sjkim /* Print ordering. */ 227280304Sjkim BIO_printf(bio, "Ordering: %s\n", 228280304Sjkim TS_TST_INFO_get_ordering(a) ? "yes" : "no"); 229238384Sjkim 230280304Sjkim /* Print nonce. */ 231280304Sjkim BIO_printf(bio, "Nonce: "); 232280304Sjkim nonce = TS_TST_INFO_get_nonce(a); 233280304Sjkim if (nonce == NULL) 234280304Sjkim BIO_printf(bio, "unspecified"); 235280304Sjkim else 236280304Sjkim TS_ASN1_INTEGER_print_bio(bio, nonce); 237280304Sjkim BIO_write(bio, "\n", 1); 238238384Sjkim 239280304Sjkim /* Print TSA name. */ 240280304Sjkim BIO_printf(bio, "TSA: "); 241280304Sjkim tsa_name = TS_TST_INFO_get_tsa(a); 242280304Sjkim if (tsa_name == NULL) 243280304Sjkim BIO_printf(bio, "unspecified"); 244280304Sjkim else { 245280304Sjkim STACK_OF(CONF_VALUE) *nval; 246280304Sjkim if ((nval = i2v_GENERAL_NAME(NULL, tsa_name, NULL))) 247280304Sjkim X509V3_EXT_val_prn(bio, nval, 0, 0); 248280304Sjkim sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); 249280304Sjkim } 250280304Sjkim BIO_write(bio, "\n", 1); 251238384Sjkim 252280304Sjkim /* Print extensions. */ 253280304Sjkim TS_ext_print_bio(bio, TS_TST_INFO_get_exts(a)); 254238384Sjkim 255280304Sjkim return 1; 256280304Sjkim} 257238384Sjkim 258238384Sjkimstatic int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy) 259280304Sjkim{ 260280304Sjkim const ASN1_INTEGER *seconds = TS_ACCURACY_get_seconds(accuracy); 261280304Sjkim const ASN1_INTEGER *millis = TS_ACCURACY_get_millis(accuracy); 262280304Sjkim const ASN1_INTEGER *micros = TS_ACCURACY_get_micros(accuracy); 263238384Sjkim 264280304Sjkim if (seconds != NULL) 265280304Sjkim TS_ASN1_INTEGER_print_bio(bio, seconds); 266280304Sjkim else 267280304Sjkim BIO_printf(bio, "unspecified"); 268280304Sjkim BIO_printf(bio, " seconds, "); 269280304Sjkim if (millis != NULL) 270280304Sjkim TS_ASN1_INTEGER_print_bio(bio, millis); 271280304Sjkim else 272280304Sjkim BIO_printf(bio, "unspecified"); 273280304Sjkim BIO_printf(bio, " millis, "); 274280304Sjkim if (micros != NULL) 275280304Sjkim TS_ASN1_INTEGER_print_bio(bio, micros); 276280304Sjkim else 277280304Sjkim BIO_printf(bio, "unspecified"); 278280304Sjkim BIO_printf(bio, " micros"); 279238384Sjkim 280280304Sjkim return 1; 281280304Sjkim} 282