Aktualizr
C++ SOTA Client
uptanerepository.cc
1 #include "uptane/uptanerepository.h"
2 
3 #include <stdio.h>
4 
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>
11 #include <utility>
12 
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"
19 
20 namespace Uptane {
21 
22 bool RepositoryCommon::initRoot(const std::string& root_raw) {
23  try {
24  root = Root(type, Utils::parseJSON(root_raw)); // initialization and format check
25  root = Root(type, Utils::parseJSON(root_raw), root); // signature verification against itself
26  } catch (const std::exception& e) {
27  LOG_ERROR << "Loading initial root failed: " << e.what();
28  throw;
29  return false;
30  }
31  return true;
32 }
33 
34 bool RepositoryCommon::verifyRoot(const std::string& root_raw) {
35  try {
36  int prev_version = root.version();
37  root = Root(type, Utils::parseJSON(root_raw), root); // double signature verification
38  if (root.version() != prev_version + 1) {
39  LOG_ERROR << "Version in root metadata doesn't match the expected value";
40  return false;
41  }
42  } catch (const std::exception& e) {
43  LOG_ERROR << "Signature verification for root metadata failed: " << e.what();
44  return false;
45  }
46  return true;
47 }
48 
49 void RepositoryCommon::resetRoot() { root = Root(Root::Policy::kAcceptAll); }
50 
51 Json::Value Manifest::signManifest(const Json::Value& version_manifests) {
52  Json::Value manifest;
53  manifest["primary_ecu_serial"] = primary_ecu_serial.ToString();
54  manifest["ecu_version_manifests"] = version_manifests;
55 
56  return keys_.signTuf(manifest);
57 }
58 
59 Json::Value Manifest::signVersionManifest(const Json::Value& primary_version_manifests) {
60  Json::Value ecu_version_signed = keys_.signTuf(primary_version_manifests);
61  return ecu_version_signed;
62 }
63 
64 } // namespace Uptane
Base data types that are used in The Update Framework (TUF), part of UPTANE.