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 saveSecondaryInfo(const Uptane::EcuSerial& ecu_serial, const std::string& sec_type,
31  const PublicKey& public_key) override;
32  void saveSecondaryData(const Uptane::EcuSerial& ecu_serial, const std::string& data) override;
33  bool loadSecondaryInfo(const Uptane::EcuSerial& ecu_serial, SecondaryInfo* secondary) override;
34  bool loadSecondariesInfo(std::vector<SecondaryInfo>* secondaries) override;
35 
36  void storeTlsCreds(const std::string& ca, const std::string& cert, const std::string& pkey) override;
37  void storeTlsCa(const std::string& ca) override;
38  void storeTlsCert(const std::string& cert) override;
39  void storeTlsPkey(const std::string& pkey) override;
40  bool loadTlsCreds(std::string* ca, std::string* cert, std::string* pkey) override;
41  void clearTlsCreds() override;
42  bool loadTlsCa(std::string* ca) override;
43  bool loadTlsCert(std::string* cert) override;
44  bool loadTlsPkey(std::string* pkey) override;
45 
46  void storeRoot(const std::string& data, Uptane::RepositoryType repo, Uptane::Version version) override;
47  bool loadRoot(std::string* data, Uptane::RepositoryType repo, Uptane::Version version) override;
48  void storeNonRoot(const std::string& data, Uptane::RepositoryType repo, Uptane::Role role) override;
49  bool loadNonRoot(std::string* data, Uptane::RepositoryType repo, Uptane::Role role) override;
50  void clearNonRootMeta(Uptane::RepositoryType repo) override;
51  void clearMetadata() override;
52  void storeDelegation(const std::string& data, Uptane::Role role) override;
53  bool loadDelegation(std::string* data, Uptane::Role role) override;
54  bool loadAllDelegations(std::vector<std::pair<Uptane::Role, std::string>>& data) const override;
55  void deleteDelegation(Uptane::Role role) override;
56  void clearDelegations() override;
57 
58  void storeDeviceId(const std::string& device_id) override;
59  bool loadDeviceId(std::string* device_id) override;
60  void clearDeviceId() override;
61  void storeEcuSerials(const EcuSerials& serials) override;
62  bool loadEcuSerials(EcuSerials* serials) override;
63  void clearEcuSerials() override;
64  void storeCachedEcuManifest(const Uptane::EcuSerial& ecu_serial, const std::string& manifest) override;
65  bool loadCachedEcuManifest(const Uptane::EcuSerial& ecu_serial, std::string* manifest) override;
66  void storeMisconfiguredEcus(const std::vector<MisconfiguredEcu>& ecus) override;
67  bool loadMisconfiguredEcus(std::vector<MisconfiguredEcu>* ecus) override;
68  void clearMisconfiguredEcus() override;
69  void storeEcuRegistered() override;
70  bool loadEcuRegistered() override;
71  void clearEcuRegistered() override;
72  void storeNeedReboot() override;
73  bool loadNeedReboot(bool* need_reboot) override;
74  void clearNeedReboot() override;
75  void saveInstalledVersion(const std::string& ecu_serial, const Uptane::Target& target,
76  InstalledVersionUpdateMode update_mode) override;
77  bool loadInstalledVersions(const std::string& ecu_serial, boost::optional<Uptane::Target>* current_version,
78  boost::optional<Uptane::Target>* pending_version) override;
79  bool loadInstallationLog(const std::string& ecu_serial, std::vector<Uptane::Target>* log,
80  bool only_installed) override;
81  bool hasPendingInstall() override;
82  void getPendingEcus(std::vector<std::pair<Uptane::EcuSerial, Uptane::Hash>>* pendingEcus) override;
83  void clearInstalledVersions() override;
84 
85  void saveEcuInstallationResult(const Uptane::EcuSerial& ecu_serial, const data::InstallationResult& result) override;
86  bool loadEcuInstallationResults(
87  std::vector<std::pair<Uptane::EcuSerial, data::InstallationResult>>* results) override;
88  void storeDeviceInstallationResult(const data::InstallationResult& result, const std::string& raw_report,
89  const std::string& correlation_id) override;
90  bool loadDeviceInstallationResult(data::InstallationResult* result, std::string* raw_report,
91  std::string* correlation_id) override;
92  void saveEcuReportCounter(const Uptane::EcuSerial& ecu_serial, int64_t counter) override;
93  bool loadEcuReportCounter(std::vector<std::pair<Uptane::EcuSerial, int64_t>>* results) override;
94  void clearInstallationResults() override;
95 
96  bool checkAvailableDiskSpace(uint64_t required_bytes) const override;
97 
98  std::unique_ptr<StorageTargetWHandle> allocateTargetFile(const Uptane::Target& target) override;
99  std::unique_ptr<StorageTargetRHandle> openTargetFile(const Uptane::Target& target) override;
100  boost::optional<std::pair<uintmax_t, std::string>> checkTargetFile(const Uptane::Target& target) const override;
101  std::vector<Uptane::Target> getTargetFiles() override;
102  void removeTargetFile(const std::string& target_name) override;
103  void cleanUp() override;
104  StorageType type() override { return StorageType::kSqlite; };
105 
106  private:
107  boost::filesystem::path images_path_{sqldb_path_.parent_path() / "images"};
108 
109  void cleanMetaVersion(Uptane::RepositoryType repo, const Uptane::Role& role);
110 };
111 
112 #endif // SQLSTORAGE_H_
data::InstallationResult
Definition: types.h:182
Uptane::Version
Metadata version numbers.
Definition: tuf.h:116
StorageConfig
Definition: storage_config.h:15
data
General data structures.
Definition: types.cc:54
Uptane::RepositoryType
Definition: tuf.h:20
Uptane::EcuSerial
Definition: tuf.h:174
SecondaryInfo
Definition: invstorage.h:106
PublicKey
Definition: crypto.h:26
SQLTargetRHandle
Definition: sqlstorage.cc:1795
result
Results of libaktualizr API calls.
Definition: results.h:13
SQLTargetWHandle
Definition: sqlstorage.cc:1700
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:126