Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
managedsecondary.h
1 #ifndef PRIMARY_MANAGEDSECONDARY_H_
2 #define PRIMARY_MANAGEDSECONDARY_H_
3 
4 #include <future>
5 #include <string>
6 #include <vector>
7 
8 #include <boost/filesystem.hpp>
9 #include "json/json.h"
10 
11 #include "primary/secondary_config.h"
12 #include "uptane/secondaryinterface.h"
13 #include "utilities/types.h"
14 
15 namespace Primary {
16 
18  public:
19  ManagedSecondaryConfig(const char* type = Type) : SecondaryConfig(type) {}
20 
21  public:
22  constexpr static const char* const Type = "managed";
23 
24  public:
25  bool partial_verifying{false};
26  std::string ecu_serial;
27  std::string ecu_hardware_id;
28  boost::filesystem::path full_client_dir;
29  std::string ecu_private_key;
30  std::string ecu_public_key;
31  boost::filesystem::path firmware_path;
32  boost::filesystem::path target_name_path;
33  boost::filesystem::path metadata_path;
34  KeyType key_type{KeyType::kRSA2048};
35 };
36 
37 // Managed secondary is an abstraction over virtual and other types of legacy
38 // (non-Uptane) secondaries. They require all the Uptane-related functionality
39 // to be implemented in aktualizr itself, so there's some shared code.
40 
42  public:
44  ~ManagedSecondary() override = default;
45 
46  void Initialize();
47 
48  Uptane::EcuSerial getSerial() const override {
49  if (!sconfig.ecu_serial.empty()) {
50  return Uptane::EcuSerial(sconfig.ecu_serial);
51  }
52  return Uptane::EcuSerial(public_key_.KeyId());
53  }
54  Uptane::HardwareIdentifier getHwId() const override { return Uptane::HardwareIdentifier(sconfig.ecu_hardware_id); }
55  PublicKey getPublicKey() const override { return public_key_; }
56  bool putMetadata(const Uptane::RawMetaPack& meta_pack) override;
57  int getRootVersion(bool director) const override;
58  bool putRoot(const std::string& root, bool director) override;
59 
60  bool sendFirmware(const std::string& data) override;
61  data::ResultCode::Numeric install(const std::string& target_name) override;
62 
63  Uptane::Manifest getManifest() const override;
64 
65  bool loadKeys(std::string* pub_key, std::string* priv_key);
66 
67  protected:
69  std::string detected_attack;
70  std::string expected_target_name;
71  std::vector<Uptane::Hash> expected_target_hashes;
72  uint64_t expected_target_length{};
73  std::mutex install_mutex;
74 
75  virtual bool storeFirmware(const std::string& target_name, const std::string& content) = 0;
76  virtual bool getFirmwareInfo(Uptane::InstalledImageInfo& firmware_info) const = 0;
77 
78  private:
79  PublicKey public_key_;
80  std::string private_key;
81  Uptane::MetaPack current_meta;
82  Uptane::RawMetaPack current_raw_meta;
83 
84  void storeKeys(const std::string& pub_key, const std::string& priv_key);
85  void rawToMeta();
86 
87  // TODO: implement
88  void storeMetadata(const Uptane::RawMetaPack& meta_pack) { (void)meta_pack; }
89  bool loadMetadata(Uptane::RawMetaPack* meta_pack);
90 };
91 
92 } // namespace Primary
93 
94 #endif // PRIMARY_MANAGEDSECONDARY_H_
types.h
data
General data structures.
Definition: types.cc:55
Uptane::HardwareIdentifier
Definition: tuf.h:143
Uptane::MetaPack
Definition: tuf.h:525
Primary::SecondaryConfig
Definition: secondary_config.h:6
Uptane::RawMetaPack
Definition: tuf.h:535
Uptane::InstalledImageInfo
Definition: tuf.h:132
Uptane::EcuSerial
Definition: tuf.h:174
Primary::ManagedSecondaryConfig
Definition: managedsecondary.h:17
PublicKey
Definition: crypto.h:26
Primary::ManagedSecondary
Definition: managedsecondary.h:41
data::ResultCode::Numeric
Numeric
Definition: types.h:128
Uptane::SecondaryInterface
Definition: secondaryinterface.h:12
Uptane::Manifest
Definition: manifest.h:13