| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "update_engine/delta_performer.h" | 5 #include "update_engine/delta_performer.h" |
| 6 | 6 |
| 7 #include <endian.h> | 7 #include <endian.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return -err; | 167 return -err; |
| 168 } | 168 } |
| 169 | 169 |
| 170 namespace { | 170 namespace { |
| 171 | 171 |
| 172 void LogPartitionInfoHash(const PartitionInfo& info, const string& tag) { | 172 void LogPartitionInfoHash(const PartitionInfo& info, const string& tag) { |
| 173 string sha256; | 173 string sha256; |
| 174 if (OmahaHashCalculator::Base64Encode(info.hash().data(), | 174 if (OmahaHashCalculator::Base64Encode(info.hash().data(), |
| 175 info.hash().size(), | 175 info.hash().size(), |
| 176 &sha256)) { | 176 &sha256)) { |
| 177 LOG(INFO) << "PartitionInfo " << tag << " sha256:" << sha256 | 177 LOG(INFO) << "PartitionInfo " << tag << " sha256: " << sha256 |
| 178 << " length:" << tag.size(); | 178 << " size: " << info.size(); |
| 179 } else { | 179 } else { |
| 180 LOG(ERROR) << "Base64Encode failed for tag: " << tag; | 180 LOG(ERROR) << "Base64Encode failed for tag: " << tag; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 void LogPartitionInfo(const DeltaArchiveManifest& manifest) { | 184 void LogPartitionInfo(const DeltaArchiveManifest& manifest) { |
| 185 if (manifest.has_old_kernel_info()) | 185 if (manifest.has_old_kernel_info()) |
| 186 LogPartitionInfoHash(manifest.old_kernel_info(), "old_kernel_info"); | 186 LogPartitionInfoHash(manifest.old_kernel_info(), "old_kernel_info"); |
| 187 if (manifest.has_old_rootfs_info()) | 187 if (manifest.has_old_rootfs_info()) |
| 188 LogPartitionInfoHash(manifest.old_rootfs_info(), "old_rootfs_info"); | 188 LogPartitionInfoHash(manifest.old_rootfs_info(), "old_rootfs_info"); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 &signed_hash_data)); | 582 &signed_hash_data)); |
| 583 OmahaHashCalculator signed_hasher; | 583 OmahaHashCalculator signed_hasher; |
| 584 TEST_AND_RETURN_FALSE(signed_hasher.SetContext(signed_hash_context_)); | 584 TEST_AND_RETURN_FALSE(signed_hasher.SetContext(signed_hash_context_)); |
| 585 TEST_AND_RETURN_FALSE(signed_hasher.Finalize()); | 585 TEST_AND_RETURN_FALSE(signed_hasher.Finalize()); |
| 586 const vector<char>& hash_data = signed_hasher.raw_hash(); | 586 const vector<char>& hash_data = signed_hasher.raw_hash(); |
| 587 TEST_AND_RETURN_FALSE(!hash_data.empty()); | 587 TEST_AND_RETURN_FALSE(!hash_data.empty()); |
| 588 TEST_AND_RETURN_FALSE(hash_data == signed_hash_data); | 588 TEST_AND_RETURN_FALSE(hash_data == signed_hash_data); |
| 589 return true; | 589 return true; |
| 590 } | 590 } |
| 591 | 591 |
| 592 bool DeltaPerformer::VerifyAppliedUpdate(const string& path, | 592 bool DeltaPerformer::GetNewPartitionInfo(uint64_t* kernel_size, |
| 593 const string& kernel_path) { | 593 vector<char>* kernel_hash, |
| 594 LOG(INFO) << "Verifying applied update."; | 594 uint64_t* rootfs_size, |
| 595 vector<char>* rootfs_hash) { |
| 595 TEST_AND_RETURN_FALSE(manifest_valid_ && | 596 TEST_AND_RETURN_FALSE(manifest_valid_ && |
| 596 manifest_.has_new_kernel_info() && | 597 manifest_.has_new_kernel_info() && |
| 597 manifest_.has_new_rootfs_info()); | 598 manifest_.has_new_rootfs_info()); |
| 598 const string* paths[] = { &kernel_path, &path }; | 599 *kernel_size = manifest_.new_kernel_info().size(); |
| 599 const PartitionInfo* infos[] = { | 600 *rootfs_size = manifest_.new_rootfs_info().size(); |
| 600 &manifest_.new_kernel_info(), &manifest_.new_rootfs_info() | 601 vector<char> new_kernel_hash(manifest_.new_kernel_info().hash().begin(), |
| 601 }; | 602 manifest_.new_kernel_info().hash().end()); |
| 602 for (size_t i = 0; i < arraysize(paths); ++i) { | 603 vector<char> new_rootfs_hash(manifest_.new_rootfs_info().hash().begin(), |
| 603 OmahaHashCalculator hasher; | 604 manifest_.new_rootfs_info().hash().end()); |
| 604 TEST_AND_RETURN_FALSE(hasher.UpdateFile(*paths[i], infos[i]->size())); | 605 kernel_hash->swap(new_kernel_hash); |
| 605 TEST_AND_RETURN_FALSE(hasher.Finalize()); | 606 rootfs_hash->swap(new_rootfs_hash); |
| 606 TEST_AND_RETURN_FALSE(hasher.raw_hash().size() == infos[i]->hash().size()); | |
| 607 TEST_AND_RETURN_FALSE(memcmp(hasher.raw_hash().data(), | |
| 608 infos[i]->hash().data(), | |
| 609 hasher.raw_hash().size()) == 0); | |
| 610 } | |
| 611 return true; | 607 return true; |
| 612 } | 608 } |
| 613 | 609 |
| 614 bool DeltaPerformer::VerifySourcePartitions() { | 610 bool DeltaPerformer::VerifySourcePartitions() { |
| 615 LOG(INFO) << "Verifying source partitions."; | 611 LOG(INFO) << "Verifying source partitions."; |
| 616 CHECK(manifest_valid_); | 612 CHECK(manifest_valid_); |
| 617 if (manifest_.has_old_kernel_info()) { | 613 if (manifest_.has_old_kernel_info()) { |
| 618 const PartitionInfo& info = manifest_.old_kernel_info(); | 614 const PartitionInfo& info = manifest_.old_kernel_info(); |
| 619 TEST_AND_RETURN_FALSE(current_kernel_hash_ != NULL && | 615 TEST_AND_RETURN_FALSE(!current_kernel_hash_.empty() && |
| 620 current_kernel_hash_->size() == info.hash().size() && | 616 current_kernel_hash_.size() == info.hash().size() && |
| 621 memcmp(current_kernel_hash_->data(), | 617 memcmp(current_kernel_hash_.data(), |
| 622 info.hash().data(), | 618 info.hash().data(), |
| 623 current_kernel_hash_->size()) == 0); | 619 current_kernel_hash_.size()) == 0); |
| 624 } | 620 } |
| 625 if (manifest_.has_old_rootfs_info()) { | 621 if (manifest_.has_old_rootfs_info()) { |
| 626 const PartitionInfo& info = manifest_.old_rootfs_info(); | 622 const PartitionInfo& info = manifest_.old_rootfs_info(); |
| 627 TEST_AND_RETURN_FALSE(current_rootfs_hash_ != NULL && | 623 TEST_AND_RETURN_FALSE(!current_rootfs_hash_.empty() && |
| 628 current_rootfs_hash_->size() == info.hash().size() && | 624 current_rootfs_hash_.size() == info.hash().size() && |
| 629 memcmp(current_rootfs_hash_->data(), | 625 memcmp(current_rootfs_hash_.data(), |
| 630 info.hash().data(), | 626 info.hash().data(), |
| 631 current_rootfs_hash_->size()) == 0); | 627 current_rootfs_hash_.size()) == 0); |
| 632 } | 628 } |
| 633 return true; | 629 return true; |
| 634 } | 630 } |
| 635 | 631 |
| 636 void DeltaPerformer::DiscardBufferHeadBytes(size_t count) { | 632 void DeltaPerformer::DiscardBufferHeadBytes(size_t count) { |
| 637 hash_calculator_.Update(&buffer_[0], count); | 633 hash_calculator_.Update(&buffer_[0], count); |
| 638 buffer_.erase(buffer_.begin(), buffer_.begin() + count); | 634 buffer_.erase(buffer_.begin(), buffer_.begin() + count); |
| 639 } | 635 } |
| 640 | 636 |
| 641 bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs, | 637 bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { | 745 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { |
| 750 resumed_update_failures++; | 746 resumed_update_failures++; |
| 751 } else { | 747 } else { |
| 752 resumed_update_failures = 1; | 748 resumed_update_failures = 1; |
| 753 } | 749 } |
| 754 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); | 750 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); |
| 755 return true; | 751 return true; |
| 756 } | 752 } |
| 757 | 753 |
| 758 } // namespace chromeos_update_engine | 754 } // namespace chromeos_update_engine |
| OLD | NEW |