Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
helpers.cc
1 #include "helpers.h"
2 
3 #include <boost/uuid/uuid_generators.hpp>
4 #include <boost/uuid/uuid_io.hpp>
5 
6 #include "package_manager/ostreemanager.h"
7 
8 static void finalizeIfNeeded(INvStorage &storage, PackageConfig &config) {
9  boost::optional<Uptane::Target> pending_version;
10  storage.loadInstalledVersions("", nullptr, &pending_version);
11 
12  if (!!pending_version) {
13  GObjectUniquePtr<OstreeSysroot> sysroot_smart = OstreeManager::LoadSysroot(config.sysroot);
14  OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment(sysroot_smart.get());
15  if (booted_deployment == nullptr) {
16  throw std::runtime_error("Could not get booted deployment in " + config.sysroot.string());
17  }
18  std::string current_hash = ostree_deployment_get_csum(booted_deployment);
19 
20  const Uptane::Target &target = *pending_version;
21  if (current_hash == target.sha256Hash()) {
22  LOG_INFO << "Marking target install complete for: " << target;
23  storage.saveInstalledVersion("", target, InstalledVersionUpdateMode::kCurrent);
24  }
25  }
26 }
27 
28 LiteClient::LiteClient(Config &config_in) : config(std::move(config_in)) {
29  std::string pkey;
30  storage = INvStorage::newStorage(config.storage);
31  storage->importData(config.import);
32 
33  EcuSerials ecu_serials;
34  if (!storage->loadEcuSerials(&ecu_serials)) {
35  // Set a "random" serial so we don't get warning messages.
36  std::string serial = config.provision.primary_ecu_serial;
37  std::string hwid = config.provision.primary_ecu_hardware_id;
38  if (hwid.empty()) {
39  hwid = Utils::getHostname();
40  }
41  if (serial.empty()) {
42  boost::uuids::uuid tmp = boost::uuids::random_generator()();
43  serial = boost::uuids::to_string(tmp);
44  }
45  ecu_serials.emplace_back(Uptane::EcuSerial(serial), Uptane::HardwareIdentifier(hwid));
46  storage->storeEcuSerials(ecu_serials);
47  }
48 
49  auto http_client = std::make_shared<HttpClient>();
50 
51  KeyManager keys(storage, config.keymanagerConfig());
52  keys.copyCertsToCurl(*http_client);
53 
54  primary = std::make_shared<SotaUptaneClient>(config, storage, http_client);
55  finalizeIfNeeded(*storage, config.pacman);
56 }
KeyManager
Definition: keymanager.h:13
Uptane::HardwareIdentifier
Definition: tuf.h:143
Config
Configuration object for an aktualizr instance running on a primary ECU.
Definition: config.h:73
Uptane::EcuSerial
Definition: tuf.h:174
PackageConfig
Definition: packagemanagerconfig.h:13
Uptane::Target
Definition: tuf.h:238
INvStorage
Definition: invstorage.h:109