diff options
Diffstat (limited to 'update_verifier/update_verifier.cpp')
-rw-r--r-- | update_verifier/update_verifier.cpp | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp index 6e86ac9d3..d7cd061e2 100644 --- a/update_verifier/update_verifier.cpp +++ b/update_verifier/update_verifier.cpp @@ -65,6 +65,8 @@ using android::hardware::boot::V1_0::IBootControl; using android::hardware::boot::V1_0::BoolResult; using android::hardware::boot::V1_0::CommandResult; +constexpr const char* kDefaultCareMapPrefix = "/data/ota_package/care_map"; + // Find directories in format of "/sys/block/dm-X". static int dm_name_filter(const dirent* de) { if (android::base::StartsWith(de->d_name, "dm-")) { @@ -73,6 +75,10 @@ static int dm_name_filter(const dirent* de) { return 0; } +UpdateVerifier::UpdateVerifier() + : care_map_prefix_(kDefaultCareMapPrefix), + property_reader_([](const std::string& id) { return android::base::GetProperty(id, ""); }) {} + // Iterate the content of "/sys/block/dm-X/dm/name" and find all the dm-wrapped block devices. // We will later read all the ("cared") blocks from "/dev/block/dm-X" to ensure the target // partition's integrity. @@ -224,18 +230,14 @@ bool UpdateVerifier::ParseCareMapPlainText(const std::string& content) { return true; } -bool UpdateVerifier::ParseCareMap(const std::string& file_name) { +bool UpdateVerifier::ParseCareMap() { partition_map_.clear(); - std::string care_map_name = file_name; - if (care_map_name.empty()) { - std::string care_map_prefix = "/data/ota_package/care_map"; - care_map_name = care_map_prefix + ".pb"; - if (access(care_map_name.c_str(), R_OK) == -1) { - LOG(WARNING) << care_map_name - << " doesn't exist, falling back to read the care_map in plain text format."; - care_map_name = care_map_prefix + ".txt"; - } + std::string care_map_name = care_map_prefix_ + ".pb"; + if (access(care_map_name.c_str(), R_OK) == -1) { + LOG(WARNING) << care_map_name + << " doesn't exist, falling back to read the care_map in plain text format."; + care_map_name = care_map_prefix_ + ".txt"; } android::base::unique_fd care_map_fd(TEMP_FAILURE_RETRY(open(care_map_name.c_str(), O_RDONLY))); @@ -283,7 +285,21 @@ bool UpdateVerifier::ParseCareMap(const std::string& file_name) { return false; } - // TODO(xunchang) compare the fingerprint of the partition. + // Continues to check other partitions if there is a fingerprint mismatch. + if (partition.id().empty() || partition.id() == "unknown") { + LOG(WARNING) << "Skip reading partition " << partition.name() + << ": property_id is not provided to get fingerprint."; + continue; + } + + std::string fingerprint = property_reader_(partition.id()); + if (fingerprint != partition.fingerprint()) { + LOG(WARNING) << "Skip reading partition " << partition.name() << ": fingerprint " + << fingerprint << " doesn't match the expected value " + << partition.fingerprint(); + continue; + } + partition_map_.emplace(partition.name(), ranges); } @@ -295,6 +311,15 @@ bool UpdateVerifier::ParseCareMap(const std::string& file_name) { return true; } +void UpdateVerifier::set_care_map_prefix(const std::string& prefix) { + care_map_prefix_ = prefix; +} + +void UpdateVerifier::set_property_reader( + const std::function<std::string(const std::string&)>& property_reader) { + property_reader_ = property_reader; +} + static int reboot_device() { if (android_reboot(ANDROID_RB_RESTART2, 0, nullptr) == -1) { LOG(ERROR) << "Failed to reboot."; |