Directory: | cvmfs/ |
---|---|
File: | cvmfs/manifest_fetch.h |
Date: | 2025-02-02 02:34:22 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 26 | 26 | 100.0% |
Branches: | 9 | 10 | 90.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * This file is part of the CernVM File System. | ||
3 | */ | ||
4 | |||
5 | #ifndef CVMFS_MANIFEST_FETCH_H_ | ||
6 | #define CVMFS_MANIFEST_FETCH_H_ | ||
7 | |||
8 | #include <cstdlib> | ||
9 | #include <string> | ||
10 | |||
11 | #include "manifest.h" | ||
12 | |||
13 | namespace shash { | ||
14 | struct Any; | ||
15 | } | ||
16 | |||
17 | namespace signature { | ||
18 | class SignatureManager; | ||
19 | } | ||
20 | |||
21 | namespace download { | ||
22 | class DownloadManager; | ||
23 | } | ||
24 | |||
25 | namespace manifest { | ||
26 | |||
27 | enum Failures { | ||
28 | kFailOk = 0, | ||
29 | kFailLoad, | ||
30 | kFailIncomplete, | ||
31 | kFailNameMismatch, | ||
32 | kFailRootMismatch, | ||
33 | kFailOutdated, | ||
34 | kFailBadCertificate, | ||
35 | kFailBadSignature, | ||
36 | kFailBadWhitelist, | ||
37 | kFailInvalidCertificate, | ||
38 | kFailUnknown, | ||
39 | |||
40 | kFailNumEntries | ||
41 | }; | ||
42 | |||
43 | 7 | inline const char *Code2Ascii(const Failures error) { | |
44 | const char *texts[kFailNumEntries + 1]; | ||
45 | 7 | texts[0] = "OK"; | |
46 | 7 | texts[1] = "failed to download"; | |
47 | 7 | texts[2] = "incomplete manifest"; | |
48 | 7 | texts[3] = "repository name mismatch"; | |
49 | 7 | texts[4] = "catalog root path mismatch"; | |
50 | 7 | texts[5] = "outdated manifest"; | |
51 | 7 | texts[6] = "bad certificate, failed to verify repository manifest"; | |
52 | 7 | texts[7] = "bad signature, failed to verify repository manifest"; | |
53 | 7 | texts[8] = "bad whitelist"; | |
54 | 7 | texts[9] = "invalid certificate"; | |
55 | 7 | texts[10] = "unknown error"; | |
56 | 7 | texts[11] = "no text"; | |
57 | 7 | return texts[error]; | |
58 | } | ||
59 | |||
60 | /** | ||
61 | * A manifest requires the certificate and the whitelist to be verified. | ||
62 | * All three (for with the pkcs7 signature of the whitelist) are an ensemble. | ||
63 | */ | ||
64 | struct ManifestEnsemble { | ||
65 | 31 | ManifestEnsemble() { | |
66 | 31 | manifest = NULL; | |
67 | 31 | raw_manifest_buf = cert_buf = whitelist_buf = whitelist_pkcs7_buf = NULL; | |
68 | 31 | raw_manifest_size = cert_size = whitelist_size = whitelist_pkcs7_size = 0; | |
69 | 31 | } | |
70 | 62 | virtual ~ManifestEnsemble() { | |
71 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 6 times.
|
62 | delete manifest; |
72 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 6 times.
|
62 | if (raw_manifest_buf) free(raw_manifest_buf); |
73 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 10 times.
|
62 | if (cert_buf) free(cert_buf); |
74 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 10 times.
|
62 | if (whitelist_buf) free(whitelist_buf); |
75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
62 | if (whitelist_pkcs7_buf) free(whitelist_pkcs7_buf); |
76 | } | ||
77 | // Can be overwritten to fetch certificate from cache | ||
78 | 11 | virtual void FetchCertificate(const shash::Any &hash) {} | |
79 | |||
80 | Manifest *manifest; | ||
81 | unsigned char *raw_manifest_buf; | ||
82 | unsigned char *cert_buf; | ||
83 | unsigned char *whitelist_buf; | ||
84 | unsigned char *whitelist_pkcs7_buf; | ||
85 | unsigned raw_manifest_size; | ||
86 | unsigned cert_size; | ||
87 | unsigned whitelist_size; | ||
88 | unsigned whitelist_pkcs7_size; | ||
89 | }; | ||
90 | |||
91 | // TODO(jblomer): analogous to the Fetcher class, make a ManifestFetcher class | ||
92 | Failures Fetch(const std::string &base_url, const std::string &repository_name, | ||
93 | const uint64_t minimum_timestamp, const shash::Any *base_catalog, | ||
94 | signature::SignatureManager *signature_manager, | ||
95 | download::DownloadManager *download_manager, | ||
96 | ManifestEnsemble *ensemble); | ||
97 | |||
98 | Failures Verify(unsigned char *manifest_data, size_t manifest_size, | ||
99 | const std::string &base_url, const std::string &repository_name, | ||
100 | const uint64_t minimum_timestamp, | ||
101 | const shash::Any *base_catalog, | ||
102 | signature::SignatureManager *signature_manager, | ||
103 | download::DownloadManager *download_manager, | ||
104 | ManifestEnsemble *ensemble); | ||
105 | |||
106 | } // namespace manifest | ||
107 | |||
108 | #endif // CVMFS_MANIFEST_FETCH_H_ | ||
109 |