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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 if (!utils::FileExists(key_path.c_str())) { | 538 if (!utils::FileExists(key_path.c_str())) { |
539 LOG(WARNING) << "Not verifying signed delta payload -- missing public key."; | 539 LOG(WARNING) << "Not verifying signed delta payload -- missing public key."; |
540 return true; | 540 return true; |
541 } | 541 } |
542 TEST_AND_RETURN_FALSE(!signatures_message_data_.empty()); | 542 TEST_AND_RETURN_FALSE(!signatures_message_data_.empty()); |
543 vector<char> signed_hash_data; | 543 vector<char> signed_hash_data; |
544 TEST_AND_RETURN_FALSE(PayloadSigner::VerifySignature(signatures_message_data_, | 544 TEST_AND_RETURN_FALSE(PayloadSigner::VerifySignature(signatures_message_data_, |
545 key_path, | 545 key_path, |
546 &signed_hash_data)); | 546 &signed_hash_data)); |
547 OmahaHashCalculator signed_hasher; | 547 OmahaHashCalculator signed_hasher; |
548 // TODO(petkov): Make sure signed_hash_context_ is loaded when resuming an | |
549 // update. | |
550 TEST_AND_RETURN_FALSE(signed_hasher.SetContext(signed_hash_context_)); | 548 TEST_AND_RETURN_FALSE(signed_hasher.SetContext(signed_hash_context_)); |
551 TEST_AND_RETURN_FALSE(signed_hasher.Finalize()); | 549 TEST_AND_RETURN_FALSE(signed_hasher.Finalize()); |
552 const vector<char>& hash_data = signed_hasher.raw_hash(); | 550 const vector<char>& hash_data = signed_hasher.raw_hash(); |
553 TEST_AND_RETURN_FALSE(!hash_data.empty()); | 551 TEST_AND_RETURN_FALSE(!hash_data.empty()); |
554 TEST_AND_RETURN_FALSE(hash_data == signed_hash_data); | 552 TEST_AND_RETURN_FALSE(hash_data == signed_hash_data); |
555 return true; | 553 return true; |
556 } | 554 } |
557 | 555 |
| 556 bool DeltaPerformer::VerifyAppliedUpdate(const string& path, |
| 557 const string& kernel_path) { |
| 558 LOG(INFO) << "Verifying applied update."; |
| 559 TEST_AND_RETURN_FALSE(manifest_valid_ && |
| 560 manifest_.has_new_kernel_info() && |
| 561 manifest_.has_new_rootfs_info()); |
| 562 const string* paths[] = { &kernel_path, &path }; |
| 563 const PartitionInfo* infos[] = { |
| 564 &manifest_.new_kernel_info(), &manifest_.new_rootfs_info() |
| 565 }; |
| 566 for (size_t i = 0; i < arraysize(paths); ++i) { |
| 567 OmahaHashCalculator hasher; |
| 568 TEST_AND_RETURN_FALSE(hasher.UpdateFile(*paths[i], infos[i]->size())); |
| 569 TEST_AND_RETURN_FALSE(hasher.Finalize()); |
| 570 TEST_AND_RETURN_FALSE(hasher.raw_hash().size() == infos[i]->hash().size()); |
| 571 TEST_AND_RETURN_FALSE(memcmp(hasher.raw_hash().data(), |
| 572 infos[i]->hash().data(), |
| 573 hasher.raw_hash().size()) == 0); |
| 574 } |
| 575 return true; |
| 576 } |
| 577 |
558 void DeltaPerformer::DiscardBufferHeadBytes(size_t count) { | 578 void DeltaPerformer::DiscardBufferHeadBytes(size_t count) { |
559 hash_calculator_.Update(&buffer_[0], count); | 579 hash_calculator_.Update(&buffer_[0], count); |
560 buffer_.erase(buffer_.begin(), buffer_.begin() + count); | 580 buffer_.erase(buffer_.begin(), buffer_.begin() + count); |
561 } | 581 } |
562 | 582 |
563 bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs, | 583 bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs, |
564 string update_check_response_hash) { | 584 string update_check_response_hash) { |
565 int64_t next_operation = kUpdateStateOperationInvalid; | 585 int64_t next_operation = kUpdateStateOperationInvalid; |
566 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextOperation, | 586 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextOperation, |
567 &next_operation) && | 587 &next_operation) && |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { | 690 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { |
671 resumed_update_failures++; | 691 resumed_update_failures++; |
672 } else { | 692 } else { |
673 resumed_update_failures = 1; | 693 resumed_update_failures = 1; |
674 } | 694 } |
675 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); | 695 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); |
676 return true; | 696 return true; |
677 } | 697 } |
678 | 698 |
679 } // namespace chromeos_update_engine | 699 } // namespace chromeos_update_engine |
OLD | NEW |