1 #include <boost/algorithm/hex.hpp>
2 #include <boost/filesystem.hpp>
5 #include "crypto/crypto.h"
6 #include "utilities/fault_injection.h"
7 #include "utilities/utils.h"
8 #include "virtualsecondary.h"
12 const char*
const VirtualSecondaryConfig::Type =
"virtual";
14 VirtualSecondaryConfig::VirtualSecondaryConfig(
const Json::Value& json_config) : ManagedSecondaryConfig(Type) {
15 partial_verifying = json_config[
"partial_verifying"].asBool();
16 ecu_serial = json_config[
"ecu_serial"].asString();
17 ecu_hardware_id = json_config[
"ecu_hardware_id"].asString();
18 full_client_dir = json_config[
"full_client_dir"].asString();
19 ecu_private_key = json_config[
"ecu_private_key"].asString();
20 ecu_public_key = json_config[
"ecu_public_key"].asString();
21 firmware_path = json_config[
"firmware_path"].asString();
22 target_name_path = json_config[
"target_name_path"].asString();
23 metadata_path = json_config[
"metadata_path"].asString();
26 std::vector<VirtualSecondaryConfig> VirtualSecondaryConfig::create_from_file(
27 const boost::filesystem::path& file_full_path) {
28 Json::Value json_config;
29 std::ifstream json_file(file_full_path.string());
30 Json::parseFromStream(Json::CharReaderBuilder(), json_file, &json_config,
nullptr);
33 std::vector<VirtualSecondaryConfig> sec_configs;
34 sec_configs.reserve(json_config[Type].size());
36 for (
const auto& item : json_config[Type]) {
37 sec_configs.emplace_back(VirtualSecondaryConfig(item));
42 void VirtualSecondaryConfig::dump(
const boost::filesystem::path& file_full_path)
const {
43 Json::Value json_config;
45 json_config[
"partial_verifying"] = partial_verifying;
46 json_config[
"ecu_serial"] = ecu_serial;
47 json_config[
"ecu_hardware_id"] = ecu_hardware_id;
48 json_config[
"full_client_dir"] = full_client_dir.string();
49 json_config[
"ecu_private_key"] = ecu_private_key;
50 json_config[
"ecu_public_key"] = ecu_public_key;
51 json_config[
"firmware_path"] = firmware_path.string();
52 json_config[
"target_name_path"] = target_name_path.string();
53 json_config[
"metadata_path"] = metadata_path.string();
57 if (boost::filesystem::exists(file_full_path)) {
58 root = Utils::parseJSONFile(file_full_path);
60 root[Type].append(json_config);
62 Json::StreamWriterBuilder json_bwriter;
63 json_bwriter[
"indentation"] =
"\t";
64 std::unique_ptr<Json::StreamWriter>
const json_writer(json_bwriter.newStreamWriter());
66 boost::filesystem::create_directories(file_full_path.parent_path());
67 std::ofstream json_file(file_full_path.string());
68 json_writer->write(root, &json_file);
73 : ManagedSecondary(std::move(sconfig_in)) {}
76 if (fiu_fail(
"secondary_putmetadata") != 0) {
80 return ManagedSecondary::putMetadata(target);
85 if (fiu_fail(
"secondary_putroot") != 0) {
89 return ManagedSecondary::putRoot(root, director);
93 if (fiu_fail((std::string(
"secondary_sendfirmware_") + getSerial().ToString()).c_str()) != 0) {
100 return ManagedSecondary::sendFirmware(target);
104 if (fiu_fail((std::string(
"secondary_install_") + getSerial().ToString()).c_str()) != 0) {
111 return ManagedSecondary::install(target);