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