9 #include <boost/filesystem.hpp>
10 #include <boost/optional.hpp>
12 #include "libaktualizr/config.h"
13 #include "storage_exception.h"
14 #include "uptane/tuf.h"
20 using store_data_t = void (
INvStorage::*)(
const std::string&);
21 using load_data_t = bool (
INvStorage::*)(std::string*)
const;
23 typedef std::vector<std::pair<Uptane::EcuSerial, Uptane::HardwareIdentifier>> EcuSerials;
27 enum class EcuState { kOld = 0, kUnused };
31 : serial(std::move(serial_in)), hardware_id(std::move(hardware_id_in)), state(state_in) {}
37 enum class InstalledVersionUpdateMode { kNone, kCurrent, kPending };
47 virtual StorageType type() = 0;
48 virtual void storePrimaryKeys(
const std::string& public_key,
const std::string& private_key) = 0;
49 virtual bool loadPrimaryKeys(std::string* public_key, std::string* private_key)
const = 0;
50 virtual bool loadPrimaryPublic(std::string* public_key)
const = 0;
51 virtual bool loadPrimaryPrivate(std::string* private_key)
const = 0;
52 virtual void clearPrimaryKeys() = 0;
54 virtual void saveSecondaryInfo(
const Uptane::EcuSerial& ecu_serial,
const std::string& sec_type,
58 virtual bool loadSecondariesInfo(std::vector<SecondaryInfo>* secondaries)
const = 0;
60 virtual void storeTlsCreds(
const std::string& ca,
const std::string& cert,
const std::string& pkey) = 0;
61 virtual void storeTlsCa(
const std::string& ca) = 0;
62 virtual void storeTlsCert(
const std::string& cert) = 0;
63 virtual void storeTlsPkey(
const std::string& pkey) = 0;
64 virtual bool loadTlsCreds(std::string* ca, std::string* cert, std::string* pkey)
const = 0;
65 virtual bool loadTlsCa(std::string* ca)
const = 0;
66 virtual bool loadTlsCert(std::string* cert)
const = 0;
67 virtual bool loadTlsPkey(std::string* cert)
const = 0;
68 virtual void clearTlsCreds() = 0;
78 virtual void clearMetadata() = 0;
79 virtual void storeDelegation(
const std::string&
data,
Uptane::Role role) = 0;
81 virtual bool loadAllDelegations(std::vector<std::pair<Uptane::Role, std::string>>&
data)
const = 0;
83 virtual void clearDelegations() = 0;
85 virtual void storeDeviceId(
const std::string& device_id) = 0;
86 virtual bool loadDeviceId(std::string* device_id)
const = 0;
87 virtual void clearDeviceId() = 0;
89 virtual void storeEcuSerials(
const EcuSerials& serials) = 0;
90 virtual bool loadEcuSerials(EcuSerials* serials)
const = 0;
91 virtual void clearEcuSerials() = 0;
93 virtual void storeCachedEcuManifest(
const Uptane::EcuSerial& ecu_serial,
const std::string& manifest) = 0;
94 virtual bool loadCachedEcuManifest(
const Uptane::EcuSerial& ecu_serial, std::string* manifest)
const = 0;
97 virtual bool loadMisconfiguredEcus(std::vector<MisconfiguredEcu>* ecus)
const = 0;
98 virtual void clearMisconfiguredEcus() = 0;
100 virtual void storeEcuRegistered() = 0;
101 virtual bool loadEcuRegistered()
const = 0;
102 virtual void clearEcuRegistered() = 0;
104 virtual void storeNeedReboot() = 0;
105 virtual bool loadNeedReboot(
bool* need_reboot)
const = 0;
106 virtual void clearNeedReboot() = 0;
108 virtual void saveInstalledVersion(
const std::string& ecu_serial,
const Uptane::Target& target,
109 InstalledVersionUpdateMode update_mode) = 0;
110 virtual bool loadInstalledVersions(
const std::string& ecu_serial, boost::optional<Uptane::Target>* current_version,
111 boost::optional<Uptane::Target>* pending_version)
const = 0;
112 virtual bool loadInstallationLog(
const std::string& ecu_serial, std::vector<Uptane::Target>* log,
113 bool only_installed)
const = 0;
114 virtual bool hasPendingInstall() = 0;
115 virtual void getPendingEcus(std::vector<std::pair<Uptane::EcuSerial, Hash>>* pendingEcus) = 0;
116 virtual void clearInstalledVersions() = 0;
120 virtual bool loadEcuInstallationResults(
121 std::vector<std::pair<Uptane::EcuSerial, data::InstallationResult>>* results)
const = 0;
123 const std::string& correlation_id) = 0;
124 virtual bool storeDeviceInstallationRawReport(
const std::string& raw_report) = 0;
126 std::string* correlation_id)
const = 0;
127 virtual void clearInstallationResults() = 0;
129 virtual void saveEcuReportCounter(
const Uptane::EcuSerial& ecu_serial, int64_t counter) = 0;
130 virtual bool loadEcuReportCounter(std::vector<std::pair<Uptane::EcuSerial, int64_t>>* results)
const = 0;
132 virtual void saveReportEvent(
const Json::Value& json_value) = 0;
133 virtual bool loadReportEvents(Json::Value* report_array, int64_t* id_max)
const = 0;
134 virtual void deleteReportEvents(int64_t id_max) = 0;
136 virtual void storeDeviceDataHash(
const std::string& data_type,
const std::string& hash) = 0;
137 virtual bool loadDeviceDataHash(
const std::string& data_type, std::string* hash)
const = 0;
138 virtual void clearDeviceData() = 0;
141 virtual void storeTargetFilename(
const std::string& targetname,
const std::string& filename)
const = 0;
142 virtual std::string getTargetFilename(
const std::string& targetname)
const = 0;
143 virtual std::vector<std::string> getAllTargetNames()
const = 0;
144 virtual void deleteTargetInfo(
const std::string& targetname)
const = 0;
146 virtual void cleanUp() = 0;
149 static std::shared_ptr<INvStorage> newStorage(
const StorageConfig& config,
bool readonly =
false);
151 static bool fsReadInstalledVersions(
const boost::filesystem::path& filename,
152 std::vector<Uptane::Target>* installed_versions,
size_t* current_version);
156 bool loadPrimaryInstalledVersions(boost::optional<Uptane::Target>* current_version,
157 boost::optional<Uptane::Target>* pending_version)
const {
158 return loadInstalledVersions(
"", current_version, pending_version);
160 void savePrimaryInstalledVersion(
const Uptane::Target& target, InstalledVersionUpdateMode update_mode) {
161 return saveInstalledVersion(
"", target, update_mode);
163 bool loadPrimaryInstallationLog(std::vector<Uptane::Target>* log,
bool only_installed)
const {
164 return loadInstallationLog(
"", log, only_installed);
166 void importInstalledVersions(
const boost::filesystem::path& base_path);
169 void importSimple(
const boost::filesystem::path& base_path, store_data_t store_func, load_data_t load_func,
171 void importUpdateSimple(
const boost::filesystem::path& base_path, store_data_t store_func, load_data_t load_func,
173 void importUpdateCertificate(
const boost::filesystem::path& base_path,
const utils::BasedPath& imported_data_path);
174 void importPrimaryKeys(
const boost::filesystem::path& base_path,
const utils::BasedPath& import_pubkey_path,
181 #endif // INVSTORAGE_H_