1 #include "uptane/uptanerepository.h"
6 #include <openssl/bio.h>
7 #include <openssl/pem.h>
8 #include <openssl/x509.h>
9 #include <boost/algorithm/hex.hpp>
10 #include <boost/algorithm/string/replace.hpp>
11 #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 const std::string RepositoryType::DIRECTOR =
"director";
23 const std::string RepositoryType::IMAGE =
"image";
25 void RepositoryCommon::initRoot(RepositoryType repo_type,
const std::string& root_raw) {
27 root = Root(type, Utils::parseJSON(root_raw));
28 root = Root(type, Utils::parseJSON(root_raw), root);
29 }
catch (
const std::exception& e) {
30 LOG_ERROR <<
"Loading initial " << repo_type.toString() <<
" Root metadata failed: " << e.what();
35 void RepositoryCommon::verifyRoot(
const std::string& root_raw) {
37 int prev_version = rootVersion();
42 root = Root(type, Utils::parseJSON(root_raw), root);
47 if (root.version() != prev_version + 1) {
48 LOG_ERROR <<
"Version " << root.version() <<
" in Root metadata doesn't match the expected value "
52 }
catch (
const std::exception& e) {
53 LOG_ERROR <<
"Signature verification for Root metadata failed: " << e.what();
58 void RepositoryCommon::resetRoot() { root = Root(Root::Policy::kAcceptAll); }
60 void RepositoryCommon::updateRoot(
INvStorage& storage,
const IMetadataFetcher& fetcher,
61 const RepositoryType repo_type) {
65 if (storage.loadLatestRoot(&root_raw, repo_type)) {
66 initRoot(repo_type, root_raw);
68 fetcher.fetchRole(&root_raw, kMaxRootSize, repo_type, Role::Root(), Version(1));
69 initRoot(repo_type, root_raw);
70 storage.storeRoot(root_raw, repo_type, Version(1));
75 for (
int version = rootVersion() + 1; version < kMaxRotations; ++version) {
79 fetcher.fetchRole(&root_raw, kMaxRootSize, repo_type, Role::Root(), Version(version));
80 }
catch (
const std::exception& e) {
88 storage.storeRoot(root_raw, repo_type, Version(version));
89 storage.clearNonRootMeta(repo_type);