Aktualizr
C++ SOTA Client
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) const override;
26  bool loadPrimaryPublic(std::string* public_key) const override;
27  bool loadPrimaryPrivate(std::string* private_key) const 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) const override;
34  bool loadSecondariesInfo(std::vector<SecondaryInfo>* secondaries) const 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) const override;
41  void clearTlsCreds() override;
42  bool loadTlsCa(std::string* ca) const override;
43  bool loadTlsCert(std::string* cert) const override;
44  bool loadTlsPkey(std::string* pkey) const 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) const 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) const 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) const 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) const override;
60  void clearDeviceId() override;
61  void storeEcuSerials(const EcuSerials& serials) override;
62  bool loadEcuSerials(EcuSerials* serials) const 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) const override;
66  void saveMisconfiguredEcu(const MisconfiguredEcu& ecu) override;
67  bool loadMisconfiguredEcus(std::vector<MisconfiguredEcu>* ecus) const override;
68  void clearMisconfiguredEcus() override;
69  void storeEcuRegistered() override;
70  bool loadEcuRegistered() const override;
71  void clearEcuRegistered() override;
72  void storeNeedReboot() override;
73  bool loadNeedReboot(bool* need_reboot) const 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) const override;
79  bool loadInstallationLog(const std::string& ecu_serial, std::vector<Uptane::Target>* log,
80  bool only_installed) const override;
81  bool hasPendingInstall() override;
82  void getPendingEcus(std::vector<std::pair<Uptane::EcuSerial, 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) const override;
88  void storeDeviceInstallationResult(const data::InstallationResult& result, const std::string& raw_report,
89  const std::string& correlation_id) override;
90  bool storeDeviceInstallationRawReport(const std::string& raw_report) override;
91  bool loadDeviceInstallationResult(data::InstallationResult* result, std::string* raw_report,
92  std::string* correlation_id) const override;
93  void saveEcuReportCounter(const Uptane::EcuSerial& ecu_serial, int64_t counter) override;
94  bool loadEcuReportCounter(std::vector<std::pair<Uptane::EcuSerial, int64_t>>* results) const override;
95  void saveReportEvent(const Json::Value& json_value) override;
96  bool loadReportEvents(Json::Value* report_array, int64_t* id_max) const override;
97  void deleteReportEvents(int64_t id_max) override;
98  void clearInstallationResults() override;
99 
100  void storeDeviceDataHash(const std::string& data_type, const std::string& hash) override;
101  bool loadDeviceDataHash(const std::string& data_type, std::string* hash) const override;
102  void clearDeviceData() override;
103 
104  void storeTargetFilename(const std::string& targetname, const std::string& filename) const override;
105  std::string getTargetFilename(const std::string& targetname) const override;
106  std::vector<std::string> getAllTargetNames() const override;
107  void deleteTargetInfo(const std::string& targetname) const override;
108 
109  void cleanUp() override;
110  StorageType type() override { return StorageType::kSqlite; };
111 
112  private:
113  void cleanMetaVersion(Uptane::RepositoryType repo, const Uptane::Role& role);
114 };
115 
116 #endif // SQLSTORAGE_H_
data::InstallationResult
Definition: types.h:277
Uptane::Version
Metadata version numbers.
Definition: tuf.h:120
StorageConfig
Definition: config.h:111
MisconfiguredEcu
Definition: invstorage.h:29
data
General data structures.
Definition: types.h:217
Uptane::RepositoryType
Definition: tuf.h:21
Uptane::EcuSerial
Definition: types.h:346
SecondaryInfo
Definition: types.h:462
PublicKey
Definition: types.h:119
result
Results of libaktualizr API calls.
Definition: results.h:12
Uptane::Role
TUF Roles.
Definition: tuf.h:61
Uptane::Target
Definition: types.h:379
SQLStorageBase
Definition: sqlstorage_base.h:33
SQLStorage
Definition: sqlstorage.h:18
INvStorage
Definition: invstorage.h:43