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