Aktualizr
C++ SOTA Client
secondaryconfig.h
1 #ifndef UPTANE_SECONDARYCONFIG_H_
2 #define UPTANE_SECONDARYCONFIG_H_
3 
4 #include <string>
5 
6 #include <sys/socket.h>
7 #include <boost/filesystem.hpp>
8 #include "utilities/exceptions.h"
9 #include "utilities/types.h"
10 #include "utilities/utils.h"
11 
12 namespace Uptane {
13 
14 enum class SecondaryType {
15 
16  kVirtual, // Virtual secondary (in-process fake implementation).
17 
18  kLegacy, // legacy non-UPTANE secondary. All the UPTANE metadata is managed locally. All commands are sent to an
19  // external firmware loader via shell.
20 
21  kOpcuaUptane, // Uptane protocol over OPC-UA
22 
23  kIpUptane, // Custom Uptane protocol over TCP/IP network
24 
25  kVirtualUptane, // Partial UPTANE secondary implemented inside primary
26 };
27 
29  public:
30  SecondaryConfig() = default;
31  SecondaryConfig(const boost::filesystem::path &config_file) {
32  if (!boost::filesystem::exists(config_file)) {
33  throw FatalException(config_file.string() + " does not exist!");
34  }
35  Json::Value config_json = Utils::parseJSONFile(config_file);
36 
37  std::string stype = config_json["secondary_type"].asString();
38  if (stype == "virtual") {
39  secondary_type = Uptane::SecondaryType::kVirtual;
40  } else if (stype == "legacy") {
41  throw FatalException("Legacy secondaries should be initialized with --legacy-interface.");
42  } else if (stype == "ip_uptane") {
43  secondary_type = Uptane::SecondaryType::kIpUptane;
44  } else if (stype == "opcua_uptane") {
45  secondary_type = Uptane::SecondaryType::kOpcuaUptane;
46  } else {
47  throw FatalException(std::string("Unrecognized secondary type: ") + stype);
48  }
49  ecu_serial = config_json["ecu_serial"].asString();
50  ecu_hardware_id = config_json["ecu_hardware_id"].asString();
51  partial_verifying = config_json["partial_verifying"].asBool();
52  ecu_private_key = config_json["ecu_private_key"].asString();
53  ecu_public_key = config_json["ecu_public_key"].asString();
54 
55  full_client_dir = boost::filesystem::path(config_json["full_client_dir"].asString());
56  firmware_path = boost::filesystem::path(config_json["firmware_path"].asString());
57  metadata_path = boost::filesystem::path(config_json["metadata_path"].asString());
58  target_name_path = boost::filesystem::path(config_json["target_name_path"].asString());
59  flasher = "";
60 
61  std::string key_type_str = config_json["key_type"].asString();
62  if (key_type_str.size() != 0u) {
63  if (key_type_str == "RSA2048") {
64  key_type = KeyType::kRSA2048;
65  } else if (key_type_str == "RSA3072") {
66  key_type = KeyType::kRSA3072;
67  } else if (key_type_str == "RSA4096") {
68  key_type = KeyType::kRSA4096;
69  } else if (key_type_str == "ED25519") {
70  key_type = KeyType::kED25519;
71  }
72  }
73  }
74  SecondaryType secondary_type{};
75  std::string ecu_serial;
76  std::string ecu_hardware_id;
77  bool partial_verifying{};
78  std::string ecu_private_key;
79  std::string ecu_public_key;
80  KeyType key_type{KeyType::kRSA2048};
81 
82  std::string opcua_lds_url;
83 
84  boost::filesystem::path full_client_dir; // SecondaryType::kVirtual, SecondaryType::kLegacy
85  boost::filesystem::path firmware_path; // SecondaryType::kVirtual, SecondaryType::kLegacy
86  boost::filesystem::path metadata_path; // SecondaryType::kVirtual, SecondaryType::kLegacy
87  boost::filesystem::path target_name_path; // SecondaryType::kVirtual, SecondaryType::kLegacy
88 
89  boost::filesystem::path flasher; // SecondaryType::kLegacy
90 
91  sockaddr_storage ip_addr{}; // SecondaryType::kIpUptane
92 };
93 } // namespace Uptane
94 
95 #endif
Base data types that are used in The Update Framework (TUF), part of UPTANE.