]>
git.cameronkatri.com Git - trustcache.git/blob - info.c
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2022 Cameron Katri. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY CAMERON KATRI AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL CAMERON KATRI OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "trustcache.h"
39 tcinfo(int argc
, char **argv
)
41 struct trust_cache cache
;
42 bool headeronly
= false, onlyhash
= false;
43 uint32_t entrynum
= 0;
44 const char *errstr
= NULL
;
47 while ((ch
= getopt(argc
, argv
, "che:")) != -1) {
53 entrynum
= strtonum(optarg
, 1, UINT32_MAX
, &errstr
);
55 fprintf(stderr
, "entry number is %s: %s\n", errstr
, optarg
);
71 cache
= opentrustcache(argv
[0]);
73 if (entrynum
== 0 && !onlyhash
)
77 for (uint32_t i
= 0; i
< cache
.num_entries
; i
++) {
78 if (cache
.version
== 0)
79 print_hash(cache
.hashes
[i
], true);
80 else if (cache
.version
== 1)
81 print_hash(cache
.entries
[i
].cdhash
, true);
82 else if (cache
.version
== 2)
83 print_hash(cache
.entries2
[i
].cdhash
, true);
88 if (entrynum
> cache
.num_entries
) {
89 fprintf(stderr
, "no entry %i\n", entrynum
);
92 if (cache
.version
== 0) {
93 print_hash(cache
.hashes
[entrynum
- 1], true);
94 } else if (cache
.version
== 1) {
95 print_entry(cache
.entries
[entrynum
- 1]);
96 } else if (cache
.version
== 2) {
97 print_entry2(cache
.entries2
[entrynum
- 1]);
100 print_entries(cache
);
111 print_header(struct trust_cache cache
)
113 printf("version = %i\n", cache
.version
);
115 uuid_unparse(cache
.uuid
, out
);
116 printf("uuid = %s\n", out
);
117 printf("entry count = %i\n", cache
.num_entries
);
121 print_entries(struct trust_cache cache
)
123 for (uint32_t i
= 0; i
< cache
.num_entries
; i
++) {
124 if (cache
.version
== 0)
125 print_hash(cache
.hashes
[i
], true);
126 else if (cache
.version
== 1)
127 print_entry(cache
.entries
[i
]);
128 else if (cache
.version
== 2)
129 print_entry2(cache
.entries2
[i
]);
134 print_entry(struct trust_cache_entry1 entry
)
136 print_hash(entry
.cdhash
, false);
138 switch (entry
.flags
) {
139 case CS_TRUST_CACHE_AMFID
:
140 printf(" CS_TRUST_CACHE_AMFID ");
142 case CS_TRUST_CACHE_ANE
:
143 printf(" CS_TRUST_CACHE_ANE ");
145 case CS_TRUST_CACHE_AMFID
|CS_TRUST_CACHE_ANE
:
146 printf(" CS_TRUST_CACHE_AMFID|CS_TRUST_CACHE_ANE ");
152 printf(" [%i] ", entry
.flags
);
156 printf("[%i]\n", entry
.hash_type
);
160 print_entry2(struct trust_cache_entry2 entry
)
162 print_hash(entry
.cdhash
, false);
164 switch (entry
.flags
) {
165 case CS_TRUST_CACHE_AMFID
:
166 printf(" CS_TRUST_CACHE_AMFID ");
168 case CS_TRUST_CACHE_ANE
:
169 printf(" CS_TRUST_CACHE_ANE ");
171 case CS_TRUST_CACHE_AMFID
|CS_TRUST_CACHE_ANE
:
172 printf(" CS_TRUST_CACHE_AMFID|CS_TRUST_CACHE_ANE ");
178 printf(" [%i] ", entry
.flags
);
182 printf("[%i] [%i]\n", entry
.hash_type
, entry
.category
);
186 print_hash(uint8_t cdhash
[CS_CDHASH_LEN
], bool newline
)
188 for (size_t j
= 0; j
< CS_CDHASH_LEN
; j
++) {
189 printf("%02x", cdhash
[j
]);