Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_DELTA_PERFORMER_H_ |
| 6 | #define UPDATE_ENGINE_DELTA_PERFORMER_H_ |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 7 | |
| 8 | #include <inttypes.h> |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 9 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 10 | #include <string> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 11 | #include <vector> |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 12 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 13 | #include <base/time/time.h> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 14 | #include <google/protobuf/repeated_field.h> |
Andrew de los Reyes | 353777c | 2010-10-08 10:34:30 -0700 | [diff] [blame] | 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 16 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 17 | #include "update_engine/file_writer.h" |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 18 | #include "update_engine/install_plan.h" |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 19 | #include "update_engine/omaha_hash_calculator.h" |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 20 | #include "update_engine/system_state.h" |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 21 | #include "update_engine/update_metadata.pb.h" |
| 22 | |
| 23 | namespace chromeos_update_engine { |
| 24 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 25 | class PrefsInterface; |
| 26 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 27 | // This class performs the actions in a delta update synchronously. The delta |
| 28 | // update itself should be passed in in chunks as it is received. |
| 29 | |
| 30 | class DeltaPerformer : public FileWriter { |
| 31 | public: |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 32 | enum MetadataParseResult { |
| 33 | kMetadataParseSuccess, |
| 34 | kMetadataParseError, |
| 35 | kMetadataParseInsufficientData, |
| 36 | }; |
| 37 | |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 38 | static const uint64_t kDeltaVersionSize; |
| 39 | static const uint64_t kDeltaManifestSizeSize; |
Don Garrett | 4d03944 | 2013-10-28 18:40:06 -0700 | [diff] [blame] | 40 | static const uint64_t kSupportedMajorPayloadVersion; |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 41 | static const uint64_t kSupportedMinorPayloadVersion; |
| 42 | static const uint64_t kFullPayloadMinorVersion; |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 43 | static const char kUpdatePayloadPublicKeyPath[]; |
| 44 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 45 | // Defines the granularity of progress logging in terms of how many "completed |
| 46 | // chunks" we want to report at the most. |
| 47 | static const unsigned kProgressLogMaxChunks; |
| 48 | // Defines a timeout since the last progress was logged after which we want to |
| 49 | // force another log message (even if the current chunk was not completed). |
| 50 | static const unsigned kProgressLogTimeoutSeconds; |
| 51 | // These define the relative weights (0-100) we give to the different work |
| 52 | // components associated with an update when computing an overall progress. |
| 53 | // Currently they include the download progress and the number of completed |
| 54 | // operations. They must add up to one hundred (100). |
| 55 | static const unsigned kProgressDownloadWeight; |
| 56 | static const unsigned kProgressOperationsWeight; |
| 57 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 58 | DeltaPerformer(PrefsInterface* prefs, |
| 59 | SystemState* system_state, |
| 60 | InstallPlan* install_plan) |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 61 | : prefs_(prefs), |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 62 | system_state_(system_state), |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 63 | install_plan_(install_plan), |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 64 | fd_(-1), |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 65 | kernel_fd_(-1), |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 66 | manifest_parsed_(false), |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 67 | manifest_valid_(false), |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 68 | metadata_size_(0), |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 69 | next_operation_num_(0), |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 70 | buffer_offset_(0), |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 71 | last_updated_buffer_offset_(kuint64max), |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 72 | block_size_(0), |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 73 | public_key_path_(kUpdatePayloadPublicKeyPath), |
| 74 | total_bytes_received_(0), |
| 75 | num_rootfs_operations_(0), |
| 76 | num_total_operations_(0), |
| 77 | overall_progress_(0), |
| 78 | last_progress_chunk_(0), |
| 79 | forced_progress_log_wait_( |
| 80 | base::TimeDelta::FromSeconds(kProgressLogTimeoutSeconds)) {} |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 81 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 82 | // Opens the kernel. Should be called before or after Open(), but before |
| 83 | // Write(). The kernel file will be close()d when Close() is called. |
| 84 | bool OpenKernel(const char* kernel_path); |
| 85 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 86 | // flags and mode ignored. Once Close()d, a DeltaPerformer can't be |
| 87 | // Open()ed again. |
| 88 | int Open(const char* path, int flags, mode_t mode); |
| 89 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 90 | // FileWriter's Write implementation where caller doesn't care about |
| 91 | // error codes. |
| 92 | bool Write(const void* bytes, size_t count) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 93 | ErrorCode error; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 94 | return Write(bytes, count, &error); |
| 95 | } |
| 96 | |
| 97 | // FileWriter's Write implementation that returns a more specific |error| code |
| 98 | // in case of failures in Write operation. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 99 | bool Write(const void* bytes, size_t count, ErrorCode *error); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 100 | |
| 101 | // Wrapper around close. Returns 0 on success or -errno on error. |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 102 | // Closes both 'path' given to Open() and the kernel path. |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 103 | int Close(); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 104 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 105 | // Returns |true| only if the manifest has been processed and it's valid. |
| 106 | bool IsManifestValid(); |
| 107 | |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 108 | // Verifies the downloaded payload against the signed hash included in the |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 109 | // payload, against the update check hash (which is in base64 format) and |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 110 | // size using the public key and returns ErrorCode::kSuccess on success, an |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 111 | // error code on failure. This method should be called after closing the |
| 112 | // stream. Note this method skips the signed hash check if the public key is |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 113 | // unavailable; it returns ErrorCode::kSignedDeltaPayloadExpectedError if the |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 114 | // public key is available but the delta payload doesn't include a signature. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 115 | ErrorCode VerifyPayload(const std::string& update_check_response_hash, |
Andrew de los Reyes | 771e1bd | 2011-08-30 14:47:23 -0700 | [diff] [blame] | 116 | const uint64_t update_check_response_size); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 117 | |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 118 | // Reads from the update manifest the expected sizes and hashes of the target |
| 119 | // kernel and rootfs partitions. These values can be used for applied update |
| 120 | // hash verification. This method must be called after the update manifest has |
| 121 | // been parsed (e.g., after closing the stream). Returns true on success, and |
| 122 | // false on failure (e.g., when the values are not present in the update |
| 123 | // manifest). |
| 124 | bool GetNewPartitionInfo(uint64_t* kernel_size, |
| 125 | std::vector<char>* kernel_hash, |
| 126 | uint64_t* rootfs_size, |
| 127 | std::vector<char>* rootfs_hash); |
Darin Petkov | 2dd0109 | 2010-10-08 15:43:05 -0700 | [diff] [blame] | 128 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 129 | // Converts an ordered collection of Extent objects which contain data of |
| 130 | // length full_length to a comma-separated string. For each Extent, the |
| 131 | // string will have the start offset and then the length in bytes. |
| 132 | // The length value of the last extent in the string may be short, since |
| 133 | // the full length of all extents in the string is capped to full_length. |
| 134 | // Also, an extent starting at kSparseHole, appears as -1 in the string. |
| 135 | // For example, if the Extents are {1, 1}, {4, 2}, {kSparseHole, 1}, |
| 136 | // {0, 1}, block_size is 4096, and full_length is 5 * block_size - 13, |
| 137 | // the resulting string will be: "4096:4096,16384:8192,-1:4096,0:4083" |
| 138 | static bool ExtentsToBsdiffPositionsString( |
| 139 | const google::protobuf::RepeatedPtrField<Extent>& extents, |
| 140 | uint64_t block_size, |
| 141 | uint64_t full_length, |
| 142 | std::string* positions_string); |
| 143 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 144 | // Returns true if a previous update attempt can be continued based on the |
| 145 | // persistent preferences and the new update check response hash. |
| 146 | static bool CanResumeUpdate(PrefsInterface* prefs, |
| 147 | std::string update_check_response_hash); |
| 148 | |
| 149 | // Resets the persistent update progress state to indicate that an update |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 150 | // can't be resumed. Performs a quick update-in-progress reset if |quick| is |
| 151 | // true, otherwise resets all progress-related update state. Returns true on |
| 152 | // success, false otherwise. |
| 153 | static bool ResetUpdateProgress(PrefsInterface* prefs, bool quick); |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 154 | |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 155 | // Attempts to parse the update metadata starting from the beginning of |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 156 | // |payload|. On success, returns kMetadataParseSuccess. Returns |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 157 | // kMetadataParseInsufficientData if more data is needed to parse the complete |
| 158 | // metadata. Returns kMetadataParseError if the metadata can't be parsed given |
| 159 | // the payload. |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 160 | MetadataParseResult ParsePayloadMetadata(const std::vector<char>& payload, |
| 161 | ErrorCode* error); |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 162 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 163 | void set_public_key_path(const std::string& public_key_path) { |
| 164 | public_key_path_ = public_key_path; |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Don Garrett | 4d03944 | 2013-10-28 18:40:06 -0700 | [diff] [blame] | 167 | // Returns the byte offset at which the payload version can be found. |
| 168 | static uint64_t GetVersionOffset(); |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 169 | |
| 170 | // Returns the byte offset where the size of the manifest is stored in |
| 171 | // a payload. This offset precedes the actual start of the manifest |
| 172 | // that's returned by the GetManifestOffset method. |
| 173 | static uint64_t GetManifestSizeOffset(); |
| 174 | |
Don Garrett | 4d03944 | 2013-10-28 18:40:06 -0700 | [diff] [blame] | 175 | // Returns the byte offset at which the manifest protobuf begins in a |
| 176 | // payload. |
| 177 | static uint64_t GetManifestOffset(); |
| 178 | |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 179 | // Returns the size of the payload metadata, which includes the payload header |
| 180 | // and the manifest. Is the header was not yet parsed, returns zero. |
| 181 | uint64_t GetMetadataSize() const; |
| 182 | |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 183 | // If the manifest was successfully parsed, copies it to |*out_manifest_p|. |
| 184 | // Returns true on success. |
| 185 | bool GetManifest(DeltaArchiveManifest* out_manifest_p) const; |
| 186 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 187 | private: |
Andrew de los Reyes | 353777c | 2010-10-08 10:34:30 -0700 | [diff] [blame] | 188 | friend class DeltaPerformerTest; |
| 189 | FRIEND_TEST(DeltaPerformerTest, IsIdempotentOperationTest); |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 190 | FRIEND_TEST(DeltaPerformerTest, UsePublicKeyFromResponse); |
Andrew de los Reyes | 353777c | 2010-10-08 10:34:30 -0700 | [diff] [blame] | 191 | |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 192 | // Appends up to |*count_p| bytes from |*bytes_p| to |buffer_|, but only to |
| 193 | // the extent that the size of |buffer_| does not exceed |max|. Advances |
| 194 | // |*cbytes_p| and decreases |*count_p| by the actual number of bytes copied, |
| 195 | // and returns this number. |
| 196 | size_t CopyDataToBuffer(const char** bytes_p, size_t* count_p, size_t max); |
| 197 | |
| 198 | // If |op_result| is false, emits an error message using |op_type_name| and |
| 199 | // sets |*error| accordingly. Otherwise does nothing. Returns |op_result|. |
| 200 | bool HandleOpResult(bool op_result, const char* op_type_name, |
| 201 | ErrorCode* error); |
| 202 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 203 | // Logs the progress of downloading/applying an update. |
| 204 | void LogProgress(const char* message_prefix); |
| 205 | |
| 206 | // Update overall progress metrics, log as necessary. |
| 207 | void UpdateOverallProgress(bool force_log, const char* message_prefix); |
| 208 | |
Andrew de los Reyes | 353777c | 2010-10-08 10:34:30 -0700 | [diff] [blame] | 209 | static bool IsIdempotentOperation( |
| 210 | const DeltaArchiveManifest_InstallOperation& op); |
| 211 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 212 | // Verifies that the expected source partition hashes (if present) match the |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 213 | // hashes for the current partitions. Returns true if there are no expected |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 214 | // hashes in the payload (e.g., if it's a new-style full update) or if the |
| 215 | // hashes match; returns false otherwise. |
| 216 | bool VerifySourcePartitions(); |
| 217 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 218 | // Returns true if enough of the delta file has been passed via Write() |
| 219 | // to be able to perform a given install operation. |
| 220 | bool CanPerformInstallOperation( |
| 221 | const DeltaArchiveManifest_InstallOperation& operation); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 222 | |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 223 | // Checks the integrity of the payload manifest. Returns true upon success, |
| 224 | // false otherwise. |
| 225 | ErrorCode ValidateManifest(); |
| 226 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 227 | // Validates that the hash of the blobs corresponding to the given |operation| |
| 228 | // matches what's specified in the manifest in the payload. |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 229 | // Returns ErrorCode::kSuccess on match or a suitable error code otherwise. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 230 | ErrorCode ValidateOperationHash( |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 231 | const DeltaArchiveManifest_InstallOperation& operation); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 232 | |
| 233 | // Interprets the given |protobuf| as a DeltaArchiveManifest protocol buffer |
| 234 | // of the given protobuf_length and verifies that the signed hash of the |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 235 | // metadata matches what's specified in the install plan from Omaha. |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 236 | // Returns ErrorCode::kSuccess on match or a suitable error code otherwise. |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 237 | // This method must be called before any part of the |protobuf| is parsed |
| 238 | // so that a man-in-the-middle attack on the SSL connection to the payload |
| 239 | // server doesn't exploit any vulnerability in the code that parses the |
| 240 | // protocol buffer. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 241 | ErrorCode ValidateMetadataSignature(const char* protobuf, |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 242 | uint64_t protobuf_length); |
| 243 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 244 | // Returns true on success. |
| 245 | bool PerformInstallOperation( |
| 246 | const DeltaArchiveManifest_InstallOperation& operation); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 247 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 248 | // These perform a specific type of operation and return true on success. |
| 249 | bool PerformReplaceOperation( |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 250 | const DeltaArchiveManifest_InstallOperation& operation, |
| 251 | bool is_kernel_partition); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 252 | bool PerformMoveOperation( |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 253 | const DeltaArchiveManifest_InstallOperation& operation, |
| 254 | bool is_kernel_partition); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 255 | bool PerformBsdiffOperation( |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 256 | const DeltaArchiveManifest_InstallOperation& operation, |
| 257 | bool is_kernel_partition); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 258 | |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 259 | // Returns true if the payload signature message has been extracted from |
| 260 | // |operation|, false otherwise. |
| 261 | bool ExtractSignatureMessage( |
| 262 | const DeltaArchiveManifest_InstallOperation& operation); |
| 263 | |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 264 | // Updates the hash calculator with the bytes in |buffer_|. Then discard the |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 265 | // content, ensuring that memory is being deallocated. If |do_advance_offset|, |
| 266 | // advances the internal offset counter accordingly. |
| 267 | void DiscardBuffer(bool do_advance_offset); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 268 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 269 | // Checkpoints the update progress into persistent storage to allow this |
| 270 | // update attempt to be resumed after reboot. |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 271 | bool CheckpointUpdateProgress(); |
| 272 | |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 273 | // Primes the required update state. Returns true if the update state was |
| 274 | // successfully initialized to a saved resume state or if the update is a new |
| 275 | // update. Returns false otherwise. |
| 276 | bool PrimeUpdateState(); |
| 277 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 278 | // Sends UMA statistics for the given error code. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 279 | void SendUmaStat(ErrorCode code); |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 280 | |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 281 | // If the Omaha response contains a public RSA key and we're allowed |
| 282 | // to use it (e.g. if we're in developer mode), extract the key from |
| 283 | // the response and store it in a temporary file and return true. In |
| 284 | // the affirmative the path to the temporary file is stored in |
| 285 | // |out_tmp_key| and it is the responsibility of the caller to clean |
| 286 | // it up. |
| 287 | bool GetPublicKeyFromResponse(base::FilePath *out_tmp_key); |
| 288 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 289 | // Update Engine preference store. |
| 290 | PrefsInterface* prefs_; |
| 291 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 292 | // Global context of the system. |
| 293 | SystemState* system_state_; |
| 294 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 295 | // Install Plan based on Omaha Response. |
| 296 | InstallPlan* install_plan_; |
| 297 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 298 | // File descriptor of open device. |
| 299 | int fd_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 300 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 301 | // File descriptor of the kernel device |
| 302 | int kernel_fd_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 303 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 304 | std::string path_; // Path that fd_ refers to. |
| 305 | std::string kernel_path_; // Path that kernel_fd_ refers to. |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 306 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 307 | DeltaArchiveManifest manifest_; |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 308 | bool manifest_parsed_; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 309 | bool manifest_valid_; |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 310 | uint64_t metadata_size_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 311 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 312 | // Index of the next operation to perform in the manifest. |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 313 | size_t next_operation_num_; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 314 | |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 315 | // A buffer used for accumulating downloaded data. Initially, it stores the |
| 316 | // payload metadata; once that's downloaded and parsed, it stores data for the |
| 317 | // next update operation. |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 318 | std::vector<char> buffer_; |
| 319 | // Offset of buffer_ in the binary blobs section of the update. |
| 320 | uint64_t buffer_offset_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 321 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 322 | // Last |buffer_offset_| value updated as part of the progress update. |
| 323 | uint64_t last_updated_buffer_offset_; |
| 324 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 325 | // The block size (parsed from the manifest). |
| 326 | uint32_t block_size_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 327 | |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 328 | // Calculates the payload hash. |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 329 | OmahaHashCalculator hash_calculator_; |
| 330 | |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 331 | // Saves the signed hash context. |
| 332 | std::string signed_hash_context_; |
| 333 | |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 334 | // Signatures message blob extracted directly from the payload. |
| 335 | std::vector<char> signatures_message_data_; |
| 336 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 337 | // The public key to be used. Provided as a member so that tests can |
| 338 | // override with test keys. |
| 339 | std::string public_key_path_; |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 340 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 341 | // The number of bytes received so far, used for progress tracking. |
| 342 | size_t total_bytes_received_; |
| 343 | |
| 344 | // The number rootfs and total operations in a payload, once we know them. |
| 345 | size_t num_rootfs_operations_; |
| 346 | size_t num_total_operations_; |
| 347 | |
| 348 | // An overall progress counter, which should reflect both download progress |
| 349 | // and the ratio of applied operations. Range is 0-100. |
| 350 | unsigned overall_progress_; |
| 351 | |
| 352 | // The last progress chunk recorded. |
| 353 | unsigned last_progress_chunk_; |
| 354 | |
| 355 | // The timeout after which we should force emitting a progress log (constant), |
| 356 | // and the actual point in time for the next forced log to be emitted. |
| 357 | const base::TimeDelta forced_progress_log_wait_; |
| 358 | base::Time forced_progress_log_time_; |
| 359 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 360 | DISALLOW_COPY_AND_ASSIGN(DeltaPerformer); |
| 361 | }; |
| 362 | |
| 363 | } // namespace chromeos_update_engine |
| 364 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 365 | #endif // UPDATE_ENGINE_DELTA_PERFORMER_H_ |