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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 << "Unable to store the signed hash context."; | 565 << "Unable to store the signed hash context."; |
566 LOG(INFO) << "Extracted signature data of size " | 566 LOG(INFO) << "Extracted signature data of size " |
567 << manifest_.signatures_size() << " at " | 567 << manifest_.signatures_size() << " at " |
568 << manifest_.signatures_offset(); | 568 << manifest_.signatures_offset(); |
569 return true; | 569 return true; |
570 } | 570 } |
571 | 571 |
572 bool DeltaPerformer::VerifyPayload( | 572 bool DeltaPerformer::VerifyPayload( |
573 const string& public_key_path, | 573 const string& public_key_path, |
574 const std::string& update_check_response_hash, | 574 const std::string& update_check_response_hash, |
575 const uint64_t update_check_response_size) { | 575 const uint64_t update_check_response_size, |
576 bool* signature_failed) { | |
576 string key_path = public_key_path; | 577 string key_path = public_key_path; |
577 if (key_path.empty()) { | 578 if (key_path.empty()) { |
578 key_path = kUpdatePayloadPublicKeyPath; | 579 key_path = kUpdatePayloadPublicKeyPath; |
579 } | 580 } |
580 LOG(INFO) << "Verifying delta payload. Public key path: " << key_path; | 581 LOG(INFO) << "Verifying delta payload. Public key path: " << key_path; |
581 | 582 |
582 // Verifies the download hash. | 583 // Verifies the download hash. |
583 const string& download_hash_data = hash_calculator_.hash(); | 584 const string& download_hash_data = hash_calculator_.hash(); |
584 TEST_AND_RETURN_FALSE(!download_hash_data.empty()); | 585 TEST_AND_RETURN_FALSE(!download_hash_data.empty()); |
585 TEST_AND_RETURN_FALSE(download_hash_data == update_check_response_hash); | 586 TEST_AND_RETURN_FALSE(download_hash_data == update_check_response_hash); |
586 | 587 |
587 // Verifies the download size. | 588 // Verifies the download size. |
588 TEST_AND_RETURN_FALSE(update_check_response_size == | 589 TEST_AND_RETURN_FALSE(update_check_response_size == |
589 manifest_metadata_size_ + buffer_offset_); | 590 manifest_metadata_size_ + buffer_offset_); |
590 | 591 |
591 // Verifies the signed payload hash. | 592 // Verifies the signed payload hash. |
592 if (!utils::FileExists(key_path.c_str())) { | 593 if (!utils::FileExists(key_path.c_str())) { |
petkov
2011/03/30 21:04:42
I assume you have full confidence in the correctne
adlr
2011/03/30 21:52:19
Good point! I was thinking we should really expect
| |
593 LOG(WARNING) << "Not verifying signed delta payload -- missing public key."; | 594 LOG(WARNING) << "Not verifying signed delta payload -- missing public key."; |
594 return true; | 595 return true; |
595 } | 596 } |
596 TEST_AND_RETURN_FALSE(!signatures_message_data_.empty()); | 597 TEST_AND_RETURN_FALSE(!signatures_message_data_.empty()); |
597 vector<char> signed_hash_data; | 598 vector<char> signed_hash_data; |
598 TEST_AND_RETURN_FALSE(PayloadSigner::VerifySignature(signatures_message_data_, | 599 TEST_AND_RETURN_FALSE(PayloadSigner::VerifySignature(signatures_message_data_, |
petkov
2011/03/30 21:04:42
If signatures get mixed up this will fail first. S
adlr
2011/03/30 21:52:19
Done.
| |
599 key_path, | 600 key_path, |
600 &signed_hash_data)); | 601 &signed_hash_data)); |
601 OmahaHashCalculator signed_hasher; | 602 OmahaHashCalculator signed_hasher; |
602 TEST_AND_RETURN_FALSE(signed_hasher.SetContext(signed_hash_context_)); | 603 TEST_AND_RETURN_FALSE(signed_hasher.SetContext(signed_hash_context_)); |
603 TEST_AND_RETURN_FALSE(signed_hasher.Finalize()); | 604 TEST_AND_RETURN_FALSE(signed_hasher.Finalize()); |
604 vector<char> hash_data = signed_hasher.raw_hash(); | 605 vector<char> hash_data = signed_hasher.raw_hash(); |
605 PayloadSigner::PadRSA2048SHA256Hash(&hash_data); | 606 PayloadSigner::PadRSA2048SHA256Hash(&hash_data); |
606 TEST_AND_RETURN_FALSE(!hash_data.empty()); | 607 TEST_AND_RETURN_FALSE(!hash_data.empty()); |
607 TEST_AND_RETURN_FALSE(hash_data == signed_hash_data); | 608 if (hash_data != signed_hash_data) { |
609 LOG(ERROR) << "Public key verificaion failed. This is non-fatal. " | |
610 "Attached Signature:"; | |
611 utils::HexDumpVector(signed_hash_data); | |
612 LOG(ERROR) << "Computed Signature:"; | |
613 utils::HexDumpVector(hash_data); | |
614 if (signature_failed) { | |
615 *signature_failed = true; | |
616 } | |
617 } | |
608 return true; | 618 return true; |
609 } | 619 } |
610 | 620 |
611 bool DeltaPerformer::GetNewPartitionInfo(uint64_t* kernel_size, | 621 bool DeltaPerformer::GetNewPartitionInfo(uint64_t* kernel_size, |
612 vector<char>* kernel_hash, | 622 vector<char>* kernel_hash, |
613 uint64_t* rootfs_size, | 623 uint64_t* rootfs_size, |
614 vector<char>* rootfs_hash) { | 624 vector<char>* rootfs_hash) { |
615 TEST_AND_RETURN_FALSE(manifest_valid_ && | 625 TEST_AND_RETURN_FALSE(manifest_valid_ && |
616 manifest_.has_new_kernel_info() && | 626 manifest_.has_new_kernel_info() && |
617 manifest_.has_new_rootfs_info()); | 627 manifest_.has_new_rootfs_info()); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { | 774 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { |
765 resumed_update_failures++; | 775 resumed_update_failures++; |
766 } else { | 776 } else { |
767 resumed_update_failures = 1; | 777 resumed_update_failures = 1; |
768 } | 778 } |
769 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); | 779 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); |
770 return true; | 780 return true; |
771 } | 781 } |
772 | 782 |
773 } // namespace chromeos_update_engine | 783 } // namespace chromeos_update_engine |
OLD | NEW |