Aktualizr
C++ SOTA Client
managedsecondary.h
1 #ifndef UPTANE_MANAGEDSECONDARY_H_
2 #define UPTANE_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 "uptane/secondaryconfig.h"
12 #include "uptane/secondaryinterface.h"
13 #include "utilities/events.h"
14 #include "utilities/types.h"
15 
16 namespace Uptane {
17 
18 // Managed secondary is an abstraction over virtual and legacy secondaries. Both of them have all the UPTANE-related
19 // functionality implemented in aktualizr itself, so there's some shared code.
20 
22  public:
23  explicit ManagedSecondary(const SecondaryConfig& sconfig_in);
24 
25  EcuSerial getSerial() override {
26  if (!sconfig.ecu_serial.empty()) {
27  return EcuSerial(sconfig.ecu_serial);
28  }
29  return EcuSerial(public_key_.KeyId());
30  }
31  PublicKey getPublicKey() override { return public_key_; }
32  bool putMetadata(const RawMetaPack& meta_pack) override;
33  int getRootVersion(bool director) override;
34  bool putRoot(const std::string& root, bool director) override;
35 
36  bool sendFirmwareAsync(const std::shared_ptr<std::string>& data) override;
37  Json::Value getManifest() override;
38 
39  bool loadKeys(std::string* pub_key, std::string* priv_key);
40 
41  private:
42  PublicKey public_key_;
43  std::string private_key;
44 
45  std::string detected_attack;
46  std::string expected_target_name;
47  std::vector<Hash> expected_target_hashes;
48  int64_t expected_target_length{};
49 
50  MetaPack current_meta;
51  RawMetaPack current_raw_meta;
52  std::future<bool> install_future;
53 
54  virtual bool storeFirmware(const std::string& target_name, const std::string& content) = 0;
55  virtual bool getFirmwareInfo(std::string* target_name, size_t& target_len, std::string* sha256hash) = 0;
56 
57  void storeKeys(const std::string& pub_key, const std::string& priv_key);
58  void rawToMeta();
59 
60  // TODO: implement
61  void storeMetadata(const RawMetaPack& meta_pack) { (void)meta_pack; }
62  bool loadMetadata(RawMetaPack* meta_pack);
63  bool sendFirmware(const std::shared_ptr<std::string>& data);
64 };
65 } // namespace Uptane
66 
67 #endif // UPTANE_MANAGEDSECONDARY_H_
General data structures.
Definition: types.cc:6
Base data types that are used in The Update Framework (TUF), part of UPTANE.