| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2011 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 | // | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ | 
|  | 18 | #define UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | #include <string> | 
| Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 21 | #include <vector> | 
|  | 22 |  | 
| Ben Chan | 05735a1 | 2014-09-03 07:48:22 -0700 | [diff] [blame] | 23 | #include <base/macros.h> | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 24 | #include <brillo/secure_blob.h> | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 25 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 26 | #include "update_engine/common/action.h" | 
|  | 27 | #include "update_engine/common/boot_control_interface.h" | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 28 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 29 | // InstallPlan is a simple struct that contains relevant info for many | 
|  | 30 | // parts of the update system about the install that should happen. | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 31 | namespace chromeos_update_engine { | 
|  | 32 |  | 
|  | 33 | struct InstallPlan { | 
| Darin Petkov | 7ed561b | 2011-10-04 02:59:03 -0700 | [diff] [blame] | 34 | InstallPlan(bool is_resume, | 
| Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 35 | bool is_full_update, | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | const std::string& url, | 
| Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 37 | uint64_t payload_size, | 
|  | 38 | const std::string& payload_hash, | 
| Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 39 | uint64_t metadata_size, | 
|  | 40 | const std::string& metadata_signature, | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 41 | const std::string& public_key_rsa); | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 42 |  | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 43 | // Default constructor. | 
|  | 44 | InstallPlan() = default; | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | bool operator==(const InstallPlan& that) const; | 
|  | 47 | bool operator!=(const InstallPlan& that) const; | 
|  | 48 |  | 
|  | 49 | void Dump() const; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 50 |  | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 51 | // Load the |source_path| and |target_path| of all |partitions| based on the | 
|  | 52 | // |source_slot| and |target_slot| if available. Returns whether it succeeded | 
|  | 53 | // to load all the partitions for the valid slots. | 
| Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 54 | bool LoadPartitionsFromSlots(BootControlInterface* boot_control); | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 55 |  | 
|  | 56 | bool is_resume{false}; | 
|  | 57 | bool is_full_update{false}; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 58 | std::string download_url;  // url to download from | 
| Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 59 | std::string version;       // version we are installing. | 
| Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 60 |  | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 61 | uint64_t payload_size{0};              // size of the payload | 
|  | 62 | std::string payload_hash;              // SHA256 hash of the payload | 
|  | 63 | uint64_t metadata_size{0};             // size of the metadata | 
| Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 64 | std::string metadata_signature;        // signature of the  metadata | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 65 |  | 
|  | 66 | // The partition slots used for the update. | 
|  | 67 | BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot}; | 
|  | 68 | BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot}; | 
|  | 69 |  | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 70 | // The vector below is used for partition verification. The flow is: | 
| Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 71 | // | 
| Allie Wood | eb9e6d8 | 2015-04-17 13:55:30 -0700 | [diff] [blame] | 72 | // 1. FilesystemVerifierAction computes and fills in the source partition | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 73 | // hash based on the guessed source size for delta major version 1 updates. | 
| Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 74 | // | 
|  | 75 | // 2. DownloadAction verifies the source partition sizes and hashes against | 
|  | 76 | // the expected values transmitted in the update manifest. It fills in the | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 77 | // expected target partition sizes and hashes based on the manifest. | 
| Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 78 | // | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 79 | // 3. FilesystemVerifierAction computes and verifies the applied partition | 
|  | 80 | // sizes and hashes against the expected values in target_partition_hashes. | 
|  | 81 | struct Partition { | 
|  | 82 | bool operator==(const Partition& that) const; | 
|  | 83 |  | 
|  | 84 | // The name of the partition. | 
|  | 85 | std::string name; | 
|  | 86 |  | 
|  | 87 | std::string source_path; | 
|  | 88 | uint64_t source_size{0}; | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 89 | brillo::Blob source_hash; | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 90 |  | 
|  | 91 | std::string target_path; | 
|  | 92 | uint64_t target_size{0}; | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 93 | brillo::Blob target_hash; | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 94 |  | 
|  | 95 | // Whether we should run the postinstall script from this partition. | 
|  | 96 | bool run_postinstall{false}; | 
|  | 97 | }; | 
|  | 98 | std::vector<Partition> partitions; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 99 |  | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 100 | // True if payload hash checks are mandatory based on the system state and | 
|  | 101 | // the Omaha response. | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 102 | bool hash_checks_mandatory{false}; | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 103 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 104 | // True if Powerwash is required on reboot after applying the payload. | 
|  | 105 | // False otherwise. | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 106 | bool powerwash_required{false}; | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 107 |  | 
|  | 108 | // If not blank, a base-64 encoded representation of the PEM-encoded | 
|  | 109 | // public key in the response. | 
|  | 110 | std::string public_key_rsa; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 111 | }; | 
|  | 112 |  | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 113 | class InstallPlanAction; | 
|  | 114 |  | 
|  | 115 | template<> | 
|  | 116 | class ActionTraits<InstallPlanAction> { | 
|  | 117 | public: | 
|  | 118 | // Takes the install plan as input | 
|  | 119 | typedef InstallPlan InputObjectType; | 
|  | 120 | // Passes the install plan as output | 
|  | 121 | typedef InstallPlan OutputObjectType; | 
|  | 122 | }; | 
|  | 123 |  | 
|  | 124 | // Basic action that only receives and sends Install Plans. | 
|  | 125 | // Can be used to construct an Install Plan to send to any other Action that | 
|  | 126 | // accept an InstallPlan. | 
|  | 127 | class InstallPlanAction : public Action<InstallPlanAction> { | 
|  | 128 | public: | 
|  | 129 | InstallPlanAction() {} | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 130 | explicit InstallPlanAction(const InstallPlan& install_plan): | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 131 | install_plan_(install_plan) {} | 
|  | 132 |  | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 133 | void PerformAction() override { | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 134 | if (HasOutputPipe()) { | 
|  | 135 | SetOutputObject(install_plan_); | 
|  | 136 | } | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 137 | processor_->ActionComplete(this, ErrorCode::kSuccess); | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 138 | } | 
|  | 139 |  | 
| Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 140 | InstallPlan* install_plan() { return &install_plan_; } | 
|  | 141 |  | 
|  | 142 | static std::string StaticType() { return "InstallPlanAction"; } | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 143 | std::string Type() const override { return StaticType(); } | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 144 |  | 
|  | 145 | typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType; | 
|  | 146 | typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType; | 
|  | 147 |  | 
|  | 148 | private: | 
|  | 149 | InstallPlan install_plan_; | 
|  | 150 |  | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 151 | DISALLOW_COPY_AND_ASSIGN(InstallPlanAction); | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 152 | }; | 
|  | 153 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 154 | }  // namespace chromeos_update_engine | 
|  | 155 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 156 | #endif  // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ |