From dc61ab1ae4baedd116ad980392856053e13d905f Mon Sep 17 00:00:00 2001 From: Patti Vacek Date: Fri, 1 Oct 2021 10:39:21 +0200 Subject: [PATCH] Hacks to support TUF-only operation in aktualizr-secondary. Signed-off-by: Patti Vacek --- src/aktualizr_secondary/aktualizr_secondary.cc | 13 ++++++++++--- src/libaktualizr-posix/ipuptanesecondary.cc | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/aktualizr_secondary/aktualizr_secondary.cc b/src/aktualizr_secondary/aktualizr_secondary.cc index 4db915e71..8535ed2bd 100644 --- a/src/aktualizr_secondary/aktualizr_secondary.cc +++ b/src/aktualizr_secondary/aktualizr_secondary.cc @@ -72,6 +72,7 @@ data::InstallationResult AktualizrSecondary::doFullVerification(const Metadata& // We trust the time that the given system/ECU provides. TimeStamp now(TimeStamp::Now()); + /* // 2. Download and check the Root metadata file from the Director repository. // 3. NOT SUPPORTED: Download and check the Timestamp metadata file from the Director repository. // 4. NOT SUPPORTED: Download and check the Snapshot metadata file from the Director repository. @@ -83,6 +84,7 @@ data::InstallationResult AktualizrSecondary::doFullVerification(const Metadata& return data::InstallationResult(data::ResultCode::Numeric::kVerificationFailed, std::string("Failed to update Director metadata: ") + e.what()); } + */ // 6. Download and check the Root metadata file from the Image repository. // 7. Download and check the Timestamp metadata file from the Image repository. @@ -96,14 +98,17 @@ data::InstallationResult AktualizrSecondary::doFullVerification(const Metadata& std::string("Failed to update Image repo metadata: ") + e.what()); } + /* // 10. Verify that Targets metadata from the Director and Image repositories match. if (!director_repo_.matchTargetsWithImageTargets(*(image_repo_.getTargets()))) { LOG_ERROR << "Targets metadata from the Director and Image repositories do not match"; return data::InstallationResult(data::ResultCode::Numeric::kVerificationFailed, "Targets metadata from the Director and Image repositories do not match"); } + */ - auto targetsForThisEcu = director_repo_.getTargets(serial(), hwID()); + // auto targetsForThisEcu = director_repo_.getTargets(serial(), hwID()); + auto targetsForThisEcu = image_repo_.getTargets()->getTargets(serial(), hwID()); if (targetsForThisEcu.size() != 1) { LOG_ERROR << "Invalid number of targets (should be 1): " << targetsForThisEcu.size(); @@ -169,13 +174,15 @@ void AktualizrSecondary::uptaneInitialize() { void AktualizrSecondary::initPendingTargetIfAny() { try { - director_repo_.checkMetaOffline(*storage_); + // director_repo_.checkMetaOffline(*storage_); + image_repo_.checkMetaOffline(*storage_); } catch (const std::exception& e) { LOG_INFO << "No valid metadata found in storage."; return; } - auto targetsForThisEcu = director_repo_.getTargets(ecu_serial_, hardware_id_); + // auto targetsForThisEcu = director_repo_.getTargets(ecu_serial_, hardware_id_); + auto targetsForThisEcu = image_repo_.getTargets()->getTargets(serial(), hwID()); if (targetsForThisEcu.size() != 1) { LOG_ERROR << "Invalid number of targets (should be 1): " << targetsForThisEcu.size(); diff --git a/src/libaktualizr-posix/ipuptanesecondary.cc b/src/libaktualizr-posix/ipuptanesecondary.cc index 35bbdba6b..8fc7a7046 100644 --- a/src/libaktualizr-posix/ipuptanesecondary.cc +++ b/src/libaktualizr-posix/ipuptanesecondary.cc @@ -215,13 +215,13 @@ data::InstallationResult IpUptaneSecondary::putMetadata_v2(const Uptane::MetaBun req->present(AKIpUptaneMes_PR_putMetaReq2); auto m = req->putMetaReq2(); - m->directorRepo.present = directorRepo_PR_collection; + // m->directorRepo.present = directorRepo_PR_collection; m->imageRepo.present = imageRepo_PR_collection; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - addMetadata(meta_bundle, Uptane::RepositoryType::Director(), Uptane::Role::Root(), m->directorRepo.choice.collection); - addMetadata(meta_bundle, Uptane::RepositoryType::Director(), Uptane::Role::Targets(), - m->directorRepo.choice.collection); // NOLINT(cppcoreguidelines-pro-type-union-access) + // addMetadata(meta_bundle, Uptane::RepositoryType::Director(), Uptane::Role::Root(), m->directorRepo.choice.collection); + // addMetadata(meta_bundle, Uptane::RepositoryType::Director(), Uptane::Role::Targets(), + // m->directorRepo.choice.collection); // NOLINT(cppcoreguidelines-pro-type-union-access) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) addMetadata(meta_bundle, Uptane::RepositoryType::Image(), Uptane::Role::Root(), m->imageRepo.choice.collection); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)