From f8db80284ccd7964df7a09a2b3c06c086aabc655 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Mon, 1 Jul 2019 10:13:45 +0300 Subject: [PATCH] OTA-2488: Move Managed and Virtual secondaries out of Uptane namespace Signed-off-by: Mike Sul --- config/sota-local.toml | 3 - config/sota-ubuntu.toml | 3 - docs/configuration.adoc | 1 - docs/secondaries.svg | 1001 ----------------- src/aktualizr_primary/secondary.cc | 2 +- src/libaktualizr/primary/aktualizr_test.cc | 8 +- src/libaktualizr/primary/uptane_key_test.cc | 12 +- src/libaktualizr/uptane/uptane_ci_test.cc | 4 +- src/libaktualizr/uptane/uptane_test.cc | 2 +- src/virtual_secondary/managedsecondary.cc | 19 +- src/virtual_secondary/managedsecondary.h | 33 +- .../virtual_secondary_test.cc | 2 +- src/virtual_secondary/virtualsecondary.cc | 6 +- src/virtual_secondary/virtualsecondary.h | 12 +- tests/uptane_test_common.h | 4 +- 15 files changed, 50 insertions(+), 1062 deletions(-) delete mode 100644 docs/secondaries.svg diff --git a/config/sota-local.toml b/config/sota-local.toml index 078b2ab1f8..773456b051 100644 --- a/config/sota-local.toml +++ b/config/sota-local.toml @@ -2,9 +2,6 @@ provision_path = "credentials.zip" primary_ecu_hardware_id = "local-fake" -[uptane] -secondary_configs_dir = "secondary_configs" - [logger] loglevel = 1 diff --git a/config/sota-ubuntu.toml b/config/sota-ubuntu.toml index 0977b51f94..4a5f683a55 100644 --- a/config/sota-ubuntu.toml +++ b/config/sota-ubuntu.toml @@ -2,9 +2,6 @@ provision_path = "/var/sota/sota_provisioning_credentials.zip" primary_ecu_hardware_id = "ubuntu" -[uptane] -secondary_configs_dir = "/usr/lib/sota/secondaries" - [storage] type = "sqlite" diff --git a/docs/configuration.adoc b/docs/configuration.adoc index fa687583e5..3c1c80f029 100644 --- a/docs/configuration.adoc +++ b/docs/configuration.adoc @@ -86,7 +86,6 @@ Options for Uptane. | `repo_server` | | Image repository server URL. If empty, set to `tls.server` with `/repo` appended. | `key_source` | `"file"` | Where to read the device's private key from. Options: `"file"`, `"pkcs11"`. | `key_type` | `"RSA2048"` | Type of cryptographic keys to use. Options: `"ED25519"`, `"RSA2048"`, `"RSA3072"` or `"RSA4096"`. -| `secondary_configs_dir` | `""` | Directory containing individual secondary json configuration files. Example here: link:{aktualizr-github-url}/config/secondary/virtualsec.json[]. This is currently only used for virtual secondaries and will be soon replaced entirely by `secondary_configs_file`. | `secondary_config_file` | `""` | A path to a json file containing configuration of Secondary ECU(s) to be registered with the primary. Example here: link:{aktualizr-github-url}/config/posix-secondary-config.json[]. | `force_install_completion`| false | Forces installation completion. Causes a system reboot in case of an ostree package manager. Emulates a reboot in case of a fake package manager. |========================================================================================== diff --git a/docs/secondaries.svg b/docs/secondaries.svg deleted file mode 100644 index d12dbe9748..0000000000 --- a/docs/secondaries.svg +++ /dev/null @@ -1,1001 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - SotaUptaneClient - SecondaryInterface - VirtualSecondary - Customer Secondary - UptaneSecondary - - Customer flasher - - Legacy ECU - UDSSecondary - DoIPSecondary - ... - - - - - - - SecondaryFactory - - - - Uptane ECU - Uptane ECU - - - - - - - - - - No border - - Dashed border - - Solid border - - — C++ class - — Executable - — External device - - — Is a parent of - — Communicates - — Creates - — Is given to - - - - - SecondaryConfig - - - - diff --git a/src/aktualizr_primary/secondary.cc b/src/aktualizr_primary/secondary.cc index 41f50b6ba9..8ae3a470ce 100644 --- a/src/aktualizr_primary/secondary.cc +++ b/src/aktualizr_primary/secondary.cc @@ -27,7 +27,7 @@ static SecondaryFactoryRegistry sec_factory_registry = { {VirtualSecondaryConfig::Type, [](const SecondaryConfig& config) { auto virtual_sec_cgf = dynamic_cast(config); - return Secondaries({std::make_shared(virtual_sec_cgf)}); + return Secondaries({std::make_shared(virtual_sec_cgf)}); }}, // { // Add another secondary factory here diff --git a/src/libaktualizr/primary/aktualizr_test.cc b/src/libaktualizr/primary/aktualizr_test.cc index e2e579ed2e..be33ddbbd2 100644 --- a/src/libaktualizr/primary/aktualizr_test.cc +++ b/src/libaktualizr/primary/aktualizr_test.cc @@ -136,7 +136,7 @@ TEST(Aktualizr, AddSecondary) { Primary::VirtualSecondaryConfig ecu_config = virtual_configuration(temp_dir.Path()); - aktualizr.AddSecondary(std::make_shared(ecu_config)); + aktualizr.AddSecondary(std::make_shared(ecu_config)); aktualizr.Initialize(); @@ -156,7 +156,7 @@ TEST(Aktualizr, AddSecondary) { EXPECT_EQ(expected_ecus.size(), 0); ecu_config.ecu_serial = "ecuserial4"; - auto sec4 = std::make_shared(ecu_config); + auto sec4 = std::make_shared(ecu_config); EXPECT_THROW(aktualizr.AddSecondary(sec4), std::logic_error); } @@ -180,7 +180,7 @@ TEST(Aktualizr, DeviceInstallationResult) { Primary::VirtualSecondaryConfig ecu_config = virtual_configuration(temp_dir.Path()); - aktualizr.AddSecondary(std::make_shared(ecu_config)); + aktualizr.AddSecondary(std::make_shared(ecu_config)); aktualizr.Initialize(); @@ -1005,7 +1005,7 @@ TEST(Aktualizr, FullMultipleSecondaries) { UptaneTestCommon::TestAktualizr aktualizr(conf, storage, http); UptaneTestCommon::addDefaultSecondary(conf, temp_dir2, "sec_serial2", "sec_hwid2"); if (boost::filesystem::exists(conf.uptane.secondary_config_file)) { - aktualizr.AddSecondary(std::make_shared( + aktualizr.AddSecondary(std::make_shared( Primary::VirtualSecondaryConfig::create_from_file(conf.uptane.secondary_config_file))); } std::function event)> f_cb = process_events_FullMultipleSecondaries; diff --git a/src/libaktualizr/primary/uptane_key_test.cc b/src/libaktualizr/primary/uptane_key_test.cc index f757ab9436..1342f723d3 100644 --- a/src/libaktualizr/primary/uptane_key_test.cc +++ b/src/libaktualizr/primary/uptane_key_test.cc @@ -84,8 +84,8 @@ class UptaneKey_Check_Test { // Verify that each secondary has valid keys. std::map >::iterator it; for (it = sota_client->secondaries.begin(); it != sota_client->secondaries.end(); it++) { - std::shared_ptr managed = - boost::polymorphic_pointer_downcast(it->second); + std::shared_ptr managed = + boost::polymorphic_pointer_downcast(it->second); std::string public_key; std::string private_key; EXPECT_TRUE(managed->loadKeys(&public_key, &private_key)); @@ -117,8 +117,8 @@ TEST(UptaneKey, CheckAllKeys) { initKeyTests(config, ecu_config1, ecu_config2, temp_dir, http->tls_server); auto storage = INvStorage::newStorage(config.storage); auto sota_client = UptaneTestCommon::newTestClient(config, storage, http); - sota_client->addNewSecondary(std::make_shared(ecu_config1)); - sota_client->addNewSecondary(std::make_shared(ecu_config2)); + sota_client->addNewSecondary(std::make_shared(ecu_config1)); + sota_client->addNewSecondary(std::make_shared(ecu_config2)); EXPECT_NO_THROW(sota_client->initialize()); UptaneKey_Check_Test::checkKeyTests(storage, sota_client); } @@ -140,8 +140,8 @@ TEST(UptaneKey, RecoverWithoutKeys) { { auto storage = INvStorage::newStorage(config.storage); auto sota_client = UptaneTestCommon::newTestClient(config, storage, http); - sota_client->addNewSecondary(std::make_shared(ecu_config1)); - sota_client->addNewSecondary(std::make_shared(ecu_config2)); + sota_client->addNewSecondary(std::make_shared(ecu_config1)); + sota_client->addNewSecondary(std::make_shared(ecu_config2)); EXPECT_NO_THROW(sota_client->initialize()); UptaneKey_Check_Test::checkKeyTests(storage, sota_client); diff --git a/src/libaktualizr/uptane/uptane_ci_test.cc b/src/libaktualizr/uptane/uptane_ci_test.cc index 334a4a83e9..3ecd9cb98a 100644 --- a/src/libaktualizr/uptane/uptane_ci_test.cc +++ b/src/libaktualizr/uptane/uptane_ci_test.cc @@ -76,8 +76,8 @@ TEST(UptaneCI, CheckKeys) { std::map >::iterator it; for (it = sota_client->secondaries.begin(); it != sota_client->secondaries.end(); it++) { - std::shared_ptr managed_secondary = - std::dynamic_pointer_cast(it->second); + std::shared_ptr managed_secondary = + std::dynamic_pointer_cast(it->second); EXPECT_TRUE(managed_secondary); std::string public_key; diff --git a/src/libaktualizr/uptane/uptane_test.cc b/src/libaktualizr/uptane/uptane_test.cc index 8b774507f0..07ab944656 100644 --- a/src/libaktualizr/uptane/uptane_test.cc +++ b/src/libaktualizr/uptane/uptane_test.cc @@ -531,7 +531,7 @@ TEST(Uptane, UptaneSecondaryAddSameSerial) { auto storage = INvStorage::newStorage(config.storage); auto sota_client = UptaneTestCommon::newTestClient(config, storage, http); UptaneTestCommon::addDefaultSecondary(config, temp_dir, "secondary_ecu_serial", "secondary_hardware_new"); - EXPECT_THROW(sota_client->addNewSecondary(std::make_shared( + EXPECT_THROW(sota_client->addNewSecondary(std::make_shared( Primary::VirtualSecondaryConfig::create_from_file(config.uptane.secondary_config_file))), std::runtime_error); } diff --git a/src/virtual_secondary/managedsecondary.cc b/src/virtual_secondary/managedsecondary.cc index 08a1d879c6..b25c27bd53 100644 --- a/src/virtual_secondary/managedsecondary.cc +++ b/src/virtual_secondary/managedsecondary.cc @@ -12,7 +12,8 @@ #include -namespace Uptane { +namespace Primary { + ManagedSecondary::ManagedSecondary(Primary::ManagedSecondaryConfig sconfig_in) : sconfig(std::move(sconfig_in)) { // TODO: FIX // loadMetadata(meta_pack); @@ -60,15 +61,16 @@ void ManagedSecondary::Initialize() { void ManagedSecondary::rawToMeta() { // raw meta is trusted current_meta.director_root = - Uptane::Root(RepositoryType::Director(), Utils::parseJSON(current_raw_meta.director_root)); + Uptane::Root(Uptane::RepositoryType::Director(), Utils::parseJSON(current_raw_meta.director_root)); current_meta.director_targets = Uptane::Targets(Utils::parseJSON(current_raw_meta.director_targets)); - current_meta.image_root = Uptane::Root(RepositoryType::Image(), Utils::parseJSON(current_raw_meta.image_root)); + current_meta.image_root = + Uptane::Root(Uptane::RepositoryType::Image(), Utils::parseJSON(current_raw_meta.image_root)); current_meta.image_targets = Uptane::Targets(Utils::parseJSON(current_raw_meta.image_targets)); current_meta.image_timestamp = Uptane::TimestampMeta(Utils::parseJSON(current_raw_meta.image_timestamp)); current_meta.image_snapshot = Uptane::Snapshot(Utils::parseJSON(current_raw_meta.image_snapshot)); } -bool ManagedSecondary::putMetadata(const RawMetaPack &meta_pack) { +bool ManagedSecondary::putMetadata(const Uptane::RawMetaPack &meta_pack) { // No verification is currently performed, we can add verification in future for testing purposes detected_attack = ""; @@ -117,8 +119,8 @@ int ManagedSecondary::getRootVersion(const bool director) { bool ManagedSecondary::putRoot(const std::string &root, const bool director) { Uptane::Root &prev_root = (director) ? current_meta.director_root : current_meta.image_root; std::string &prev_raw_root = (director) ? current_raw_meta.director_root : current_raw_meta.image_root; - Uptane::Root new_root = - Uptane::Root((director) ? RepositoryType::Director() : RepositoryType::Image(), Utils::parseJSON(root)); + Uptane::Root new_root = Uptane::Root( + (director) ? Uptane::RepositoryType::Director() : Uptane::RepositoryType::Image(), Utils::parseJSON(root)); // No verification is currently performed, we can add verification in future for testing purposes if (new_root.version() == prev_root.version() + 1) { @@ -151,7 +153,7 @@ bool ManagedSecondary::sendFirmware(const std::shared_ptr &data) { return false; } - std::vector::const_iterator it; + std::vector::const_iterator it; for (it = expected_target_hashes.begin(); it != expected_target_hashes.end(); it++) { if (it->TypeString() == "sha256") { if (boost::algorithm::to_lower_copy(boost::algorithm::hex(Crypto::sha256digest(*data))) != @@ -227,4 +229,5 @@ bool ManagedSecondary::loadKeys(std::string *pub_key, std::string *priv_key) { *pub_key = Utils::readFile(public_key_path.string()); return true; } -} // namespace Uptane + +} // namespace Primary diff --git a/src/virtual_secondary/managedsecondary.h b/src/virtual_secondary/managedsecondary.h index 3a4e56c278..2e24b610f4 100644 --- a/src/virtual_secondary/managedsecondary.h +++ b/src/virtual_secondary/managedsecondary.h @@ -1,5 +1,5 @@ -#ifndef UPTANE_MANAGEDSECONDARY_H_ -#define UPTANE_MANAGEDSECONDARY_H_ +#ifndef PRIMARY_MANAGEDSECONDARY_H_ +#define PRIMARY_MANAGEDSECONDARY_H_ #include #include @@ -34,30 +34,26 @@ class ManagedSecondaryConfig : public SecondaryConfig { KeyType key_type{KeyType::kRSA2048}; }; -} // namespace Primary - -namespace Uptane { - // Managed secondary is an abstraction over virtual and other types of legacy // (non-UPTANE) secondaries. They require all the UPTANE-related functionality // to be implemented in aktualizr itself, so there's some shared code. -class ManagedSecondary : public SecondaryInterface { +class ManagedSecondary : public Uptane::SecondaryInterface { public: explicit ManagedSecondary(Primary::ManagedSecondaryConfig sconfig_in); ~ManagedSecondary() override = default; void Initialize(); - EcuSerial getSerial() override { + Uptane::EcuSerial getSerial() override { if (!sconfig.ecu_serial.empty()) { - return EcuSerial(sconfig.ecu_serial); + return Uptane::EcuSerial(sconfig.ecu_serial); } - return EcuSerial(public_key_.KeyId()); + return Uptane::EcuSerial(public_key_.KeyId()); } Uptane::HardwareIdentifier getHwId() override { return Uptane::HardwareIdentifier(sconfig.ecu_hardware_id); } PublicKey getPublicKey() override { return public_key_; } - bool putMetadata(const RawMetaPack& meta_pack) override; + bool putMetadata(const Uptane::RawMetaPack& meta_pack) override; int getRootVersion(bool director) override; bool putRoot(const std::string& root, bool director) override; @@ -75,11 +71,11 @@ class ManagedSecondary : public SecondaryInterface { std::string detected_attack; std::string expected_target_name; - std::vector expected_target_hashes; + std::vector expected_target_hashes; uint64_t expected_target_length{}; - MetaPack current_meta; - RawMetaPack current_raw_meta; + Uptane::MetaPack current_meta; + Uptane::RawMetaPack current_raw_meta; std::mutex install_mutex; virtual bool storeFirmware(const std::string& target_name, const std::string& content) = 0; @@ -89,9 +85,10 @@ class ManagedSecondary : public SecondaryInterface { void rawToMeta(); // TODO: implement - void storeMetadata(const RawMetaPack& meta_pack) { (void)meta_pack; } - bool loadMetadata(RawMetaPack* meta_pack); + void storeMetadata(const Uptane::RawMetaPack& meta_pack) { (void)meta_pack; } + bool loadMetadata(Uptane::RawMetaPack* meta_pack); }; -} // namespace Uptane -#endif // UPTANE_MANAGEDSECONDARY_H_ +} // namespace Primary + +#endif // PRIMARY_MANAGEDSECONDARY_H_ diff --git a/src/virtual_secondary/virtual_secondary_test.cc b/src/virtual_secondary/virtual_secondary_test.cc index b3d48807ce..a881492257 100644 --- a/src/virtual_secondary/virtual_secondary_test.cc +++ b/src/virtual_secondary/virtual_secondary_test.cc @@ -49,7 +49,7 @@ class PartialVerificationSecondaryTest : public ::testing::Test { }; /* Create a virtual secondary for testing. */ -TEST_F(VirtualSecondaryTest, Instantiation) { EXPECT_NO_THROW(Uptane::VirtualSecondary virtual_sec(config_)); } +TEST_F(VirtualSecondaryTest, Instantiation) { EXPECT_NO_THROW(Primary::VirtualSecondary virtual_sec(config_)); } /* Partial verification secondaries generate and store public keys. */ TEST_F(PartialVerificationSecondaryTest, Uptane_get_key) { diff --git a/src/virtual_secondary/virtualsecondary.cc b/src/virtual_secondary/virtualsecondary.cc index 81232eece5..f71db00a56 100644 --- a/src/virtual_secondary/virtualsecondary.cc +++ b/src/virtual_secondary/virtualsecondary.cc @@ -56,9 +56,6 @@ void VirtualSecondaryConfig::dump(const boost::filesystem::path& file_full_path) json_file.close(); } -} // namespace Primary - -namespace Uptane { VirtualSecondary::VirtualSecondary(Primary::VirtualSecondaryConfig sconfig_in) : ManagedSecondary(std::move(sconfig_in)) {} @@ -87,4 +84,5 @@ bool VirtualSecondary::getFirmwareInfo(std::string* target_name, size_t& target_ return true; } -} // namespace Uptane + +} // namespace Primary diff --git a/src/virtual_secondary/virtualsecondary.h b/src/virtual_secondary/virtualsecondary.h index 9f1ebfde1f..60b080347f 100644 --- a/src/virtual_secondary/virtualsecondary.h +++ b/src/virtual_secondary/virtualsecondary.h @@ -1,5 +1,5 @@ -#ifndef UPTANE_VIRTUALSECONDARY_H_ -#define UPTANE_VIRTUALSECONDARY_H_ +#ifndef PRIMARY_VIRTUALSECONDARY_H_ +#define PRIMARY_VIRTUALSECONDARY_H_ #include @@ -20,9 +20,6 @@ class VirtualSecondaryConfig : public ManagedSecondaryConfig { static const char* const Type; }; -} // namespace Primary - -namespace Uptane { class VirtualSecondary : public ManagedSecondary { public: explicit VirtualSecondary(Primary::VirtualSecondaryConfig sconfig_in); @@ -32,6 +29,7 @@ class VirtualSecondary : public ManagedSecondary { bool storeFirmware(const std::string& target_name, const std::string& content) override; bool getFirmwareInfo(std::string* target_name, size_t& target_len, std::string* sha256hash) override; }; -} // namespace Uptane -#endif // UPTANE_VIRTUALSECONDARY_H_ +} // namespace Primary + +#endif // PRIMARY_VIRTUALSECONDARY_H_ diff --git a/tests/uptane_test_common.h b/tests/uptane_test_common.h index f987879d7c..7b74da19b5 100644 --- a/tests/uptane_test_common.h +++ b/tests/uptane_test_common.h @@ -37,7 +37,7 @@ struct UptaneTestCommon { std::shared_ptr http) : Aktualizr(config, storage, http) { if (boost::filesystem::exists(config.uptane.secondary_config_file)) { - AddSecondary(std::make_shared(Primary::VirtualSecondaryConfig::create_from_file(config.uptane.secondary_config_file))); + AddSecondary(std::make_shared(Primary::VirtualSecondaryConfig::create_from_file(config.uptane.secondary_config_file))); } } @@ -56,7 +56,7 @@ struct UptaneTestCommon { SotaUptaneClient(config_in, storage_in, http_client, bootloader_in, report_queue_in, events_channel_in) { if (boost::filesystem::exists(config_in.uptane.secondary_config_file)) { - addSecondary(std::make_shared(Primary::VirtualSecondaryConfig::create_from_file(config_in.uptane.secondary_config_file))); + addSecondary(std::make_shared(Primary::VirtualSecondaryConfig::create_from_file(config_in.uptane.secondary_config_file))); } } };