Aktualizr
C++ SOTA Client
config.h
1 #ifndef CONFIG_H_
2 #define CONFIG_H_
3 
4 #include <algorithm>
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 
9 #include <boost/filesystem.hpp>
10 #include <boost/program_options.hpp>
11 #include <boost/property_tree/ini_parser.hpp>
12 #include <boost/uuid/uuid.hpp> // uuid class
13 #include <boost/uuid/uuid_generators.hpp> // generators
14 #include <boost/uuid/uuid_io.hpp>
15 
16 #include "asn1/asn1-cerstream.h"
17 #include "bootloader/bootloader.h"
18 #include "crypto/keymanager_config.h"
19 #include "crypto/p11_config.h"
20 #include "logging/logging_config.h"
21 #include "package_manager/packagemanagerconfig.h"
22 #include "storage/storage_config.h"
23 #include "telemetry/telemetryconfig.h"
24 #include "uptane/secondaryconfig.h"
25 #include "utilities/config_utils.h"
26 #include "utilities/types.h"
27 
28 enum class ProvisionMode { kAutomatic = 0, kImplicit };
29 
30 // Try to keep the order of config options the same as in Config::writeToStream()
31 // and Config::updateFromPropertyTree() in config.cc.
32 
33 struct NetworkConfig {
34  std::string ipdiscovery_host{"127.0.0.1"};
35  in_port_t ipdiscovery_port{9031};
36  uint32_t ipdiscovery_wait_seconds{2};
37  in_port_t ipuptane_port{9030};
38 
39  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
40  void writeToStream(std::ostream& out_stream) const;
41 };
42 
43 struct TlsConfig {
44  std::string server;
45  boost::filesystem::path server_url_path;
46  CryptoSource ca_source{CryptoSource::kFile};
47  CryptoSource pkey_source{CryptoSource::kFile};
48  CryptoSource cert_source{CryptoSource::kFile};
49 
50  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
51  void writeToStream(std::ostream& out_stream) const;
52 };
53 
54 asn1::Serializer& operator<<(asn1::Serializer& ser, const TlsConfig& tls_conf);
55 asn1::Deserializer& operator>>(asn1::Deserializer& des, TlsConfig& tls_conf);
56 
58  std::string server;
59  std::string p12_password;
60  std::string expiry_days{"36000"};
61  boost::filesystem::path provision_path;
62  ProvisionMode mode{ProvisionMode::kAutomatic};
63  std::string device_id;
64  std::string primary_ecu_serial;
65  std::string primary_ecu_hardware_id;
66  std::string ecu_registration_endpoint;
67 
68  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
69  void writeToStream(std::ostream& out_stream) const;
70 };
71 
72 struct UptaneConfig {
73  RunningMode running_mode{RunningMode::kFull};
74  uint64_t polling_sec{10u};
75  std::string director_server;
76  std::string repo_server;
77  CryptoSource key_source{CryptoSource::kFile};
78  KeyType key_type{KeyType::kRSA2048};
79  boost::filesystem::path legacy_interface{};
80  std::vector<Uptane::SecondaryConfig> secondary_configs{};
81 
82  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
83  void writeToStream(std::ostream& out_stream) const;
84 };
85 
87  bool ipuptane{false};
88 
89  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
90  void writeToStream(std::ostream& out_stream) const;
91 };
92 
93 /**
94  * Configuration object for an aktualizr instance running on a primary ECU.
95  *
96  * This class is a parent to a series of smaller configuration objects for
97  * specific subsystems. Note that most other aktualizr-related tools have their
98  * own parent configuration objects with a reduced set of members.
99  */
100 class Config : public BaseConfig {
101  public:
102  Config();
103  explicit Config(const boost::program_options::variables_map& cmd);
104  explicit Config(const boost::filesystem::path& filename);
105  explicit Config(const std::vector<boost::filesystem::path>& config_dirs);
106 
107  KeyManagerConfig keymanagerConfig() const;
108 
109  void updateFromTomlString(const std::string& contents);
110  void postUpdateValues();
111  void writeToStream(std::ostream& sink) const;
112 
113  // Config data structures. Keep logger first so that it is taken into account
114  // while processing the others.
115  LoggerConfig logger;
116  NetworkConfig network;
117  P11Config p11;
118  TlsConfig tls;
119  ProvisionConfig provision;
120  UptaneConfig uptane;
121  DiscoveryConfig discovery;
122  PackageConfig pacman;
123  StorageConfig storage;
124  ImportConfig import;
125  TelemetryConfig telemetry;
126  BootloaderConfig bootloader;
127 
128  private:
129  void updateFromPropertyTree(const boost::property_tree::ptree& pt) override;
130  void updateFromCommandLine(const boost::program_options::variables_map& cmd);
131  void readSecondaryConfigs(const std::vector<boost::filesystem::path>& sconfigs);
132  void checkLegacyVersion();
133  void initLegacySecondaries();
134 
135  std::vector<boost::filesystem::path> config_dirs_ = {"/usr/lib/sota/conf.d", "/etc/sota/conf.d/"};
136  bool loglevel_from_cmdline{false};
137 };
138 
139 #endif // CONFIG_H_
Fully automated mode.
RunningMode
Execution mode to run aktualizr in.
Definition: types.h:62
Configuration object for an aktualizr instance running on a primary ECU.
Definition: config.h:100