Aktualizr
C++ SOTA Client
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 "libaktualizr/secondaryinterface.h"
12 #include "libaktualizr/types.h"
13 #include "primary/secondary_config.h"
14 
15 namespace Primary {
16 
17 struct MetaPack;
18 
20  public:
21  ManagedSecondaryConfig(const char* type = Type) : SecondaryConfig(type) {}
22 
23  public:
24  constexpr static const char* const Type = "managed";
25 
26  public:
27  bool partial_verifying{false};
28  std::string ecu_serial;
29  std::string ecu_hardware_id;
30  boost::filesystem::path full_client_dir;
31  std::string ecu_private_key;
32  std::string ecu_public_key;
33  boost::filesystem::path firmware_path;
34  boost::filesystem::path target_name_path;
35  boost::filesystem::path metadata_path;
36  KeyType key_type{KeyType::kRSA2048};
37 };
38 
39 // ManagedSecondary is an abstraction over virtual and other types of legacy
40 // (non-Uptane) Secondaries. They require any the Uptane-related functionality
41 // to be implemented in aktualizr itself.
43  public:
45  ~ManagedSecondary() override;
46 
47  void init(std::shared_ptr<SecondaryProvider> secondary_provider_in) override {
48  secondary_provider_ = std::move(secondary_provider_in);
49  }
50  void Initialize();
51 
52  Uptane::EcuSerial getSerial() const override {
53  if (!sconfig.ecu_serial.empty()) {
54  return Uptane::EcuSerial(sconfig.ecu_serial);
55  }
56  return Uptane::EcuSerial(public_key_.KeyId());
57  }
58  Uptane::HardwareIdentifier getHwId() const override { return Uptane::HardwareIdentifier(sconfig.ecu_hardware_id); }
59  PublicKey getPublicKey() const override { return public_key_; }
60  data::InstallationResult putMetadata(const Uptane::Target& target) override;
61  int getRootVersion(bool director) const override;
62  data::InstallationResult putRoot(const std::string& root, bool director) override;
63 
64  data::InstallationResult sendFirmware(const Uptane::Target& target) override;
65  data::InstallationResult install(const Uptane::Target& target) override;
66 
67  Uptane::Manifest getManifest() const override;
68 
69  bool loadKeys(std::string* pub_key, std::string* priv_key);
70 
71  protected:
72  virtual bool getFirmwareInfo(Uptane::InstalledImageInfo& firmware_info) const;
73 
74  std::shared_ptr<SecondaryProvider> secondary_provider_;
76  std::string detected_attack;
77 
78  private:
79  void storeKeys(const std::string& pub_key, const std::string& priv_key);
80  void rawToMeta();
81 
82  // TODO: implement persistent storage.
83  bool storeMetadata() { return true; }
84  bool loadMetadata() { return true; }
85 
86  PublicKey public_key_;
87  std::string private_key;
88  std::unique_ptr<MetaPack> current_meta;
89  std::unique_ptr<Uptane::MetaBundle> meta_bundle_;
90 };
91 
92 } // namespace Primary
93 
94 #endif // PRIMARY_MANAGEDSECONDARY_H_
types.h
data::InstallationResult
Definition: types.h:277
Uptane::HardwareIdentifier
Definition: types.h:315
Primary::SecondaryConfig
Definition: secondary_config.h:6
Uptane::InstalledImageInfo
Definition: types.h:306
Uptane::EcuSerial
Definition: types.h:346
Primary::ManagedSecondaryConfig
Definition: managedsecondary.h:19
PublicKey
Definition: types.h:119
Primary::ManagedSecondary
Definition: managedsecondary.h:42
Uptane::Target
Definition: types.h:379
Uptane::Manifest
Definition: types.h:448
SecondaryInterface
Definition: secondaryinterface.h:9