1 #ifndef SOTA_UPTANE_CLIENT_H_ 2 #define SOTA_UPTANE_CLIENT_H_ 10 #include <boost/signals2.hpp> 11 #include "gtest/gtest_prod.h" 12 #include "json/json.h" 14 #include "bootloader/bootloader.h" 15 #include "campaign/campaign.h" 16 #include "config/config.h" 17 #include "http/httpclient.h" 18 #include "package_manager/packagemanagerfactory.h" 19 #include "package_manager/packagemanagerinterface.h" 22 #include "reportqueue.h" 23 #include "storage/invstorage.h" 24 #include "uptane/directorrepository.h" 25 #include "uptane/exceptions.h" 26 #include "uptane/fetcher.h" 27 #include "uptane/imagerepository.h" 28 #include "uptane/iterator.h" 29 #include "uptane/secondaryinterface.h" 33 SotaUptaneClient(
Config &config_in, std::shared_ptr<INvStorage> storage_in, std::shared_ptr<HttpInterface> http_in,
34 std::shared_ptr<event::Channel> events_channel_in,
38 storage(std::move(storage_in)),
39 http(std::move(http_in)),
40 package_manager_(PackageManagerFactory::makePackageManager(config.pacman, config.bootloader, storage, http)),
42 events_channel(std::move(events_channel_in)),
43 primary_ecu_serial_(primary_serial),
44 primary_ecu_hw_id_(hwid) {
45 report_queue = std_::make_unique<ReportQueue>(config, http, storage);
49 std::shared_ptr<HttpInterface> http_in)
50 : SotaUptaneClient(config_in, storage_in, std::move(http_in),
nullptr) {}
52 SotaUptaneClient(
Config &config_in,
const std::shared_ptr<INvStorage> &storage_in)
53 : SotaUptaneClient(config_in, storage_in, std::make_shared<HttpClient>()) {}
56 void addSecondary(
const std::shared_ptr<Uptane::SecondaryInterface> &sec);
59 std::pair<bool, Uptane::Target> downloadImage(
const Uptane::Target &target,
63 void sendDeviceData(
const Json::Value &custom_hwinfo = Json::nullValue);
65 bool putManifest(
const Json::Value &custom = Json::nullValue);
67 result::Install uptaneInstall(
const std::vector<Uptane::Target> &updates);
69 void campaignAccept(
const std::string &campaign_id);
70 void campaignDecline(
const std::string &campaign_id);
71 void campaignPostpone(
const std::string &campaign_id);
73 bool hasPendingUpdates()
const;
74 bool isInstallCompletionRequired()
const;
75 void completeInstall()
const;
77 Uptane::Target getCurrent()
const {
return package_manager_->getCurrent(); }
79 void updateImageMeta();
80 void checkImageMetaOffline();
82 TargetStatus VerifyTarget(
const Uptane::Target &target)
const {
return package_manager_->verifyTarget(target); }
86 FRIEND_TEST(
Aktualizr, DeviceInstallationResult);
87 FRIEND_TEST(
Aktualizr, FullMultipleSecondaries);
89 FRIEND_TEST(
Aktualizr, DownloadWithUpdates);
90 FRIEND_TEST(
Aktualizr, FinalizationFailure);
91 FRIEND_TEST(
Aktualizr, InstallationFailure);
92 FRIEND_TEST(
Aktualizr, AutoRebootAfterUpdate);
95 FRIEND_TEST(
Aktualizr, DownloadNonOstreeBin);
98 FRIEND_TEST(
Uptane, AssembleManifestGood);
99 FRIEND_TEST(
Uptane, AssembleManifestBad);
100 FRIEND_TEST(
Uptane, InstallFakeGood);
101 FRIEND_TEST(
Uptane, restoreVerify);
102 FRIEND_TEST(
Uptane, PutManifest);
103 FRIEND_TEST(
Uptane, offlineIteration);
104 FRIEND_TEST(
Uptane, IgnoreUnknownUpdate);
105 FRIEND_TEST(
Uptane, kRejectAllTest);
106 FRIEND_TEST(UptaneCI, ProvisionAndPutManifest);
107 FRIEND_TEST(UptaneCI, CheckKeys);
108 FRIEND_TEST(UptaneKey, Check);
109 FRIEND_TEST(UptaneNetwork, DownloadFailure);
110 FRIEND_TEST(UptaneNetwork, LogConnectivityRestored);
112 FRIEND_TEST(aktualizr_secondary_uptane, credentialsPassing);
116 void uptaneIteration(std::vector<Uptane::Target> *targets,
unsigned int *ecus_count);
117 void uptaneOfflineIteration(std::vector<Uptane::Target> *targets,
unsigned int *ecus_count);
119 Json::Value AssembleManifest();
120 std::string secondaryTreehubCredentials()
const;
121 std::exception_ptr getLastException()
const {
return last_exception; }
122 static std::vector<Uptane::Target> findForEcu(
const std::vector<Uptane::Target> &targets,
125 void finalizeAfterReboot();
126 void reportHwInfo(
const Json::Value &custom_hwinfo);
127 void reportInstalledPackages();
128 void reportNetworkInfo();
129 void reportAktualizrConfiguration();
130 void verifySecondaries();
131 bool waitSecondariesReachable(
const std::vector<Uptane::Target> &updates);
132 bool sendMetadataToEcus(
const std::vector<Uptane::Target> &targets);
135 std::vector<result::Install::EcuReport> sendImagesToEcus(
const std::vector<Uptane::Target> &targets);
137 bool putManifestSimple(
const Json::Value &custom = Json::nullValue);
139 void getNewTargets(std::vector<Uptane::Target> *new_targets,
unsigned int *ecus_count =
nullptr);
141 void updateDirectorMeta();
142 void checkDirectorMetaOffline();
144 std::unique_ptr<Uptane::Target> findTargetInDelegationTree(
const Uptane::Target &target,
bool offline);
145 std::unique_ptr<Uptane::Target> findTargetHelper(
const Uptane::Targets &cur_targets,
146 const Uptane::Target &queried_target,
int level,
bool terminating,
148 void checkAndUpdatePendingSecondaries();
149 const Uptane::EcuSerial &primaryEcuSerial()
const {
return primary_ecu_serial_; }
150 boost::optional<Uptane::HardwareIdentifier> ecuHwId(
const Uptane::EcuSerial &serial)
const;
152 template <
class T,
class... Args>
153 void sendEvent(Args &&... args) {
154 std::shared_ptr<event::BaseEvent>
event = std::make_shared<T>(std::forward<Args>(args)...);
155 if (events_channel) {
156 (*events_channel)(std::move(
event));
158 LOG_INFO <<
"got " <<
event->variant <<
" event";
165 Uptane::ManifestIssuer::Ptr uptane_manifest;
166 std::shared_ptr<INvStorage> storage;
167 std::shared_ptr<HttpInterface> http;
168 std::shared_ptr<PackageManagerInterface> package_manager_;
169 std::shared_ptr<Uptane::Fetcher> uptane_fetcher;
170 std::unique_ptr<ReportQueue> report_queue;
171 std::shared_ptr<event::Channel> events_channel;
172 boost::signals2::scoped_connection conn;
173 std::exception_ptr last_exception;
175 std::map<Uptane::EcuSerial, Uptane::SecondaryInterface::Ptr> secondaries;
176 std::mutex download_mutex;
184 bool operator()(
const Uptane::Target &in)
const {
return (in.MatchTarget(target)); }
193 bool operator()(
const std::pair<Uptane::EcuSerial, Uptane::HardwareIdentifier> &in)
const {
194 return (in.first == serial);
201 #endif // SOTA_UPTANE_CLIENT_H_
Provides a thread-safe way to pause and terminate task execution.
Container for information about downloading an update.
A report for a download in progress.
Container for information about available campaigns.
UpdateStatus
Status of an update.
Configuration object for an aktualizr instance running on a Primary ECU.
Container for information about installing an update.
Container for information about available updates.
Results of libaktualizr API calls.
Base data types that are used in The Update Framework (TUF), part of Uptane.
This class provides the main APIs necessary for launching and controlling libaktualizr.