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