/src/openssl30/crypto/ct/ct_prn.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 2016-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 |  | #ifdef OPENSSL_NO_CT | 
| 11 |  | # error "CT is disabled" | 
| 12 |  | #endif | 
| 13 |  |  | 
| 14 |  | #include <openssl/asn1.h> | 
| 15 |  | #include <openssl/bio.h> | 
| 16 |  |  | 
| 17 |  | #include "ct_local.h" | 
| 18 |  |  | 
| 19 |  | static void SCT_signature_algorithms_print(const SCT *sct, BIO *out) | 
| 20 | 45.2k | { | 
| 21 | 45.2k |     int nid = SCT_get_signature_nid(sct); | 
| 22 |  |  | 
| 23 | 45.2k |     if (nid == NID_undef) | 
| 24 | 0 |         BIO_printf(out, "%02X%02X", sct->hash_alg, sct->sig_alg); | 
| 25 | 45.2k |     else | 
| 26 | 45.2k |         BIO_printf(out, "%s", OBJ_nid2ln(nid)); | 
| 27 | 45.2k | } | 
| 28 |  |  | 
| 29 |  | static void timestamp_print(uint64_t timestamp, BIO *out) | 
| 30 | 45.2k | { | 
| 31 | 45.2k |     ASN1_GENERALIZEDTIME *gen = ASN1_GENERALIZEDTIME_new(); | 
| 32 | 45.2k |     char genstr[20]; | 
| 33 |  |  | 
| 34 | 45.2k |     if (gen == NULL) | 
| 35 | 0 |         return; | 
| 36 | 45.2k |     ASN1_GENERALIZEDTIME_adj(gen, (time_t)0, | 
| 37 | 45.2k |                              (int)(timestamp / 86400000), | 
| 38 | 45.2k |                              (timestamp % 86400000) / 1000); | 
| 39 |  |     /* | 
| 40 |  |      * Note GeneralizedTime from ASN1_GENERALIZETIME_adj is always 15 | 
| 41 |  |      * characters long with a final Z. Update it with fractional seconds. | 
| 42 |  |      */ | 
| 43 | 45.2k |     BIO_snprintf(genstr, sizeof(genstr), "%.14s.%03dZ", | 
| 44 | 45.2k |                  ASN1_STRING_get0_data(gen), (unsigned int)(timestamp % 1000)); | 
| 45 | 45.2k |     if (ASN1_GENERALIZEDTIME_set_string(gen, genstr)) | 
| 46 | 28.1k |         ASN1_GENERALIZEDTIME_print(out, gen); | 
| 47 | 45.2k |     ASN1_GENERALIZEDTIME_free(gen); | 
| 48 | 45.2k | } | 
| 49 |  |  | 
| 50 |  | const char *SCT_validation_status_string(const SCT *sct) | 
| 51 | 0 | { | 
| 52 |  | 
 | 
| 53 | 0 |     switch (SCT_get_validation_status(sct)) { | 
| 54 | 0 |     case SCT_VALIDATION_STATUS_NOT_SET: | 
| 55 | 0 |         return "not set"; | 
| 56 | 0 |     case SCT_VALIDATION_STATUS_UNKNOWN_VERSION: | 
| 57 | 0 |         return "unknown version"; | 
| 58 | 0 |     case SCT_VALIDATION_STATUS_UNKNOWN_LOG: | 
| 59 | 0 |         return "unknown log"; | 
| 60 | 0 |     case SCT_VALIDATION_STATUS_UNVERIFIED: | 
| 61 | 0 |         return "unverified"; | 
| 62 | 0 |     case SCT_VALIDATION_STATUS_INVALID: | 
| 63 | 0 |         return "invalid"; | 
| 64 | 0 |     case SCT_VALIDATION_STATUS_VALID: | 
| 65 | 0 |         return "valid"; | 
| 66 | 0 |     } | 
| 67 | 0 |     return "unknown status"; | 
| 68 | 0 | } | 
| 69 |  |  | 
| 70 |  | void SCT_print(const SCT *sct, BIO *out, int indent, | 
| 71 |  |                const CTLOG_STORE *log_store) | 
| 72 | 446k | { | 
| 73 | 446k |     const CTLOG *log = NULL; | 
| 74 |  |  | 
| 75 | 446k |     if (log_store != NULL) { | 
| 76 | 0 |         log = CTLOG_STORE_get0_log_by_id(log_store, sct->log_id, | 
| 77 | 0 |                                          sct->log_id_len); | 
| 78 | 0 |     } | 
| 79 |  |  | 
| 80 | 446k |     BIO_printf(out, "%*sSigned Certificate Timestamp:", indent, ""); | 
| 81 | 446k |     BIO_printf(out, "\n%*sVersion   : ", indent + 4, ""); | 
| 82 |  |  | 
| 83 | 446k |     if (sct->version != SCT_VERSION_V1) { | 
| 84 | 400k |         BIO_printf(out, "unknown\n%*s", indent + 16, ""); | 
| 85 | 400k |         BIO_hex_string(out, indent + 16, 16, sct->sct, sct->sct_len); | 
| 86 | 400k |         return; | 
| 87 | 400k |     } | 
| 88 |  |  | 
| 89 | 45.2k |     BIO_printf(out, "v1 (0x0)"); | 
| 90 |  |  | 
| 91 | 45.2k |     if (log != NULL) { | 
| 92 | 0 |         BIO_printf(out, "\n%*sLog       : %s", indent + 4, "", | 
| 93 | 0 |                    CTLOG_get0_name(log)); | 
| 94 | 0 |     } | 
| 95 |  |  | 
| 96 | 45.2k |     BIO_printf(out, "\n%*sLog ID    : ", indent + 4, ""); | 
| 97 | 45.2k |     BIO_hex_string(out, indent + 16, 16, sct->log_id, sct->log_id_len); | 
| 98 |  |  | 
| 99 | 45.2k |     BIO_printf(out, "\n%*sTimestamp : ", indent + 4, ""); | 
| 100 | 45.2k |     timestamp_print(sct->timestamp, out); | 
| 101 |  |  | 
| 102 | 45.2k |     BIO_printf(out, "\n%*sExtensions: ", indent + 4, ""); | 
| 103 | 45.2k |     if (sct->ext_len == 0) | 
| 104 | 36.9k |         BIO_printf(out, "none"); | 
| 105 | 8.33k |     else | 
| 106 | 8.33k |         BIO_hex_string(out, indent + 16, 16, sct->ext, sct->ext_len); | 
| 107 |  |  | 
| 108 | 45.2k |     BIO_printf(out, "\n%*sSignature : ", indent + 4, ""); | 
| 109 | 45.2k |     SCT_signature_algorithms_print(sct, out); | 
| 110 | 45.2k |     BIO_printf(out, "\n%*s            ", indent + 4, ""); | 
| 111 | 45.2k |     BIO_hex_string(out, indent + 16, 16, sct->sig, sct->sig_len); | 
| 112 | 45.2k | } | 
| 113 |  |  | 
| 114 |  | void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent, | 
| 115 |  |                     const char *separator, const CTLOG_STORE *log_store) | 
| 116 | 31.9k | { | 
| 117 | 31.9k |     int sct_count = sk_SCT_num(sct_list); | 
| 118 | 31.9k |     int i; | 
| 119 |  |  | 
| 120 | 477k |     for (i = 0; i < sct_count; ++i) { | 
| 121 | 446k |         SCT *sct = sk_SCT_value(sct_list, i); | 
| 122 |  |  | 
| 123 | 446k |         SCT_print(sct, out, indent, log_store); | 
| 124 | 446k |         if (i < sk_SCT_num(sct_list) - 1) | 
| 125 | 416k |             BIO_printf(out, "%s", separator); | 
| 126 | 446k |     } | 
| 127 | 31.9k | } |