Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
packagemanagerinterface.h
1 #ifndef PACKAGEMANAGERINTERFACE_H_
2 #define PACKAGEMANAGERINTERFACE_H_
3 
4 #include <mutex>
5 #include <string>
6 
7 #include "bootloader/bootloader.h"
8 #include "crypto/keymanager.h"
9 #include "http/httpinterface.h"
10 #include "packagemanagerconfig.h"
11 #include "storage/invstorage.h"
12 #include "uptane/fetcher.h"
13 #include "utilities/apiqueue.h"
14 #include "utilities/types.h"
15 
16 using FetcherProgressCb = std::function<void(const Uptane::Target&, const std::string&, unsigned int)>;
17 
18 /**
19  * Status of downloaded target.
20  */
21 enum class TargetStatus {
22  /* Target has been downloaded and verified. */
23  kGood = 0,
24  /* Target was not found. */
25  kNotFound,
26  /* Target was found, but is incomplete. */
27  kIncomplete,
28  /* Target was found, but is larger than expected. */
29  kOversized,
30  /* Target was found, but hash did not match the metadata. */
31  kHashMismatch,
32  /* Target was found and has valid metadata but the content is not suitable for the packagemanager */
33  kInvalid,
34 };
35 
37  public:
38  PackageManagerInterface(PackageConfig pconfig, BootloaderConfig bconfig, std::shared_ptr<INvStorage> storage,
39  std::shared_ptr<HttpInterface> http)
40  : config(std::move(pconfig)),
41  storage_(std::move(storage)),
42  http_(std::move(http)),
43  bootloader_{new Bootloader(std::move(bconfig), *storage_)} {}
44  virtual ~PackageManagerInterface() = default;
45  virtual std::string name() const = 0;
46  virtual Json::Value getInstalledPackages() const = 0;
47  virtual Uptane::Target getCurrent() const = 0;
48  virtual data::InstallationResult install(const Uptane::Target& target) const = 0;
49  virtual void completeInstall() const { throw std::runtime_error("Unimplemented"); };
50  virtual data::InstallationResult finalizeInstall(const Uptane::Target& target) const = 0;
51  virtual bool rebootDetected() { return bootloader_->rebootDetected(); };
52  virtual void rebootFlagClear() { bootloader_->rebootFlagClear(); };
53  virtual void updateNotify() { bootloader_->updateNotify(); };
54  virtual bool fetchTarget(const Uptane::Target& target, Uptane::Fetcher& fetcher, const KeyManager& keys,
55  FetcherProgressCb progress_cb, const api::FlowControlToken* token);
56  virtual TargetStatus verifyTarget(const Uptane::Target& target) const;
57 
58  // only returns the version
59  Json::Value getManifest(const Uptane::EcuSerial& ecu_serial) const {
60  Uptane::Target installed_target = getCurrent();
61  Json::Value installed_image;
62  installed_image["filepath"] = installed_target.filename();
63  installed_image["fileinfo"]["length"] = Json::UInt64(installed_target.length());
64  installed_image["fileinfo"]["hashes"]["sha256"] = installed_target.sha256Hash();
65 
66  Json::Value unsigned_ecu_version;
67  unsigned_ecu_version["attacks_detected"] = "";
68  unsigned_ecu_version["installed_image"] = installed_image;
69  unsigned_ecu_version["ecu_serial"] = ecu_serial.ToString();
70  unsigned_ecu_version["previous_timeserver_time"] = "1970-01-01T00:00:00Z";
71  unsigned_ecu_version["timeserver_time"] = "1970-01-01T00:00:00Z";
72  return unsigned_ecu_version;
73  }
74 
75  protected:
76  PackageConfig config;
77  std::shared_ptr<INvStorage> storage_;
78  std::shared_ptr<HttpInterface> http_;
79  std::unique_ptr<Bootloader> bootloader_;
80 };
81 #endif // PACKAGEMANAGERINTERFACE_H_
Uptane::Fetcher
Definition: fetcher.h:33
PackageManagerInterface
Definition: packagemanagerinterface.h:36
KeyManager
Definition: keymanager.h:13
types.h
data::InstallationResult
Definition: types.h:179
Bootloader
Definition: bootloader.h:8
Uptane::EcuSerial
Definition: tuf.h:174
api::FlowControlToken
Provides a thread-safe way to pause and terminate task execution.
Definition: apiqueue.h:19
PackageConfig
Definition: packagemanagerconfig.h:13
Uptane::Target
Definition: tuf.h:238
BootloaderConfig
Definition: bootloader_config.h:11