Aktualizr
C++ SOTA Client
root.cc
1 #include "logging/logging.h"
2 #include "uptane/exceptions.h"
3 #include "uptane/tuf.h"
4 
5 using Uptane::Root;
6 
7 Root::Root(const RepositoryType repo, const Json::Value &json, Root &root) : Root(repo, json) {
8  root.UnpackSignedObject(repo, Role::Root(), json);
9  this->Root::UnpackSignedObject(repo, Role::Root(), json);
10 }
11 
12 Root::Root(const RepositoryType repo, const Json::Value &json) : MetaWithKeys(json), policy_(Policy::kCheck) {
13  if (!json["signed"].isMember("keys")) {
14  throw InvalidMetadata(repo, "root", "missing keys field");
15  } else if (!json["signed"].isMember("roles")) {
16  throw InvalidMetadata(repo, "root", "missing roles field");
17  }
18 
19  const Json::Value keys = json["signed"]["keys"];
20  ParseKeys(repo, keys);
21 
22  const Json::Value roles = json["signed"]["roles"];
23  for (auto it = roles.begin(); it != roles.end(); it++) {
24  const Role role = Role(it.key().asString());
25  ParseRole(repo, it, role, "root");
26  }
27 }
28 
29 void Uptane::Root::UnpackSignedObject(const RepositoryType repo, const Role &role, const Json::Value &signed_object) {
30  const std::string repository = repo;
31 
32  if (policy_ == Policy::kAcceptAll) {
33  return;
34  }
35  if (policy_ == Policy::kRejectAll) {
36  throw SecurityException(repository, "Root policy is Policy::kRejectAll");
37  }
38  assert(policy_ == Policy::kCheck);
39 
40  Uptane::MetaWithKeys::UnpackSignedObject(repo, role, signed_object);
41 }
Uptane::InvalidMetadata
Definition: exceptions.h:81
Uptane::Root::Root
Root(Policy policy=Policy::kRejectAll)
An empty Root, that either accepts or rejects everything.
Definition: tuf.h:221
Uptane::RepositoryType
Definition: tuf.h:21
Uptane::MetaWithKeys
Definition: tuf.h:161
Uptane::Role
TUF Roles.
Definition: tuf.h:61
Uptane::Root
Definition: tuf.h:216
Uptane::Root::UnpackSignedObject
void UnpackSignedObject(RepositoryType repo, const Role &role, const Json::Value &signed_object) override
Take a JSON blob that contains a signatures/signed component that is supposedly for a given role,...
Definition: root.cc:29
Uptane::MetaWithKeys::UnpackSignedObject
virtual void UnpackSignedObject(RepositoryType repo, const Role &role, const Json::Value &signed_object)
Take a JSON blob that contains a signatures/signed component that is supposedly for a given role,...
Definition: metawithkeys.cc:58
Uptane::SecurityException
Definition: exceptions.h:28