summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ct/ct_prn.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/ct/ct_prn.c168
1 files changed, 85 insertions, 83 deletions
diff --git a/src/lib/libcrypto/ct/ct_prn.c b/src/lib/libcrypto/ct/ct_prn.c
index e6584b57f3..3cd9b8e838 100644
--- a/src/lib/libcrypto/ct/ct_prn.c
+++ b/src/lib/libcrypto/ct/ct_prn.c
@@ -16,112 +16,114 @@
16 16
17#include "ct_local.h" 17#include "ct_local.h"
18 18
19static void SCT_signature_algorithms_print(const SCT *sct, BIO *out) 19static void
20SCT_signature_algorithms_print(const SCT *sct, BIO *out)
20{ 21{
21 int nid = SCT_get_signature_nid(sct); 22 int nid = SCT_get_signature_nid(sct);
22 23
23 if (nid == NID_undef) 24 if (nid == NID_undef)
24 BIO_printf(out, "%02X%02X", sct->hash_alg, sct->sig_alg); 25 BIO_printf(out, "%02X%02X", sct->hash_alg, sct->sig_alg);
25 else 26 else
26 BIO_printf(out, "%s", OBJ_nid2ln(nid)); 27 BIO_printf(out, "%s", OBJ_nid2ln(nid));
27} 28}
28 29
29static void timestamp_print(uint64_t timestamp, BIO *out) 30static void
31timestamp_print(uint64_t timestamp, BIO *out)
30{ 32{
31 ASN1_GENERALIZEDTIME *gen = ASN1_GENERALIZEDTIME_new(); 33 ASN1_GENERALIZEDTIME *gen = ASN1_GENERALIZEDTIME_new();
32 char genstr[20]; 34 char genstr[20];
33 35
34 if (gen == NULL) 36 if (gen == NULL)
35 return; 37 return;
36 ASN1_GENERALIZEDTIME_adj(gen, (time_t)0, 38 ASN1_GENERALIZEDTIME_adj(gen, (time_t)0,(int)(timestamp / 86400000),
37 (int)(timestamp / 86400000), 39 (timestamp % 86400000) / 1000);
38 (timestamp % 86400000) / 1000); 40 /*
39 /* 41 * Note GeneralizedTime from ASN1_GENERALIZETIME_adj is always 15
40 * Note GeneralizedTime from ASN1_GENERALIZETIME_adj is always 15 42 * characters long with a final Z. Update it with fractional seconds.
41 * characters long with a final Z. Update it with fractional seconds. 43 */
42 */ 44 BIO_snprintf(genstr, sizeof(genstr), "%.14s.%03dZ",
43 BIO_snprintf(genstr, sizeof(genstr), "%.14s.%03dZ", 45 ASN1_STRING_get0_data(gen), (unsigned int)(timestamp % 1000));
44 ASN1_STRING_get0_data(gen), (unsigned int)(timestamp % 1000)); 46 if (ASN1_GENERALIZEDTIME_set_string(gen, genstr))
45 if (ASN1_GENERALIZEDTIME_set_string(gen, genstr)) 47 ASN1_GENERALIZEDTIME_print(out, gen);
46 ASN1_GENERALIZEDTIME_print(out, gen); 48 ASN1_GENERALIZEDTIME_free(gen);
47 ASN1_GENERALIZEDTIME_free(gen);
48} 49}
49 50
50const char *SCT_validation_status_string(const SCT *sct) 51const char *
52SCT_validation_status_string(const SCT *sct)
51{ 53{
52 54 switch (SCT_get_validation_status(sct)) {
53 switch (SCT_get_validation_status(sct)) { 55 case SCT_VALIDATION_STATUS_NOT_SET:
54 case SCT_VALIDATION_STATUS_NOT_SET: 56 return "not set";
55 return "not set"; 57 case SCT_VALIDATION_STATUS_UNKNOWN_VERSION:
56 case SCT_VALIDATION_STATUS_UNKNOWN_VERSION: 58 return "unknown version";
57 return "unknown version"; 59 case SCT_VALIDATION_STATUS_UNKNOWN_LOG:
58 case SCT_VALIDATION_STATUS_UNKNOWN_LOG: 60 return "unknown log";
59 return "unknown log"; 61 case SCT_VALIDATION_STATUS_UNVERIFIED:
60 case SCT_VALIDATION_STATUS_UNVERIFIED: 62 return "unverified";
61 return "unverified"; 63 case SCT_VALIDATION_STATUS_INVALID:
62 case SCT_VALIDATION_STATUS_INVALID: 64 return "invalid";
63 return "invalid"; 65 case SCT_VALIDATION_STATUS_VALID:
64 case SCT_VALIDATION_STATUS_VALID: 66 return "valid";
65 return "valid"; 67 }
66 } 68 return "unknown status";
67 return "unknown status";
68} 69}
69 70
70void SCT_print(const SCT *sct, BIO *out, int indent, 71void
71 const CTLOG_STORE *log_store) 72SCT_print(const SCT *sct, BIO *out, int indent, const CTLOG_STORE *log_store)
72{ 73{
73 const CTLOG *log = NULL; 74 const CTLOG *log = NULL;
74 75
75 if (log_store != NULL) { 76 if (log_store != NULL) {
76 log = CTLOG_STORE_get0_log_by_id(log_store, sct->log_id, 77 log = CTLOG_STORE_get0_log_by_id(log_store, sct->log_id,
77 sct->log_id_len); 78 sct->log_id_len);
78 } 79 }
79 80
80 BIO_printf(out, "%*sSigned Certificate Timestamp:", indent, ""); 81 BIO_printf(out, "%*sSigned Certificate Timestamp:", indent, "");
81 BIO_printf(out, "\n%*sVersion : ", indent + 4, ""); 82 BIO_printf(out, "\n%*sVersion : ", indent + 4, "");
82 83
83 if (sct->version != SCT_VERSION_V1) { 84 if (sct->version != SCT_VERSION_V1) {
84 BIO_printf(out, "unknown\n%*s", indent + 16, ""); 85 BIO_printf(out, "unknown\n%*s", indent + 16, "");
85 BIO_hex_string(out, indent + 16, 16, sct->sct, sct->sct_len); 86 BIO_hex_string(out, indent + 16, 16, sct->sct, sct->sct_len);
86 return; 87 return;
87 } 88 }
88 89
89 BIO_printf(out, "v1 (0x0)"); 90 BIO_printf(out, "v1 (0x0)");
90 91
91 if (log != NULL) { 92 if (log != NULL) {
92 BIO_printf(out, "\n%*sLog : %s", indent + 4, "", 93 BIO_printf(out, "\n%*sLog : %s", indent + 4, "",
93 CTLOG_get0_name(log)); 94 CTLOG_get0_name(log));
94 } 95 }
95 96
96 BIO_printf(out, "\n%*sLog ID : ", indent + 4, ""); 97 BIO_printf(out, "\n%*sLog ID : ", indent + 4, "");
97 BIO_hex_string(out, indent + 16, 16, sct->log_id, sct->log_id_len); 98 BIO_hex_string(out, indent + 16, 16, sct->log_id, sct->log_id_len);
98 99
99 BIO_printf(out, "\n%*sTimestamp : ", indent + 4, ""); 100 BIO_printf(out, "\n%*sTimestamp : ", indent + 4, "");
100 timestamp_print(sct->timestamp, out); 101 timestamp_print(sct->timestamp, out);
101 102
102 BIO_printf(out, "\n%*sExtensions: ", indent + 4, ""); 103 BIO_printf(out, "\n%*sExtensions: ", indent + 4, "");
103 if (sct->ext_len == 0) 104 if (sct->ext_len == 0)
104 BIO_printf(out, "none"); 105 BIO_printf(out, "none");
105 else 106 else
106 BIO_hex_string(out, indent + 16, 16, sct->ext, sct->ext_len); 107 BIO_hex_string(out, indent + 16, 16, sct->ext, sct->ext_len);
107 108
108 BIO_printf(out, "\n%*sSignature : ", indent + 4, ""); 109 BIO_printf(out, "\n%*sSignature : ", indent + 4, "");
109 SCT_signature_algorithms_print(sct, out); 110 SCT_signature_algorithms_print(sct, out);
110 BIO_printf(out, "\n%*s ", indent + 4, ""); 111 BIO_printf(out, "\n%*s ", indent + 4, "");
111 BIO_hex_string(out, indent + 16, 16, sct->sig, sct->sig_len); 112 BIO_hex_string(out, indent + 16, 16, sct->sig, sct->sig_len);
112} 113}
113 114
114void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent, 115void
115 const char *separator, const CTLOG_STORE *log_store) 116SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent,
117 const char *separator, const CTLOG_STORE *log_store)
116{ 118{
117 int sct_count = sk_SCT_num(sct_list); 119 int sct_count = sk_SCT_num(sct_list);
118 int i; 120 int i;
119 121
120 for (i = 0; i < sct_count; ++i) { 122 for (i = 0; i < sct_count; ++i) {
121 SCT *sct = sk_SCT_value(sct_list, i); 123 SCT *sct = sk_SCT_value(sct_list, i);
122 124
123 SCT_print(sct, out, indent, log_store); 125 SCT_print(sct, out, indent, log_store);
124 if (i < sk_SCT_num(sct_list) - 1) 126 if (i < sk_SCT_num(sct_list) - 1)
125 BIO_printf(out, "%s", separator); 127 BIO_printf(out, "%s", separator);
126 } 128 }
127} 129}