blob: 8aa036e826848172b860503ac47c574bae7be470 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2010 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//
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_DELTA_PERFORMER_H_
18#define UPDATE_ENGINE_PAYLOAD_CONSUMER_DELTA_PERFORMER_H_
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070019
20#include <inttypes.h>
Darin Petkovd7061ab2010-10-06 14:37:09 -070021
Amin Hassanidb56be92017-09-06 12:41:23 -070022#include <limits>
Alex Vakulenkod2779df2014-06-16 13:19:00 -070023#include <string>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070024#include <vector>
Darin Petkovd7061ab2010-10-06 14:37:09 -070025
Alex Vakulenko75039d72014-03-25 12:36:28 -070026#include <base/time/time.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070027#include <brillo/secure_blob.h>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070028#include <google/protobuf/repeated_field.h>
Andrew de los Reyes353777c2010-10-08 10:34:30 -070029#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkovd7061ab2010-10-06 14:37:09 -070030
Alex Deymo39910dc2015-11-09 17:04:30 -080031#include "update_engine/common/hash_calculator.h"
32#include "update_engine/common/platform_constants.h"
33#include "update_engine/payload_consumer/file_descriptor.h"
34#include "update_engine/payload_consumer/file_writer.h"
35#include "update_engine/payload_consumer/install_plan.h"
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070036#include "update_engine/update_metadata.pb.h"
37
38namespace chromeos_update_engine {
39
Alex Deymo542c19b2015-12-03 07:43:31 -030040class DownloadActionDelegate;
41class BootControlInterface;
42class HardwareInterface;
Darin Petkov73058b42010-10-06 16:32:19 -070043class PrefsInterface;
44
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070045// This class performs the actions in a delta update synchronously. The delta
46// update itself should be passed in in chunks as it is received.
47
48class DeltaPerformer : public FileWriter {
49 public:
Darin Petkov9574f7e2011-01-13 10:48:12 -080050 enum MetadataParseResult {
51 kMetadataParseSuccess,
52 kMetadataParseError,
53 kMetadataParseInsufficientData,
54 };
55
Sen Jiangb8060e42015-09-24 17:30:50 -070056 static const uint64_t kDeltaVersionOffset;
Jay Srinivasanf4318702012-09-24 11:56:24 -070057 static const uint64_t kDeltaVersionSize;
Sen Jiangb8060e42015-09-24 17:30:50 -070058 static const uint64_t kDeltaManifestSizeOffset;
Jay Srinivasanf4318702012-09-24 11:56:24 -070059 static const uint64_t kDeltaManifestSizeSize;
Sen Jiangb8060e42015-09-24 17:30:50 -070060 static const uint64_t kDeltaMetadataSignatureSizeSize;
61 static const uint64_t kMaxPayloadHeaderSize;
Don Garrett4d039442013-10-28 18:40:06 -070062 static const uint64_t kSupportedMajorPayloadVersion;
Alex Deymoe5e5fe92015-10-05 09:28:19 -070063 static const uint32_t kSupportedMinorPayloadVersion;
Darin Petkovabc7bc02011-02-23 14:39:43 -080064
Gilad Arnold8a86fa52013-01-15 12:35:05 -080065 // Defines the granularity of progress logging in terms of how many "completed
66 // chunks" we want to report at the most.
67 static const unsigned kProgressLogMaxChunks;
68 // Defines a timeout since the last progress was logged after which we want to
69 // force another log message (even if the current chunk was not completed).
70 static const unsigned kProgressLogTimeoutSeconds;
71 // These define the relative weights (0-100) we give to the different work
72 // components associated with an update when computing an overall progress.
73 // Currently they include the download progress and the number of completed
74 // operations. They must add up to one hundred (100).
75 static const unsigned kProgressDownloadWeight;
76 static const unsigned kProgressOperationsWeight;
77
Jay Srinivasanf0572052012-10-23 18:12:56 -070078 DeltaPerformer(PrefsInterface* prefs,
Alex Deymo542c19b2015-12-03 07:43:31 -030079 BootControlInterface* boot_control,
80 HardwareInterface* hardware,
81 DownloadActionDelegate* download_delegate,
Amin Hassani7ecda262017-07-11 17:10:50 -070082 InstallPlan* install_plan,
83 bool is_interactive)
Darin Petkov73058b42010-10-06 16:32:19 -070084 : prefs_(prefs),
Alex Deymo542c19b2015-12-03 07:43:31 -030085 boot_control_(boot_control),
86 hardware_(hardware),
87 download_delegate_(download_delegate),
Amin Hassani7ecda262017-07-11 17:10:50 -070088 install_plan_(install_plan),
89 is_interactive_(is_interactive) {}
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070090
Jay Srinivasan51dcf262012-09-13 17:24:32 -070091 // FileWriter's Write implementation where caller doesn't care about
92 // error codes.
Alex Deymo610277e2014-11-11 21:18:11 -080093 bool Write(const void* bytes, size_t count) override {
David Zeuthena99981f2013-04-29 13:42:47 -070094 ErrorCode error;
Jay Srinivasan51dcf262012-09-13 17:24:32 -070095 return Write(bytes, count, &error);
96 }
97
98 // FileWriter's Write implementation that returns a more specific |error| code
99 // in case of failures in Write operation.
Alex Deymo610277e2014-11-11 21:18:11 -0800100 bool Write(const void* bytes, size_t count, ErrorCode *error) override;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700101
102 // Wrapper around close. Returns 0 on success or -errno on error.
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700103 // Closes both 'path' given to Open() and the kernel path.
Alex Deymo610277e2014-11-11 21:18:11 -0800104 int Close() override;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700105
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700106 // Open the target and source (if delta payload) file descriptors for the
107 // |current_partition_|. The manifest needs to be already parsed for this to
108 // work. Returns whether the required file descriptors were successfully open.
109 bool OpenCurrentPartition();
110
111 // Closes the current partition file descriptors if open. Returns 0 on success
112 // or -errno on error.
113 int CloseCurrentPartition();
114
David Zeuthen8f191b22013-08-06 12:27:50 -0700115 // Returns |true| only if the manifest has been processed and it's valid.
116 bool IsManifestValid();
117
Darin Petkovd7061ab2010-10-06 14:37:09 -0700118 // Verifies the downloaded payload against the signed hash included in the
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700119 // payload, against the update check hash (which is in base64 format) and
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700120 // size using the public key and returns ErrorCode::kSuccess on success, an
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700121 // error code on failure. This method should be called after closing the
122 // stream. Note this method skips the signed hash check if the public key is
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700123 // unavailable; it returns ErrorCode::kSignedDeltaPayloadExpectedError if the
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700124 // public key is available but the delta payload doesn't include a signature.
David Zeuthena99981f2013-04-29 13:42:47 -0700125 ErrorCode VerifyPayload(const std::string& update_check_response_hash,
Allie Wood9f6f0a52015-03-30 11:25:47 -0700126 const uint64_t update_check_response_size);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700127
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700128 // Converts an ordered collection of Extent objects which contain data of
129 // length full_length to a comma-separated string. For each Extent, the
130 // string will have the start offset and then the length in bytes.
131 // The length value of the last extent in the string may be short, since
132 // the full length of all extents in the string is capped to full_length.
133 // Also, an extent starting at kSparseHole, appears as -1 in the string.
134 // For example, if the Extents are {1, 1}, {4, 2}, {kSparseHole, 1},
135 // {0, 1}, block_size is 4096, and full_length is 5 * block_size - 13,
136 // the resulting string will be: "4096:4096,16384:8192,-1:4096,0:4083"
137 static bool ExtentsToBsdiffPositionsString(
138 const google::protobuf::RepeatedPtrField<Extent>& extents,
139 uint64_t block_size,
140 uint64_t full_length,
141 std::string* positions_string);
142
Darin Petkov0406e402010-10-06 21:33:11 -0700143 // Returns true if a previous update attempt can be continued based on the
144 // persistent preferences and the new update check response hash.
145 static bool CanResumeUpdate(PrefsInterface* prefs,
Chih-Hung Hsieh5c6bb1d2016-07-27 13:33:15 -0700146 const std::string& update_check_response_hash);
Darin Petkov0406e402010-10-06 21:33:11 -0700147
148 // Resets the persistent update progress state to indicate that an update
Darin Petkov9b230572010-10-08 10:20:09 -0700149 // can't be resumed. Performs a quick update-in-progress reset if |quick| is
150 // true, otherwise resets all progress-related update state. Returns true on
151 // success, false otherwise.
152 static bool ResetUpdateProgress(PrefsInterface* prefs, bool quick);
Darin Petkov0406e402010-10-06 21:33:11 -0700153
Darin Petkov9574f7e2011-01-13 10:48:12 -0800154 // Attempts to parse the update metadata starting from the beginning of
Gilad Arnolddaa27402014-01-23 11:56:17 -0800155 // |payload|. On success, returns kMetadataParseSuccess. Returns
Gilad Arnoldfe133932014-01-14 12:25:50 -0800156 // kMetadataParseInsufficientData if more data is needed to parse the complete
157 // metadata. Returns kMetadataParseError if the metadata can't be parsed given
158 // the payload.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700159 MetadataParseResult ParsePayloadMetadata(const brillo::Blob& payload,
Gilad Arnolddaa27402014-01-23 11:56:17 -0800160 ErrorCode* error);
Darin Petkov9574f7e2011-01-13 10:48:12 -0800161
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700162 void set_public_key_path(const std::string& public_key_path) {
163 public_key_path_ = public_key_path;
Darin Petkov698d0412010-10-13 10:59:44 -0700164 }
165
Amin Hassanidb56be92017-09-06 12:41:23 -0700166 // Set |*out_offset| to the byte offset where the size of the metadata
167 // signature is stored in a payload. Return true on success, if this field is
168 // not present in the payload, return false.
Sen Jiangb8060e42015-09-24 17:30:50 -0700169 bool GetMetadataSignatureSizeOffset(uint64_t* out_offset) const;
Jay Srinivasanf4318702012-09-24 11:56:24 -0700170
Sen Jiangb8060e42015-09-24 17:30:50 -0700171 // Set |*out_offset| to the byte offset at which the manifest protobuf begins
172 // in a payload. Return true on success, false if the offset is unknown.
173 bool GetManifestOffset(uint64_t* out_offset) const;
Don Garrett4d039442013-10-28 18:40:06 -0700174
Gilad Arnoldfe133932014-01-14 12:25:50 -0800175 // Returns the size of the payload metadata, which includes the payload header
Sen Jiangb8060e42015-09-24 17:30:50 -0700176 // and the manifest. If the header was not yet parsed, returns zero.
Gilad Arnoldfe133932014-01-14 12:25:50 -0800177 uint64_t GetMetadataSize() const;
178
Gilad Arnolddaa27402014-01-23 11:56:17 -0800179 // If the manifest was successfully parsed, copies it to |*out_manifest_p|.
180 // Returns true on success.
181 bool GetManifest(DeltaArchiveManifest* out_manifest_p) const;
182
Sen Jiangb8060e42015-09-24 17:30:50 -0700183 // Return true if header parsing is finished and no errors occurred.
184 bool IsHeaderParsed() const;
185
186 // Returns the major payload version. If the version was not yet parsed,
187 // returns zero.
188 uint64_t GetMajorVersion() const;
189
Allie Woodfdf00512015-03-02 13:34:55 -0800190 // Returns the delta minor version. If this value is defined in the manifest,
191 // it returns that value, otherwise it returns the default value.
192 uint32_t GetMinorVersion() const;
193
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700194 private:
Andrew de los Reyes353777c2010-10-08 10:34:30 -0700195 friend class DeltaPerformerTest;
Sen Jianga4365d62015-09-25 10:52:25 -0700196 friend class DeltaPerformerIntegrationTest;
Sen Jiang76bfa742015-10-12 17:13:26 -0700197 FRIEND_TEST(DeltaPerformerTest, BrilloMetadataSignatureSizeTest);
198 FRIEND_TEST(DeltaPerformerTest, BrilloVerifyMetadataSignatureTest);
David Zeuthene7f89172013-10-31 10:21:04 -0700199 FRIEND_TEST(DeltaPerformerTest, UsePublicKeyFromResponse);
Andrew de los Reyes353777c2010-10-08 10:34:30 -0700200
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700201 // Parse and move the update instructions of all partitions into our local
202 // |partitions_| variable based on the version of the payload. Requires the
203 // manifest to be parsed and valid.
204 bool ParseManifestPartitions(ErrorCode* error);
205
Gilad Arnoldfe133932014-01-14 12:25:50 -0800206 // Appends up to |*count_p| bytes from |*bytes_p| to |buffer_|, but only to
207 // the extent that the size of |buffer_| does not exceed |max|. Advances
208 // |*cbytes_p| and decreases |*count_p| by the actual number of bytes copied,
209 // and returns this number.
210 size_t CopyDataToBuffer(const char** bytes_p, size_t* count_p, size_t max);
211
212 // If |op_result| is false, emits an error message using |op_type_name| and
213 // sets |*error| accordingly. Otherwise does nothing. Returns |op_result|.
214 bool HandleOpResult(bool op_result, const char* op_type_name,
215 ErrorCode* error);
216
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800217 // Logs the progress of downloading/applying an update.
218 void LogProgress(const char* message_prefix);
219
220 // Update overall progress metrics, log as necessary.
221 void UpdateOverallProgress(bool force_log, const char* message_prefix);
222
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700223 // Returns true if enough of the delta file has been passed via Write()
224 // to be able to perform a given install operation.
Alex Deymoa12ee112015-08-12 22:19:32 -0700225 bool CanPerformInstallOperation(const InstallOperation& operation);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700226
Gilad Arnold21504f02013-05-24 08:51:22 -0700227 // Checks the integrity of the payload manifest. Returns true upon success,
228 // false otherwise.
229 ErrorCode ValidateManifest();
230
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700231 // Validates that the hash of the blobs corresponding to the given |operation|
232 // matches what's specified in the manifest in the payload.
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700233 // Returns ErrorCode::kSuccess on match or a suitable error code otherwise.
Alex Deymoa12ee112015-08-12 22:19:32 -0700234 ErrorCode ValidateOperationHash(const InstallOperation& operation);
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700235
Sen Jiang76bfa742015-10-12 17:13:26 -0700236 // Given the |payload|, verifies that the signed hash of its metadata matches
237 // what's specified in the install plan from Omaha (if present) or the
238 // metadata signature in payload itself (if present). Returns
239 // ErrorCode::kSuccess on match or a suitable error code otherwise. This
240 // method must be called before any part of the metadata is parsed so that a
241 // man-in-the-middle attack on the SSL connection to the payload server
242 // doesn't exploit any vulnerability in the code that parses the protocol
243 // buffer.
244 ErrorCode ValidateMetadataSignature(const brillo::Blob& payload);
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700245
Amin Hassanidb56be92017-09-06 12:41:23 -0700246 // Calculates and validates the source hash of the operation |operation|.
247 bool CalculateAndValidateSourceHash(const InstallOperation& operation,
248 ErrorCode* error);
249
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700250 // Returns true on success.
Alex Deymoa12ee112015-08-12 22:19:32 -0700251 bool PerformInstallOperation(const InstallOperation& operation);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700252
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700253 // These perform a specific type of operation and return true on success.
Sen Jiangbe2c47b2016-06-15 14:09:27 -0700254 // |error| will be set if source hash mismatch, otherwise |error| might not be
255 // set even if it fails.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700256 bool PerformReplaceOperation(const InstallOperation& operation);
257 bool PerformZeroOrDiscardOperation(const InstallOperation& operation);
258 bool PerformMoveOperation(const InstallOperation& operation);
259 bool PerformBsdiffOperation(const InstallOperation& operation);
Sen Jiangbe2c47b2016-06-15 14:09:27 -0700260 bool PerformSourceCopyOperation(const InstallOperation& operation,
261 ErrorCode* error);
262 bool PerformSourceBsdiffOperation(const InstallOperation& operation,
263 ErrorCode* error);
Amin Hassani02855c22017-09-06 22:34:50 -0700264 bool PerformPuffDiffOperation(const InstallOperation& operation,
265 ErrorCode* error);
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700266
Sen Jiangf6813802015-11-03 21:27:29 -0800267 // Extracts the payload signature message from the blob on the |operation| if
268 // the offset matches the one specified by the manifest. Returns whether the
269 // signature was extracted.
270 bool ExtractSignatureMessageFromOperation(const InstallOperation& operation);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700271
Sen Jiangf6813802015-11-03 21:27:29 -0800272 // Extracts the payload signature message from the current |buffer_| if the
273 // offset matches the one specified by the manifest. Returns whether the
274 // signature was extracted.
275 bool ExtractSignatureMessage();
276
277 // Updates the payload hash calculator with the bytes in |buffer_|, also
278 // updates the signed hash calculator with the first |signed_hash_buffer_size|
279 // bytes in |buffer_|. Then discard the content, ensuring that memory is being
280 // deallocated. If |do_advance_offset|, advances the internal offset counter
281 // accordingly.
282 void DiscardBuffer(bool do_advance_offset, size_t signed_hash_buffer_size);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700283
Darin Petkov0406e402010-10-06 21:33:11 -0700284 // Checkpoints the update progress into persistent storage to allow this
285 // update attempt to be resumed after reboot.
Darin Petkov73058b42010-10-06 16:32:19 -0700286 bool CheckpointUpdateProgress();
287
Darin Petkov9b230572010-10-08 10:20:09 -0700288 // Primes the required update state. Returns true if the update state was
289 // successfully initialized to a saved resume state or if the update is a new
290 // update. Returns false otherwise.
291 bool PrimeUpdateState();
292
David Zeuthene7f89172013-10-31 10:21:04 -0700293 // If the Omaha response contains a public RSA key and we're allowed
294 // to use it (e.g. if we're in developer mode), extract the key from
295 // the response and store it in a temporary file and return true. In
296 // the affirmative the path to the temporary file is stored in
297 // |out_tmp_key| and it is the responsibility of the caller to clean
298 // it up.
299 bool GetPublicKeyFromResponse(base::FilePath *out_tmp_key);
300
Darin Petkov73058b42010-10-06 16:32:19 -0700301 // Update Engine preference store.
302 PrefsInterface* prefs_;
303
Alex Deymo542c19b2015-12-03 07:43:31 -0300304 // BootControl and Hardware interface references.
305 BootControlInterface* boot_control_;
306 HardwareInterface* hardware_;
307
308 // The DownloadActionDelegate instance monitoring the DownloadAction, or a
309 // nullptr if not used.
310 DownloadActionDelegate* download_delegate_;
Jay Srinivasanf0572052012-10-23 18:12:56 -0700311
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700312 // Install Plan based on Omaha Response.
313 InstallPlan* install_plan_;
314
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700315 // File descriptor of the source partition. Only set while updating a
316 // partition when using a delta payload.
317 FileDescriptorPtr source_fd_{nullptr};
Darin Petkovd7061ab2010-10-06 14:37:09 -0700318
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700319 // File descriptor of the target partition. Only set while performing the
320 // operations of a given partition.
321 FileDescriptorPtr target_fd_{nullptr};
Darin Petkovd7061ab2010-10-06 14:37:09 -0700322
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700323 // Paths the |source_fd_| and |target_fd_| refer to.
324 std::string source_path_;
325 std::string target_path_;
Allie Woodfdf00512015-03-02 13:34:55 -0800326
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700327 // Parsed manifest. Set after enough bytes to parse the manifest were
328 // downloaded.
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700329 DeltaArchiveManifest manifest_;
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700330 bool manifest_parsed_{false};
331 bool manifest_valid_{false};
332 uint64_t metadata_size_{0};
333 uint64_t manifest_size_{0};
Sen Jiang76bfa742015-10-12 17:13:26 -0700334 uint32_t metadata_signature_size_{0};
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700335 uint64_t major_payload_version_{0};
Darin Petkovd7061ab2010-10-06 14:37:09 -0700336
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700337 // Accumulated number of operations per partition. The i-th element is the
338 // sum of the number of operations for all the partitions from 0 to i
339 // inclusive. Valid when |manifest_valid_| is true.
340 std::vector<size_t> acc_num_operations_;
341
342 // The total operations in a payload. Valid when |manifest_valid_| is true,
343 // otherwise 0.
344 size_t num_total_operations_{0};
345
346 // The list of partitions to update as found in the manifest major version 2.
347 // When parsing an older manifest format, the information is converted over to
348 // this format instead.
349 std::vector<PartitionUpdate> partitions_;
350
351 // Index in the list of partitions (|partitions_| member) of the current
352 // partition being processed.
353 size_t current_partition_{0};
354
355 // Index of the next operation to perform in the manifest. The index is linear
356 // on the total number of operation on the manifest.
357 size_t next_operation_num_{0};
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700358
Gilad Arnoldfe133932014-01-14 12:25:50 -0800359 // A buffer used for accumulating downloaded data. Initially, it stores the
360 // payload metadata; once that's downloaded and parsed, it stores data for the
361 // next update operation.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700362 brillo::Blob buffer_;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700363 // Offset of buffer_ in the binary blobs section of the update.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700364 uint64_t buffer_offset_{0};
Darin Petkovd7061ab2010-10-06 14:37:09 -0700365
Darin Petkov0406e402010-10-06 21:33:11 -0700366 // Last |buffer_offset_| value updated as part of the progress update.
Alex Vakulenko0103c362016-01-20 07:56:15 -0800367 uint64_t last_updated_buffer_offset_{std::numeric_limits<uint64_t>::max()};
Darin Petkov0406e402010-10-06 21:33:11 -0700368
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700369 // The block size (parsed from the manifest).
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700370 uint32_t block_size_{0};
Darin Petkovd7061ab2010-10-06 14:37:09 -0700371
Sen Jiangf6813802015-11-03 21:27:29 -0800372 // Calculates the whole payload file hash, including headers and signatures.
Alex Deymo39910dc2015-11-09 17:04:30 -0800373 HashCalculator payload_hash_calculator_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700374
Sen Jiangf6813802015-11-03 21:27:29 -0800375 // Calculates the hash of the portion of the payload signed by the payload
376 // signature. This hash skips the metadata signature portion, located after
377 // the metadata and doesn't include the payload signature itself.
Alex Deymo39910dc2015-11-09 17:04:30 -0800378 HashCalculator signed_hash_calculator_;
Darin Petkov437adc42010-10-07 13:12:24 -0700379
Darin Petkovd7061ab2010-10-06 14:37:09 -0700380 // Signatures message blob extracted directly from the payload.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700381 brillo::Blob signatures_message_data_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700382
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700383 // The public key to be used. Provided as a member so that tests can
384 // override with test keys.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700385 std::string public_key_path_{constants::kUpdatePayloadPublicKeyPath};
Darin Petkov698d0412010-10-13 10:59:44 -0700386
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800387 // The number of bytes received so far, used for progress tracking.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700388 size_t total_bytes_received_{0};
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800389
390 // An overall progress counter, which should reflect both download progress
391 // and the ratio of applied operations. Range is 0-100.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700392 unsigned overall_progress_{0};
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800393
394 // The last progress chunk recorded.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700395 unsigned last_progress_chunk_{0};
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800396
Amin Hassani7ecda262017-07-11 17:10:50 -0700397 // If |true|, the update is user initiated (vs. periodic update checks).
398 bool is_interactive_{false};
399
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800400 // The timeout after which we should force emitting a progress log (constant),
401 // and the actual point in time for the next forced log to be emitted.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700402 const base::TimeDelta forced_progress_log_wait_{
403 base::TimeDelta::FromSeconds(kProgressLogTimeoutSeconds)};
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800404 base::Time forced_progress_log_time_;
405
Sen Jiangb8060e42015-09-24 17:30:50 -0700406 // The payload major payload version supported by DeltaPerformer.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700407 uint64_t supported_major_version_{kSupportedMajorPayloadVersion};
Sen Jiangb8060e42015-09-24 17:30:50 -0700408
Allie Woodfdf00512015-03-02 13:34:55 -0800409 // The delta minor payload version supported by DeltaPerformer.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700410 uint32_t supported_minor_version_{kSupportedMinorPayloadVersion};
Allie Woodfdf00512015-03-02 13:34:55 -0800411
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700412 DISALLOW_COPY_AND_ASSIGN(DeltaPerformer);
413};
414
415} // namespace chromeos_update_engine
416
Alex Deymo39910dc2015-11-09 17:04:30 -0800417#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_DELTA_PERFORMER_H_