1 #include "uptane/uptanerepository.h"
5 #include <openssl/bio.h>
6 #include <openssl/pem.h>
7 #include <openssl/x509.h>
8 #include <boost/algorithm/hex.hpp>
9 #include <boost/algorithm/string/replace.hpp>
10 #include <boost/algorithm/string/trim.hpp>
13 #include "bootstrap/bootstrap.h"
14 #include "crypto/crypto.h"
15 #include "crypto/openssl_compat.h"
16 #include "logging/logging.h"
17 #include "storage/invstorage.h"
18 #include "utilities/utils.h"
22 bool RepositoryCommon::initRoot(
const std::string& root_raw) {
24 root = Root(type, Utils::parseJSON(root_raw));
25 root = Root(type, Utils::parseJSON(root_raw), root);
26 }
catch (
const std::exception& e) {
27 LOG_ERROR <<
"Loading initial root failed: " << e.what();
33 bool RepositoryCommon::verifyRoot(
const std::string& root_raw) {
35 int prev_version = rootVersion();
40 root = Root(type, Utils::parseJSON(root_raw), root);
45 if (root.version() != prev_version + 1) {
46 LOG_ERROR <<
"Version in root metadata doesn't match the expected value";
49 }
catch (
const std::exception& e) {
50 LOG_ERROR <<
"Signature verification for root metadata failed: " << e.what();
56 void RepositoryCommon::resetRoot() { root = Root(Root::Policy::kAcceptAll); }
58 bool RepositoryCommon::updateRoot(
INvStorage& storage,
const IMetadataFetcher& fetcher,
59 const RepositoryType repo_type) {
63 if (storage.loadLatestRoot(&root_raw, repo_type)) {
64 if (!initRoot(root_raw)) {
70 if (repo_type == RepositoryType::Director()) {
71 if (!fetcher.fetchLatestRole(&root_raw, kMaxRootSize, repo_type, Role::Root())) {
76 if (!fetcher.fetchRole(&root_raw, kMaxRootSize, repo_type, Role::Root(),
Version(1))) {
79 if (!initRoot(root_raw)) {
82 storage.storeRoot(root_raw, repo_type,
Version(1));
87 for (
int version = rootVersion() + 1; version < kMaxRotations; ++version) {
90 if (!fetcher.fetchRole(&root_raw, kMaxRootSize, repo_type, Role::Root(),
Version(version))) {
94 if (!verifyRoot(root_raw)) {
100 storage.storeRoot(root_raw, repo_type,
Version(version));
101 storage.clearNonRootMeta(repo_type);
107 return !rootExpired();