Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2012 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #include "update_engine/payload_consumer/filesystem_verifier_action.h" |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 18 | |
| 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <algorithm> |
| 25 | #include <cstdlib> |
| 26 | #include <string> |
| 27 | |
Alex Deymo | 20c9920 | 2015-07-09 16:14:16 -0700 | [diff] [blame] | 28 | #include <base/bind.h> |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 29 | #include <brillo/data_encoding.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 30 | #include <brillo/streams/file_stream.h> |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 31 | #include <base/strings/string_util.h> |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 32 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 33 | #include "update_engine/common/utils.h" |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 34 | |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 35 | using brillo::data_encoding::Base64Encode; |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 36 | using std::string; |
| 37 | |
| 38 | namespace chromeos_update_engine { |
| 39 | |
| 40 | namespace { |
Alex Deymo | 20c9920 | 2015-07-09 16:14:16 -0700 | [diff] [blame] | 41 | const off_t kReadFileBufferSize = 128 * 1024; |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 42 | } // namespace |
| 43 | |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 44 | void FilesystemVerifierAction::PerformAction() { |
| 45 | // Will tell the ActionProcessor we've failed if we return. |
| 46 | ScopedActionCompleter abort_action_completer(processor_, this); |
| 47 | |
| 48 | if (!HasInputObject()) { |
| 49 | LOG(ERROR) << "FilesystemVerifierAction missing input object."; |
| 50 | return; |
| 51 | } |
| 52 | install_plan_ = GetInputObject(); |
| 53 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 54 | if (install_plan_.partitions.empty()) { |
| 55 | LOG(INFO) << "No partitions to verify."; |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 56 | if (HasOutputPipe()) |
| 57 | SetOutputObject(install_plan_); |
| 58 | abort_action_completer.set_code(ErrorCode::kSuccess); |
| 59 | return; |
| 60 | } |
Jae Hoon Kim | 50504d6 | 2020-04-23 14:32:38 -0700 | [diff] [blame] | 61 | install_plan_.Dump(); |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 62 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 63 | StartPartitionHashing(); |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 64 | abort_action_completer.set_should_complete(false); |
| 65 | } |
| 66 | |
| 67 | void FilesystemVerifierAction::TerminateProcessing() { |
Alex Deymo | 20c9920 | 2015-07-09 16:14:16 -0700 | [diff] [blame] | 68 | cancelled_ = true; |
| 69 | Cleanup(ErrorCode::kSuccess); // error code is ignored if canceled_ is true. |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 72 | void FilesystemVerifierAction::Cleanup(ErrorCode code) { |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 73 | src_stream_.reset(); |
Alex Deymo | 20c9920 | 2015-07-09 16:14:16 -0700 | [diff] [blame] | 74 | // This memory is not used anymore. |
| 75 | buffer_.clear(); |
| 76 | |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 77 | if (cancelled_) |
| 78 | return; |
| 79 | if (code == ErrorCode::kSuccess && HasOutputPipe()) |
| 80 | SetOutputObject(install_plan_); |
Kelvin Zhang | 70eef23 | 2020-06-12 20:32:40 +0000 | [diff] [blame] | 81 | UpdateProgress(1.0); |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 82 | processor_->ActionComplete(this, code); |
| 83 | } |
| 84 | |
Kelvin Zhang | 70eef23 | 2020-06-12 20:32:40 +0000 | [diff] [blame] | 85 | void FilesystemVerifierAction::UpdateProgress(double progress) { |
| 86 | if (delegate_ != nullptr) { |
| 87 | delegate_->OnVerifyProgressUpdate(progress); |
| 88 | } |
| 89 | } |
| 90 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 91 | void FilesystemVerifierAction::StartPartitionHashing() { |
| 92 | if (partition_index_ == install_plan_.partitions.size()) { |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 93 | if (!install_plan_.untouched_dynamic_partitions.empty()) { |
| 94 | LOG(INFO) << "Verifying extents of untouched dynamic partitions [" |
| 95 | << base::JoinString(install_plan_.untouched_dynamic_partitions, |
| 96 | ", ") |
| 97 | << "]"; |
| 98 | if (!dynamic_control_->VerifyExtentsForUntouchedPartitions( |
| 99 | install_plan_.source_slot, |
| 100 | install_plan_.target_slot, |
| 101 | install_plan_.untouched_dynamic_partitions)) { |
| 102 | Cleanup(ErrorCode::kFilesystemVerifierError); |
| 103 | return; |
| 104 | } |
| 105 | } |
| 106 | |
Sen Jiang | a35896c | 2016-05-25 11:08:41 -0700 | [diff] [blame] | 107 | Cleanup(ErrorCode::kSuccess); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 108 | return; |
| 109 | } |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 110 | const InstallPlan::Partition& partition = |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 111 | install_plan_.partitions[partition_index_]; |
| 112 | |
| 113 | string part_path; |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 114 | switch (verifier_step_) { |
| 115 | case VerifierStep::kVerifySourceHash: |
Sen Jiang | e6e4bb9 | 2016-04-05 14:59:12 -0700 | [diff] [blame] | 116 | part_path = partition.source_path; |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 117 | partition_size_ = partition.source_size; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 118 | break; |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 119 | case VerifierStep::kVerifyTargetHash: |
Sen Jiang | e6e4bb9 | 2016-04-05 14:59:12 -0700 | [diff] [blame] | 120 | part_path = partition.target_path; |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 121 | partition_size_ = partition.target_size; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 122 | break; |
| 123 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 124 | |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 125 | if (part_path.empty()) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 126 | if (partition_size_ == 0) { |
| 127 | LOG(INFO) << "Skip hashing partition " << partition_index_ << " (" |
| 128 | << partition.name << ") because size is 0."; |
| 129 | partition_index_++; |
| 130 | StartPartitionHashing(); |
| 131 | return; |
| 132 | } |
| 133 | LOG(ERROR) << "Cannot hash partition " << partition_index_ << " (" |
| 134 | << partition.name |
| 135 | << ") because its device path cannot be determined."; |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 136 | Cleanup(ErrorCode::kFilesystemVerifierError); |
| 137 | return; |
| 138 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 139 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 140 | LOG(INFO) << "Hashing partition " << partition_index_ << " (" |
| 141 | << partition.name << ") on device " << part_path; |
| 142 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 143 | brillo::ErrorPtr error; |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 144 | src_stream_ = |
| 145 | brillo::FileStream::Open(base::FilePath(part_path), |
| 146 | brillo::Stream::AccessMode::READ, |
| 147 | brillo::FileStream::Disposition::OPEN_EXISTING, |
| 148 | &error); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 149 | |
| 150 | if (!src_stream_) { |
| 151 | LOG(ERROR) << "Unable to open " << part_path << " for reading"; |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 152 | Cleanup(ErrorCode::kFilesystemVerifierError); |
| 153 | return; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | buffer_.resize(kReadFileBufferSize); |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 157 | hasher_ = std::make_unique<HashCalculator>(); |
| 158 | |
| 159 | offset_ = 0; |
Sen Jiang | 3eeaf7d | 2018-10-11 13:55:32 -0700 | [diff] [blame] | 160 | if (verifier_step_ == VerifierStep::kVerifyTargetHash && |
| 161 | install_plan_.write_verity) { |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 162 | if (!verity_writer_->Init(partition)) { |
| 163 | Cleanup(ErrorCode::kVerityCalculationError); |
| 164 | return; |
| 165 | } |
| 166 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 167 | |
| 168 | // Start the first read. |
| 169 | ScheduleRead(); |
| 170 | } |
| 171 | |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 172 | void FilesystemVerifierAction::ScheduleRead() { |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 173 | const InstallPlan::Partition& partition = |
| 174 | install_plan_.partitions[partition_index_]; |
| 175 | |
| 176 | // We can only start reading anything past |hash_tree_offset| after we have |
| 177 | // already read all the data blocks that the hash tree covers. The same |
| 178 | // applies to FEC. |
| 179 | uint64_t read_end = partition_size_; |
| 180 | if (partition.hash_tree_size != 0 && |
| 181 | offset_ < partition.hash_tree_data_offset + partition.hash_tree_data_size) |
| 182 | read_end = std::min(read_end, partition.hash_tree_offset); |
| 183 | if (partition.fec_size != 0 && |
| 184 | offset_ < partition.fec_data_offset + partition.fec_data_size) |
| 185 | read_end = std::min(read_end, partition.fec_offset); |
| 186 | size_t bytes_to_read = |
| 187 | std::min(static_cast<uint64_t>(buffer_.size()), read_end - offset_); |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 188 | if (!bytes_to_read) { |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 189 | FinishPartitionHashing(); |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 193 | bool read_async_ok = src_stream_->ReadAsync( |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 194 | buffer_.data(), |
| 195 | bytes_to_read, |
| 196 | base::Bind(&FilesystemVerifierAction::OnReadDoneCallback, |
| 197 | base::Unretained(this)), |
| 198 | base::Bind(&FilesystemVerifierAction::OnReadErrorCallback, |
| 199 | base::Unretained(this)), |
| 200 | nullptr); |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 201 | |
| 202 | if (!read_async_ok) { |
| 203 | LOG(ERROR) << "Unable to schedule an asynchronous read from the stream."; |
| 204 | Cleanup(ErrorCode::kError); |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 208 | void FilesystemVerifierAction::OnReadDoneCallback(size_t bytes_read) { |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 209 | if (cancelled_) { |
| 210 | Cleanup(ErrorCode::kError); |
| 211 | return; |
| 212 | } |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 213 | if (bytes_read == 0) { |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 214 | LOG(ERROR) << "Failed to read the remaining " << partition_size_ - offset_ |
| 215 | << " bytes from partition " |
| 216 | << install_plan_.partitions[partition_index_].name; |
| 217 | Cleanup(ErrorCode::kFilesystemVerifierError); |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | if (!hasher_->Update(buffer_.data(), bytes_read)) { |
| 222 | LOG(ERROR) << "Unable to update the hash."; |
| 223 | Cleanup(ErrorCode::kError); |
| 224 | return; |
| 225 | } |
| 226 | |
Kelvin Zhang | 70eef23 | 2020-06-12 20:32:40 +0000 | [diff] [blame] | 227 | // WE don't consider sizes of each partition. Every partition |
| 228 | // has the same length on progress bar. |
| 229 | // TODO(zhangkelvin) Take sizes of each partition into account |
| 230 | |
| 231 | UpdateProgress( |
| 232 | (static_cast<double>(offset_) / partition_size_ + partition_index_) / |
| 233 | install_plan_.partitions.size()); |
Sen Jiang | 3eeaf7d | 2018-10-11 13:55:32 -0700 | [diff] [blame] | 234 | if (verifier_step_ == VerifierStep::kVerifyTargetHash && |
| 235 | install_plan_.write_verity) { |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 236 | if (!verity_writer_->Update(offset_, buffer_.data(), bytes_read)) { |
| 237 | Cleanup(ErrorCode::kVerityCalculationError); |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 238 | return; |
| 239 | } |
| 240 | } |
| 241 | |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 242 | offset_ += bytes_read; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 243 | |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 244 | if (offset_ == partition_size_) { |
| 245 | FinishPartitionHashing(); |
| 246 | return; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 247 | } |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 248 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 249 | ScheduleRead(); |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 252 | void FilesystemVerifierAction::OnReadErrorCallback(const brillo::Error* error) { |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 253 | // TODO(deymo): Transform the read-error into an specific ErrorCode. |
| 254 | LOG(ERROR) << "Asynchronous read failed."; |
| 255 | Cleanup(ErrorCode::kError); |
| 256 | } |
| 257 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 258 | void FilesystemVerifierAction::FinishPartitionHashing() { |
| 259 | if (!hasher_->Finalize()) { |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 260 | LOG(ERROR) << "Unable to finalize the hash."; |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 261 | Cleanup(ErrorCode::kError); |
| 262 | return; |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 263 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 264 | InstallPlan::Partition& partition = |
| 265 | install_plan_.partitions[partition_index_]; |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 266 | LOG(INFO) << "Hash of " << partition.name << ": " |
| 267 | << Base64Encode(hasher_->raw_hash()); |
Alex Deymo | b9e8e26 | 2015-08-03 20:23:03 -0700 | [diff] [blame] | 268 | |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 269 | switch (verifier_step_) { |
| 270 | case VerifierStep::kVerifyTargetHash: |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 271 | if (partition.target_hash != hasher_->raw_hash()) { |
| 272 | LOG(ERROR) << "New '" << partition.name |
| 273 | << "' partition verification failed."; |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 274 | if (partition.source_hash.empty()) { |
| 275 | // No need to verify source if it is a full payload. |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 276 | Cleanup(ErrorCode::kNewRootfsVerificationError); |
| 277 | return; |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 278 | } |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 279 | // If we have not verified source partition yet, now that the target |
Sen Jiang | 65566a3 | 2016-04-06 13:35:36 -0700 | [diff] [blame] | 280 | // partition does not match, and it's not a full payload, we need to |
| 281 | // switch to kVerifySourceHash step to check if it's because the source |
| 282 | // partition does not match either. |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 283 | verifier_step_ = VerifierStep::kVerifySourceHash; |
Sen Jiang | 1ad42ad | 2015-11-17 15:04:02 -0800 | [diff] [blame] | 284 | } else { |
| 285 | partition_index_++; |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 286 | } |
| 287 | break; |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 288 | case VerifierStep::kVerifySourceHash: |
Sen Jiang | 1ad42ad | 2015-11-17 15:04:02 -0800 | [diff] [blame] | 289 | if (partition.source_hash != hasher_->raw_hash()) { |
| 290 | LOG(ERROR) << "Old '" << partition.name |
| 291 | << "' partition verification failed."; |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 292 | LOG(ERROR) << "This is a server-side error due to mismatched delta" |
| 293 | << " update image!"; |
| 294 | LOG(ERROR) << "The delta I've been given contains a " << partition.name |
| 295 | << " delta update that must be applied over a " |
| 296 | << partition.name << " with a specific checksum, but the " |
| 297 | << partition.name |
| 298 | << " we're starting with doesn't have that checksum! This" |
| 299 | " means that the delta I've been given doesn't match my" |
| 300 | " existing system. The " |
| 301 | << partition.name << " partition I have has hash: " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 302 | << Base64Encode(hasher_->raw_hash()) |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 303 | << " but the update expected me to have " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 304 | << Base64Encode(partition.source_hash) << " ."; |
Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 305 | LOG(INFO) << "To get the checksum of the " << partition.name |
| 306 | << " partition run this command: dd if=" |
| 307 | << partition.source_path |
| 308 | << " bs=1M count=" << partition.source_size |
| 309 | << " iflag=count_bytes 2>/dev/null | openssl dgst -sha256 " |
| 310 | "-binary | openssl base64"; |
| 311 | LOG(INFO) << "To get the checksum of partitions in a bin file, " |
| 312 | << "run: .../src/scripts/sha256_partitions.sh .../file.bin"; |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 313 | Cleanup(ErrorCode::kDownloadStateInitializationError); |
| 314 | return; |
Sen Jiang | 1ad42ad | 2015-11-17 15:04:02 -0800 | [diff] [blame] | 315 | } |
Sen Jiang | a35896c | 2016-05-25 11:08:41 -0700 | [diff] [blame] | 316 | // The action will skip kVerifySourceHash step if target partition hash |
| 317 | // matches, if we are in this step, it means target hash does not match, |
| 318 | // and now that the source partition hash matches, we should set the error |
| 319 | // code to reflect the error in target partition. |
| 320 | // We only need to verify the source partition which the target hash does |
| 321 | // not match, the rest of the partitions don't matter. |
Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 322 | Cleanup(ErrorCode::kNewRootfsVerificationError); |
| 323 | return; |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 324 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 325 | // Start hashing the next partition, if any. |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 326 | hasher_.reset(); |
| 327 | buffer_.clear(); |
| 328 | src_stream_->CloseBlocking(nullptr); |
| 329 | StartPartitionHashing(); |
Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | } // namespace chromeos_update_engine |