]> git.cameronkatri.com Git - trustcache.git/blob - trustcache.h
Add support for new version 2 trustcaches
[trustcache.git] / trustcache.h
1 #ifndef _TRUSTCACHE_H_
2 #define _TRUSTCACHE_H_
3
4 #include <stdbool.h>
5 #include <sys/types.h>
6
7 #if __APPLE__
8 # include <libkern/OSByteOrder.h>
9 # define htole32(x) OSSwapHostToLittleInt32(x)
10 # define le32toh(x) OSSwapLittleToHostInt32(x)
11 #elif __has_include(<endian.h>)
12 # include <endian.h>
13 #else
14 # include <sys/endian.h>
15 #endif
16
17 #include "machoparse/cs_blobs.h"
18 #include "uuid/uuid.h"
19
20 struct trust_cache_entry2 {
21 uint8_t cdhash[CS_CDHASH_LEN];
22 uint8_t hash_type;
23 uint8_t flags;
24 uint16_t category;
25 } __attribute__((__packed__));
26
27 struct trust_cache_entry1 {
28 uint8_t cdhash[CS_CDHASH_LEN];
29 uint8_t hash_type;
30 uint8_t flags;
31 } __attribute__((__packed__));
32
33 typedef uint8_t trust_cache_hash0[CS_CDHASH_LEN];
34
35 struct trust_cache {
36 uint32_t version;
37 uuid_t uuid;
38 uint32_t num_entries;
39 union {
40 struct trust_cache_entry2 *entries2;
41 struct trust_cache_entry1 *entries;
42 trust_cache_hash0 *hashes;
43 };
44 } __attribute__((__packed__));
45
46 // flags
47 #define CS_TRUST_CACHE_AMFID 0x1
48 #define CS_TRUST_CACHE_ANE 0x2
49
50 struct trust_cache opentrustcache(const char *path);
51 int writetrustcache(struct trust_cache cache, const char *path);
52 struct trust_cache cache_from_tree(const char *path, uint32_t version);
53
54 int tcinfo(int argc, char **argv);
55 int tccreate(int argc, char **argv);
56 int tcappend(int argc, char **argv);
57 int tcremove(int argc, char **argv);
58
59 int ent_cmp(const void * vp1, const void * vp2);
60 int hash_cmp(const void * vp1, const void * vp2);
61
62 void print_header(struct trust_cache cache);
63 void print_hash(uint8_t cdhash[CS_CDHASH_LEN], bool newline);
64 void print_entry(struct trust_cache_entry1 entry);
65 void print_entry2(struct trust_cache_entry2 entry);
66 void print_entries(struct trust_cache cache);
67
68 #endif