-
Notifications
You must be signed in to change notification settings - Fork 17
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 #35 from uptane/virtual-secondary-verification
Implement proper metadata verification in ManagedSecondary.
- Loading branch information
Showing
18 changed files
with
213 additions
and
206 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
#include "secondary_metadata.h" | ||
|
||
namespace Uptane { | ||
|
||
SecondaryMetadata::SecondaryMetadata(MetaBundle meta_bundle_in) : meta_bundle_(std::move(meta_bundle_in)) { | ||
try { | ||
director_root_version_ = | ||
Version(extractVersionUntrusted(getMetaFromBundle(meta_bundle_, RepositoryType::Director(), Role::Root()))); | ||
} catch (const std::exception& e) { | ||
LOG_DEBUG << "Failed to read Director Root version: " << e.what(); | ||
} | ||
try { | ||
image_root_version_ = | ||
Version(extractVersionUntrusted(getMetaFromBundle(meta_bundle_, RepositoryType::Image(), Role::Root()))); | ||
} catch (const std::exception& e) { | ||
LOG_DEBUG << "Failed to read Image repo Root version: " << e.what(); | ||
} | ||
} | ||
|
||
void SecondaryMetadata::fetchRole(std::string* result, int64_t maxsize, RepositoryType repo, const Role& role, | ||
Version version) const { | ||
(void)maxsize; | ||
getRoleMetadata(result, repo, role, version); | ||
} | ||
|
||
void SecondaryMetadata::fetchLatestRole(std::string* result, int64_t maxsize, RepositoryType repo, | ||
const Role& role) const { | ||
(void)maxsize; | ||
getRoleMetadata(result, repo, role, Version()); | ||
} | ||
|
||
void SecondaryMetadata::getRoleMetadata(std::string* result, const RepositoryType& repo, const Role& role, | ||
Version version) const { | ||
if (role == Role::Root() && version != Version()) { | ||
// If requesting a Root version beyond what we have available, fail as | ||
// expected. If requesting a version before what is available, just use what | ||
// is available, since root rotation isn't supported here. | ||
if (repo == RepositoryType::Director() && director_root_version_ < version) { | ||
LOG_DEBUG << "Requested Director Root version " << version << " but only version " << director_root_version_ | ||
<< " is available."; | ||
throw std::runtime_error("Metadata not found"); | ||
} else if (repo == RepositoryType::Image() && image_root_version_ < version) { | ||
LOG_DEBUG << "Requested Image repo Root version " << version << " but only version " << image_root_version_ | ||
<< " is available."; | ||
throw std::runtime_error("Metadata not found"); | ||
} | ||
} | ||
|
||
*result = getMetaFromBundle(meta_bundle_, repo, role); | ||
} | ||
|
||
} // namespace Uptane |
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,30 @@ | ||
#ifndef AKTUALIZR_SECONDARY_METADATA_H_ | ||
#define AKTUALIZR_SECONDARY_METADATA_H_ | ||
|
||
#include "uptane/fetcher.h" | ||
#include "uptane/tuf.h" | ||
|
||
namespace Uptane { | ||
|
||
class SecondaryMetadata : public IMetadataFetcher { | ||
public: | ||
SecondaryMetadata(MetaBundle meta_bundle_in); | ||
SecondaryMetadata(SecondaryMetadata&&) = default; | ||
|
||
void fetchRole(std::string* result, int64_t maxsize, RepositoryType repo, const Role& role, | ||
Version version) const override; | ||
void fetchLatestRole(std::string* result, int64_t maxsize, RepositoryType repo, const Role& role) const override; | ||
|
||
protected: | ||
virtual void getRoleMetadata(std::string* result, const RepositoryType& repo, const Role& role, | ||
Version version) const; | ||
|
||
private: | ||
const MetaBundle meta_bundle_; | ||
Version director_root_version_; | ||
Version image_root_version_; | ||
}; | ||
|
||
} // namespace Uptane | ||
|
||
#endif // AKTUALIZR_SECONDARY_METADATA_H_ |
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
Oops, something went wrong.