1 #include "imagesrepository.h" 5 void ImagesRepository::resetMeta() {
9 timestamp = TimestampMeta();
12 bool ImagesRepository::verifyTimestamp(
const std::string& timestamp_raw) {
14 timestamp = TimestampMeta(RepositoryType::Images, Utils::parseJSON(timestamp_raw), root);
15 }
catch (
const Exception& e) {
16 LOG_ERROR <<
"Signature verification for timestamp metadata failed";
23 bool ImagesRepository::verifySnapshot(
const std::string& snapshot_raw) {
25 std::string canonical = Utils::jsonToCanonicalStr(Utils::parseJSON(snapshot_raw));
26 bool hash_exists =
false;
27 for (
const auto& it : timestamp.snapshot_hashes()) {
29 case Hash::Type::kSha256:
30 if (Hash(Hash::Type::kSha256, boost::algorithm::hex(Crypto::sha256digest(canonical))) != it) {
31 LOG_ERROR <<
"Hash verification for snapshot metadata failed";
36 case Hash::Type::kSha512:
37 if (Hash(Hash::Type::kSha512, boost::algorithm::hex(Crypto::sha512digest(canonical))) != it) {
38 LOG_ERROR <<
"Hash verification for snapshot metadata failed";
48 LOG_ERROR <<
"No hash found for shapshot.json";
51 snapshot = Snapshot(RepositoryType::Images, Utils::parseJSON(snapshot_raw), root);
52 if (snapshot.version() != timestamp.snapshot_version()) {
55 }
catch (
const Exception& e) {
56 LOG_ERROR <<
"Signature verification for snapshot metadata failed";
63 bool ImagesRepository::verifyTargets(
const std::string& targets_raw) {
65 std::string canonical = Utils::jsonToCanonicalStr(Utils::parseJSON(targets_raw));
66 bool hash_exists =
false;
67 for (
const auto& it : snapshot.targets_hashes()) {
69 case Hash::Type::kSha256:
70 if (Hash(Hash::Type::kSha256, boost::algorithm::hex(Crypto::sha256digest(canonical))) != it) {
71 LOG_ERROR <<
"Hash verification for targets metadata failed";
76 case Hash::Type::kSha512:
77 if (Hash(Hash::Type::kSha512, boost::algorithm::hex(Crypto::sha512digest(canonical))) != it) {
78 LOG_ERROR <<
"Hash verification for targets metadata failed";
88 LOG_ERROR <<
"No hash found for targets.json";
91 targets = Targets(RepositoryType::Images, Utils::parseJSON(targets_raw), root);
92 if (targets.version() != snapshot.targets_version()) {
95 }
catch (
const Exception& e) {
96 LOG_ERROR <<
"Signature verification for images targets metadata failed";
103 std::unique_ptr<Uptane::Target> ImagesRepository::getTarget(
const Uptane::Target& director_target) {
104 auto it = std::find(targets.targets.begin(), targets.targets.end(), director_target);
105 if (it == targets.targets.end()) {
106 return std::unique_ptr<Uptane::Target>(
nullptr);
108 return std_::make_unique<Uptane::Target>(*it);
Base data types that are used in The Update Framework (TUF), part of UPTANE.