LCOV - code coverage report
Current view: top level - ts - ts_rsp_print.c (source / functions) Hit Total Coverage
Test: lcov_coverage_final.info Lines: 77 98 78.6 %
Date: 2014-08-02 Functions: 4 5 80.0 %
Branches: 17 40 42.5 %

           Branch data     Line data    Source code
       1                 :            : /* crypto/ts/ts_resp_print.c */
       2                 :            : /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
       3                 :            :  * project 2002.
       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
      13                 :            :  *    notice, this list of conditions and the following disclaimer. 
      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>
      60                 :            : #include "cryptlib.h"
      61                 :            : #include <openssl/objects.h>
      62                 :            : #include <openssl/bn.h>
      63                 :            : #include <openssl/x509v3.h>
      64                 :            : #include "ts.h"
      65                 :            : 
      66                 :            : struct status_map_st
      67                 :            :         {
      68                 :            :         int bit;
      69                 :            :         const char *text;
      70                 :            :         };
      71                 :            : 
      72                 :            : /* Local function declarations. */
      73                 :            : 
      74                 :            : static int TS_status_map_print(BIO *bio, struct status_map_st *a,
      75                 :            :                                ASN1_BIT_STRING *v);
      76                 :            : static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy);
      77                 :            : 
      78                 :            : /* Function definitions. */
      79                 :            : 
      80                 :          2 : int TS_RESP_print_bio(BIO *bio, TS_RESP *a)
      81                 :            :         {
      82                 :            :         TS_TST_INFO *tst_info;
      83                 :            : 
      84                 :          2 :         BIO_printf(bio, "Status info:\n");
      85                 :          2 :         TS_STATUS_INFO_print_bio(bio, TS_RESP_get_status_info(a));
      86                 :            : 
      87                 :          2 :         BIO_printf(bio, "\nTST info:\n");
      88                 :          2 :         tst_info = TS_RESP_get_tst_info(a);
      89         [ +  - ]:          2 :         if (tst_info != NULL)
      90                 :          2 :                 TS_TST_INFO_print_bio(bio, TS_RESP_get_tst_info(a));
      91                 :            :         else
      92                 :          0 :                 BIO_printf(bio, "Not included.\n");
      93                 :            :                 
      94                 :          2 :         return 1;
      95                 :            :         }
      96                 :            : 
      97                 :          2 : int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a)
      98                 :            :         {
      99                 :            :         static const char *status_map[] =
     100                 :            :                 {
     101                 :            :                 "Granted.",
     102                 :            :                 "Granted with modifications.",
     103                 :            :                 "Rejected.",
     104                 :            :                 "Waiting.",
     105                 :            :                 "Revocation warning.",
     106                 :            :                 "Revoked."
     107                 :            :                 };
     108                 :            :         static struct status_map_st failure_map[] =
     109                 :            :                 {
     110                 :            :                 { TS_INFO_BAD_ALG,
     111                 :            :                 "unrecognized or unsupported algorithm identifier" },
     112                 :            :                 { TS_INFO_BAD_REQUEST,
     113                 :            :                 "transaction not permitted or supported" },
     114                 :            :                 { TS_INFO_BAD_DATA_FORMAT,
     115                 :            :                 "the data submitted has the wrong format" },
     116                 :            :                 { TS_INFO_TIME_NOT_AVAILABLE,
     117                 :            :                 "the TSA's time source is not available" },
     118                 :            :                 { TS_INFO_UNACCEPTED_POLICY,
     119                 :            :                 "the requested TSA policy is not supported by the TSA" },
     120                 :            :                 { TS_INFO_UNACCEPTED_EXTENSION,
     121                 :            :                 "the requested extension is not supported by the TSA" },
     122                 :            :                 { TS_INFO_ADD_INFO_NOT_AVAILABLE,
     123                 :            :                 "the additional information requested could not be understood "
     124                 :            :                 "or is not available" },
     125                 :            :                 { TS_INFO_SYSTEM_FAILURE,
     126                 :            :                 "the request cannot be handled due to system failure" },
     127                 :            :                 { -1, NULL }
     128                 :            :                 };
     129                 :            :         long status;
     130                 :          2 :         int i, lines = 0;
     131                 :            : 
     132                 :            :         /* Printing status code. */
     133                 :          2 :         BIO_printf(bio, "Status: ");
     134                 :          2 :         status = ASN1_INTEGER_get(a->status);
     135         [ +  - ]:          2 :         if (0 <= status && status < (long)(sizeof(status_map)/sizeof(status_map[0])))
     136                 :          2 :                 BIO_printf(bio, "%s\n", status_map[status]);
     137                 :            :         else
     138                 :          0 :                 BIO_printf(bio, "out of bounds\n");
     139                 :            :         
     140                 :            :         /* Printing status description. */
     141                 :          2 :         BIO_printf(bio, "Status description: ");
     142         [ -  + ]:          2 :         for (i = 0; i < sk_ASN1_UTF8STRING_num(a->text); ++i)
     143                 :            :                 {
     144         [ #  # ]:          0 :                 if (i > 0)
     145                 :          0 :                         BIO_puts(bio, "\t");
     146                 :          0 :                 ASN1_STRING_print_ex(bio, sk_ASN1_UTF8STRING_value(a->text, i),
     147                 :            :                                      0);
     148                 :          0 :                 BIO_puts(bio, "\n");
     149                 :            :                 }
     150         [ +  - ]:          2 :         if (i == 0)
     151                 :          2 :                 BIO_printf(bio, "unspecified\n");
     152                 :            : 
     153                 :            :         /* Printing failure information. */
     154                 :          2 :         BIO_printf(bio, "Failure info: ");
     155         [ -  + ]:          2 :         if (a->failure_info != NULL)
     156                 :          0 :                 lines = TS_status_map_print(bio, failure_map,
     157                 :            :                                             a->failure_info);
     158         [ +  - ]:          2 :         if (lines == 0)
     159                 :          2 :                 BIO_printf(bio, "unspecified");
     160                 :          2 :         BIO_printf(bio, "\n");
     161                 :            : 
     162                 :          2 :         return 1;
     163                 :            :         }
     164                 :            : 
     165                 :          0 : static int TS_status_map_print(BIO *bio, struct status_map_st *a,
     166                 :            :                                ASN1_BIT_STRING *v)
     167                 :            :         {
     168                 :          0 :         int lines = 0;
     169                 :            : 
     170         [ #  # ]:          0 :         for (; a->bit >= 0; ++a)
     171                 :            :                 {
     172         [ #  # ]:          0 :                 if (ASN1_BIT_STRING_get_bit(v, a->bit))
     173                 :            :                         {
     174         [ #  # ]:          0 :                         if (++lines > 1)
     175                 :          0 :                                 BIO_printf(bio, ", ");
     176                 :          0 :                         BIO_printf(bio, "%s", a->text);
     177                 :            :                         }
     178                 :            :                 }
     179                 :            : 
     180                 :          0 :         return lines;
     181                 :            :         }
     182                 :            : 
     183                 :          5 : int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a)
     184                 :            :         {
     185                 :            :         int v;
     186                 :            :         ASN1_OBJECT *policy_id;
     187                 :            :         const ASN1_INTEGER *serial;
     188                 :            :         const ASN1_GENERALIZEDTIME *gtime;
     189                 :            :         TS_ACCURACY *accuracy;
     190                 :            :         const ASN1_INTEGER *nonce;
     191                 :            :         GENERAL_NAME *tsa_name;
     192                 :            : 
     193         [ +  - ]:          5 :         if (a == NULL) return 0;
     194                 :            : 
     195                 :            :         /* Print version. */
     196                 :          5 :         v = TS_TST_INFO_get_version(a);
     197                 :          5 :         BIO_printf(bio, "Version: %d\n", v);
     198                 :            : 
     199                 :            :         /* Print policy id. */
     200                 :          5 :         BIO_printf(bio, "Policy OID: ");
     201                 :          5 :         policy_id = TS_TST_INFO_get_policy_id(a);
     202                 :          5 :         TS_OBJ_print_bio(bio, policy_id);
     203                 :            : 
     204                 :            :         /* Print message imprint. */
     205                 :          5 :         TS_MSG_IMPRINT_print_bio(bio, TS_TST_INFO_get_msg_imprint(a));
     206                 :            : 
     207                 :            :         /* Print serial number. */
     208                 :          5 :         BIO_printf(bio, "Serial number: ");
     209                 :          5 :         serial = TS_TST_INFO_get_serial(a);
     210         [ -  + ]:          5 :         if (serial == NULL)
     211                 :          0 :                 BIO_printf(bio, "unspecified");
     212                 :            :         else
     213                 :          5 :                 TS_ASN1_INTEGER_print_bio(bio, serial);
     214                 :          5 :         BIO_write(bio, "\n", 1);
     215                 :            : 
     216                 :            :         /* Print time stamp. */
     217                 :          5 :         BIO_printf(bio, "Time stamp: ");
     218                 :          5 :         gtime = TS_TST_INFO_get_time(a);
     219                 :          5 :         ASN1_GENERALIZEDTIME_print(bio, gtime);
     220                 :          5 :         BIO_write(bio, "\n", 1);
     221                 :            : 
     222                 :            :         /* Print accuracy. */
     223                 :          5 :         BIO_printf(bio, "Accuracy: ");
     224                 :          5 :         accuracy = TS_TST_INFO_get_accuracy(a);
     225         [ -  + ]:          5 :         if (accuracy == NULL)
     226                 :          0 :                 BIO_printf(bio, "unspecified");
     227                 :            :         else
     228                 :          5 :                 TS_ACCURACY_print_bio(bio, accuracy);
     229                 :          5 :         BIO_write(bio, "\n", 1);
     230                 :            : 
     231                 :            :         /* Print ordering. */
     232         [ -  + ]:          5 :         BIO_printf(bio, "Ordering: %s\n", 
     233                 :          5 :                    TS_TST_INFO_get_ordering(a) ? "yes" : "no");
     234                 :            : 
     235                 :            :         /* Print nonce. */
     236                 :          5 :         BIO_printf(bio, "Nonce: ");
     237                 :          5 :         nonce = TS_TST_INFO_get_nonce(a);
     238         [ +  + ]:          5 :         if (nonce == NULL)
     239                 :          4 :                 BIO_printf(bio, "unspecified");
     240                 :            :         else
     241                 :          1 :                 TS_ASN1_INTEGER_print_bio(bio, nonce);
     242                 :          5 :         BIO_write(bio, "\n", 1);
     243                 :            : 
     244                 :            :         /* Print TSA name. */
     245                 :          5 :         BIO_printf(bio, "TSA: ");
     246                 :          5 :         tsa_name = TS_TST_INFO_get_tsa(a);
     247         [ -  + ]:          5 :         if (tsa_name == NULL)
     248                 :          0 :                 BIO_printf(bio, "unspecified");
     249                 :            :         else
     250                 :            :                 {
     251                 :            :                 STACK_OF(CONF_VALUE) *nval;
     252         [ +  - ]:          5 :                 if ((nval = i2v_GENERAL_NAME(NULL, tsa_name, NULL)))
     253                 :          5 :                         X509V3_EXT_val_prn(bio, nval, 0, 0);
     254                 :          5 :                 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
     255                 :            :                 }
     256                 :          5 :         BIO_write(bio, "\n", 1);
     257                 :            : 
     258                 :            :         /* Print extensions. */
     259                 :          5 :         TS_ext_print_bio(bio, TS_TST_INFO_get_exts(a));
     260                 :            : 
     261                 :          5 :         return 1;
     262                 :            :         }
     263                 :            : 
     264                 :          5 : static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy)
     265                 :            :         {
     266                 :          5 :         const ASN1_INTEGER *seconds = TS_ACCURACY_get_seconds(accuracy);
     267                 :          5 :         const ASN1_INTEGER *millis = TS_ACCURACY_get_millis(accuracy);
     268                 :          5 :         const ASN1_INTEGER *micros = TS_ACCURACY_get_micros(accuracy);
     269                 :            : 
     270         [ +  - ]:          5 :         if (seconds != NULL)
     271                 :          5 :                 TS_ASN1_INTEGER_print_bio(bio, seconds);
     272                 :            :         else
     273                 :          0 :                 BIO_printf(bio, "unspecified");
     274                 :          5 :         BIO_printf(bio, " seconds, ");
     275         [ +  - ]:          5 :         if (millis != NULL)
     276                 :          5 :                 TS_ASN1_INTEGER_print_bio(bio, millis);
     277                 :            :         else
     278                 :          0 :                 BIO_printf(bio, "unspecified");
     279                 :          5 :         BIO_printf(bio, " millis, ");
     280         [ +  - ]:          5 :         if (micros != NULL)
     281                 :          5 :                 TS_ASN1_INTEGER_print_bio(bio, micros);
     282                 :            :         else
     283                 :          0 :                 BIO_printf(bio, "unspecified");
     284                 :          5 :         BIO_printf(bio, " micros");
     285                 :            : 
     286                 :          5 :         return 1;
     287                 :            :         }

Generated by: LCOV version 1.9