Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
sqlstorage.h
1 #ifndef SQLSTORAGE_H_
2 #define SQLSTORAGE_H_
3 
4 #include <boost/filesystem.hpp>
5 #include <boost/optional.hpp>
6 
7 #include <sqlite3.h>
8 
9 #include "invstorage.h"
10 #include "sqlstorage_base.h"
11 
12 extern const std::vector<std::string> libaktualizr_schema_migrations;
13 extern const std::vector<std::string> libaktualizr_schema_rollback_migrations;
14 extern const std::string libaktualizr_current_schema;
15 extern const int libaktualizr_current_schema_version;
16 
17 class SQLTargetRHandle;
18 class SQLStorage : public SQLStorageBase, public INvStorage {
19  public:
20  friend class SQLTargetWHandle;
21  friend class SQLTargetRHandle;
22  explicit SQLStorage(const StorageConfig& config, bool readonly);
23  ~SQLStorage() override = default;
24  void storePrimaryKeys(const std::string& public_key, const std::string& private_key) override;
25  bool loadPrimaryKeys(std::string* public_key, std::string* private_key) override;
26  bool loadPrimaryPublic(std::string* public_key) override;
27  bool loadPrimaryPrivate(std::string* private_key) override;
28  void clearPrimaryKeys() override;
29 
30  void storeTlsCreds(const std::string& ca, const std::string& cert, const std::string& pkey) override;
31  void storeTlsCa(const std::string& ca) override;
32  void storeTlsCert(const std::string& cert) override;
33  void storeTlsPkey(const std::string& pkey) override;
34  bool loadTlsCreds(std::string* ca, std::string* cert, std::string* pkey) override;
35  void clearTlsCreds() override;
36  bool loadTlsCa(std::string* ca) override;
37  bool loadTlsCert(std::string* cert) override;
38  bool loadTlsPkey(std::string* pkey) override;
39 
40  void storeRoot(const std::string& data, Uptane::RepositoryType repo, Uptane::Version version) override;
41  bool loadRoot(std::string* data, Uptane::RepositoryType repo, Uptane::Version version) override;
42  void storeNonRoot(const std::string& data, Uptane::RepositoryType repo, Uptane::Role role) override;
43  bool loadNonRoot(std::string* data, Uptane::RepositoryType repo, Uptane::Role role) override;
44  void clearNonRootMeta(Uptane::RepositoryType repo) override;
45  void clearMetadata() override;
46  void storeDelegation(const std::string& data, Uptane::Role role) override;
47  bool loadDelegation(std::string* data, Uptane::Role role) override;
48  bool loadAllDelegations(std::vector<std::pair<Uptane::Role, std::string>>& data) const override;
49  void deleteDelegation(Uptane::Role role) override;
50  void clearDelegations() override;
51 
52  void storeDeviceId(const std::string& device_id) override;
53  bool loadDeviceId(std::string* device_id) override;
54  void clearDeviceId() override;
55  void storeEcuSerials(const EcuSerials& serials) override;
56  bool loadEcuSerials(EcuSerials* serials) override;
57  void clearEcuSerials() override;
58  void storeMisconfiguredEcus(const std::vector<MisconfiguredEcu>& ecus) override;
59  bool loadMisconfiguredEcus(std::vector<MisconfiguredEcu>* ecus) override;
60  void clearMisconfiguredEcus() override;
61  void storeEcuRegistered() override;
62  bool loadEcuRegistered() override;
63  void clearEcuRegistered() override;
64  void storeNeedReboot() override;
65  bool loadNeedReboot(bool* need_reboot) override;
66  void clearNeedReboot() override;
67  void saveInstalledVersion(const std::string& ecu_serial, const Uptane::Target& target,
68  InstalledVersionUpdateMode update_mode) override;
69  bool loadInstalledVersions(const std::string& ecu_serial, boost::optional<Uptane::Target>* current_version,
70  boost::optional<Uptane::Target>* pending_version) override;
71  bool loadInstallationLog(const std::string& ecu_serial, std::vector<Uptane::Target>* log,
72  bool only_installed) override;
73  bool hasPendingInstall() override;
74  void getPendingEcus(std::vector<std::pair<Uptane::EcuSerial, Uptane::Hash>>* pendingEcus) override;
75  void clearInstalledVersions() override;
76 
77  void saveEcuInstallationResult(const Uptane::EcuSerial& ecu_serial, const data::InstallationResult& result) override;
78  bool loadEcuInstallationResults(
79  std::vector<std::pair<Uptane::EcuSerial, data::InstallationResult>>* results) override;
80  void storeDeviceInstallationResult(const data::InstallationResult& result, const std::string& raw_report,
81  const std::string& correlation_id) override;
82  bool loadDeviceInstallationResult(data::InstallationResult* result, std::string* raw_report,
83  std::string* correlation_id) override;
84  void saveEcuReportCounter(const Uptane::EcuSerial& ecu_serial, int64_t counter) override;
85  bool loadEcuReportCounter(std::vector<std::pair<Uptane::EcuSerial, int64_t>>* results) override;
86  void clearInstallationResults() override;
87 
88  bool checkAvailableDiskSpace(uint64_t required_bytes) const override;
89 
90  std::unique_ptr<StorageTargetWHandle> allocateTargetFile(bool from_director, const Uptane::Target& target) override;
91  std::unique_ptr<StorageTargetRHandle> openTargetFile(const Uptane::Target& target) override;
92  boost::optional<std::pair<size_t, std::string>> checkTargetFile(const Uptane::Target& target) const override;
93  std::vector<Uptane::Target> getTargetFiles() override;
94  void removeTargetFile(const std::string& target_name) override;
95  void cleanUp() override;
96  StorageType type() override { return StorageType::kSqlite; };
97 
98  private:
99  boost::filesystem::path images_path_{sqldb_path_.parent_path() / "images"};
100 
101  void cleanMetaVersion(Uptane::RepositoryType repo, const Uptane::Role& role);
102 };
103 
104 #endif // SQLSTORAGE_H_
data::InstallationResult
Definition: types.h:179
Uptane::Version
Metadata version numbers.
Definition: tuf.h:116
StorageConfig
Definition: storage_config.h:15
data
General data structures.
Definition: types.cc:44
Uptane::RepositoryType
Definition: tuf.h:20
Uptane::EcuSerial
Definition: tuf.h:174
SQLTargetRHandle
Definition: sqlstorage.cc:1599
result
Results of libaktualizr API calls.
Definition: results.h:13
SQLTargetWHandle
Definition: sqlstorage.cc:1494
Uptane::Role
TUF Roles.
Definition: tuf.h:57
Uptane::Target
Definition: tuf.h:238
SQLStorageBase
Definition: sqlstorage_base.h:33
SQLStorage
Definition: sqlstorage.h:18
INvStorage
Definition: invstorage.h:109