This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1449 from advancedtelematic/feat/OTA-3969/ip-seco…
…ndary-full-verification OTA-3969: Do the full verification of metadata on the IP Secondary
- Loading branch information
Showing
17 changed files
with
462 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "aktualizr_secondary_metadata.h" | ||
|
||
Metadata::Metadata(const Uptane::RawMetaPack& meta_pack) | ||
: _director_metadata{{Uptane::Role::ROOT, meta_pack.director_root}, | ||
{Uptane::Role::TARGETS, meta_pack.director_targets}}, | ||
_image_metadata{ | ||
{Uptane::Role::ROOT, meta_pack.image_root}, | ||
{Uptane::Role::TIMESTAMP, meta_pack.image_timestamp}, | ||
{Uptane::Role::SNAPSHOT, meta_pack.image_snapshot}, | ||
{Uptane::Role::TARGETS, meta_pack.image_targets}, | ||
} {} | ||
|
||
bool Metadata::fetchRole(std::string* result, int64_t maxsize, Uptane::RepositoryType repo, const Uptane::Role& role, | ||
Uptane::Version version) const { | ||
(void)maxsize; | ||
(void)version; | ||
|
||
return getRoleMetadata(result, repo, role); | ||
} | ||
|
||
bool Metadata::fetchLatestRole(std::string* result, int64_t maxsize, Uptane::RepositoryType repo, | ||
const Uptane::Role& role) const { | ||
(void)maxsize; | ||
return getRoleMetadata(result, repo, role); | ||
} | ||
|
||
bool Metadata::getRoleMetadata(std::string* result, const Uptane::RepositoryType& repo, | ||
const Uptane::Role& role) const { | ||
const std::unordered_map<std::string, std::string>* metadata_map = nullptr; | ||
|
||
if (repo == Uptane::RepositoryType::Director()) { | ||
metadata_map = &_director_metadata; | ||
} else if (repo == Uptane::RepositoryType::Image()) { | ||
metadata_map = &_image_metadata; | ||
} | ||
|
||
if (metadata_map == nullptr) { | ||
LOG_ERROR << "There are no any metadata for the given type of repository: " << repo.toString(); | ||
return false; | ||
} | ||
|
||
auto found_meta_it = metadata_map->find(role.ToString()); | ||
if (found_meta_it == metadata_map->end()) { | ||
LOG_ERROR << "There are no any metadata for the given type of role: " << repo.toString() << ": " << role.ToString(); | ||
return false; | ||
} | ||
|
||
*result = found_meta_it->second; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef AKTUALIZR_SECONDARY_METADATA_H_ | ||
#define AKTUALIZR_SECONDARY_METADATA_H_ | ||
|
||
#include <unordered_map> | ||
|
||
#include "uptane/fetcher.h" | ||
|
||
class Metadata : public Uptane::IMetadataFetcher { | ||
public: | ||
Metadata(const Uptane::RawMetaPack& meta_pack); | ||
|
||
bool fetchRole(std::string* result, int64_t maxsize, Uptane::RepositoryType repo, const Uptane::Role& role, | ||
Uptane::Version version) const override; | ||
bool fetchLatestRole(std::string* result, int64_t maxsize, Uptane::RepositoryType repo, | ||
const Uptane::Role& role) const override; | ||
|
||
private: | ||
bool getRoleMetadata(std::string* result, const Uptane::RepositoryType& repo, const Uptane::Role& role) const; | ||
|
||
private: | ||
const std::unordered_map<std::string, std::string> _director_metadata; | ||
const std::unordered_map<std::string, std::string> _image_metadata; | ||
}; | ||
|
||
#endif // AKTUALIZR_SECONDARY_METADATA_H_ |
Oops, something went wrong.