| 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 |  | 
| Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 33 | enum class InstallPayloadType { | 
 | 34 |   kUnknown, | 
 | 35 |   kFull, | 
 | 36 |   kDelta, | 
 | 37 | }; | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 38 |  | 
| Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 39 | std::string InstallPayloadTypeToString(InstallPayloadType type); | 
 | 40 |  | 
 | 41 | struct InstallPlan { | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 42 |   InstallPlan() = default; | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 43 |  | 
 | 44 |   bool operator==(const InstallPlan& that) const; | 
 | 45 |   bool operator!=(const InstallPlan& that) const; | 
 | 46 |  | 
 | 47 |   void Dump() const; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 48 |  | 
| Yifan Hong | 1d9077f | 2018-12-07 12:09:37 -0800 | [diff] [blame] | 49 |   // Loads the |source_path| and |target_path| of all |partitions| based on the | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 50 |   // |source_slot| and |target_slot| if available. Returns whether it succeeded | 
 | 51 |   // to load all the partitions for the valid slots. | 
| Alex Deymo | 706a5ab | 2015-11-23 17:48:30 -0300 | [diff] [blame] | 52 |   bool LoadPartitionsFromSlots(BootControlInterface* boot_control); | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 53 |  | 
 | 54 |   bool is_resume{false}; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 55 |   std::string download_url;  // url to download from | 
| Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 56 |   std::string version;       // version we are installing. | 
| Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 57 |   // system version, if present and separate from version | 
 | 58 |   std::string system_version; | 
| Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 59 |  | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 60 |   struct Payload { | 
 | 61 |     uint64_t size = 0;               // size of the payload | 
 | 62 |     uint64_t metadata_size = 0;      // size of the metadata | 
 | 63 |     std::string metadata_signature;  // signature of the metadata in base64 | 
 | 64 |     brillo::Blob hash;               // SHA256 hash of the payload | 
| Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 65 |     InstallPayloadType type{InstallPayloadType::kUnknown}; | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 66 |     // Only download manifest and fill in partitions in install plan without | 
 | 67 |     // apply the payload if true. Will be set by DownloadAction when resuming | 
 | 68 |     // multi-payload. | 
 | 69 |     bool already_applied = false; | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 70 |  | 
 | 71 |     bool operator==(const Payload& that) const { | 
 | 72 |       return size == that.size && metadata_size == that.metadata_size && | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 73 |              metadata_signature == that.metadata_signature && | 
| Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 74 |              hash == that.hash && type == that.type && | 
 | 75 |              already_applied == that.already_applied; | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 76 |     } | 
 | 77 |   }; | 
 | 78 |   std::vector<Payload> payloads; | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 79 |  | 
 | 80 |   // The partition slots used for the update. | 
 | 81 |   BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot}; | 
 | 82 |   BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot}; | 
 | 83 |  | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 84 |   // The vector below is used for partition verification. The flow is: | 
| Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 85 |   // | 
| Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 86 |   // 1. DownloadAction fills in the expected source and target partition sizes | 
 | 87 |   // and hashes based on the manifest. | 
| Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 88 |   // | 
| Sen Jiang | fef85fd | 2016-03-25 15:32:49 -0700 | [diff] [blame] | 89 |   // 2. FilesystemVerifierAction computes and verifies the partition sizes and | 
 | 90 |   // hashes against the expected values. | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 91 |   struct Partition { | 
 | 92 |     bool operator==(const Partition& that) const; | 
 | 93 |  | 
 | 94 |     // The name of the partition. | 
 | 95 |     std::string name; | 
 | 96 |  | 
 | 97 |     std::string source_path; | 
 | 98 |     uint64_t source_size{0}; | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 99 |     brillo::Blob source_hash; | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 100 |  | 
 | 101 |     std::string target_path; | 
 | 102 |     uint64_t target_size{0}; | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 103 |     brillo::Blob target_hash; | 
| Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 104 |     uint32_t block_size{0}; | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 105 |  | 
| Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 106 |     // Whether we should run the postinstall script from this partition and the | 
 | 107 |     // postinstall parameters. | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 108 |     bool run_postinstall{false}; | 
| Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 109 |     std::string postinstall_path; | 
 | 110 |     std::string filesystem_type; | 
| Alex Deymo | 5b91c6b | 2016-08-04 20:33:36 -0700 | [diff] [blame] | 111 |     bool postinstall_optional{false}; | 
| Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 112 |  | 
 | 113 |     // Verity hash tree and FEC config. See update_metadata.proto for details. | 
 | 114 |     // All offsets and sizes are in bytes. | 
 | 115 |     uint64_t hash_tree_data_offset{0}; | 
 | 116 |     uint64_t hash_tree_data_size{0}; | 
 | 117 |     uint64_t hash_tree_offset{0}; | 
 | 118 |     uint64_t hash_tree_size{0}; | 
 | 119 |     std::string hash_tree_algorithm; | 
 | 120 |     brillo::Blob hash_tree_salt; | 
 | 121 |  | 
 | 122 |     uint64_t fec_data_offset{0}; | 
 | 123 |     uint64_t fec_data_size{0}; | 
 | 124 |     uint64_t fec_offset{0}; | 
 | 125 |     uint64_t fec_size{0}; | 
 | 126 |     uint32_t fec_roots{0}; | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 127 |   }; | 
 | 128 |   std::vector<Partition> partitions; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 129 |  | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 130 |   // True if payload hash checks are mandatory based on the system state and | 
 | 131 |   // the Omaha response. | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 132 |   bool hash_checks_mandatory{false}; | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 133 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 134 |   // True if Powerwash is required on reboot after applying the payload. | 
 | 135 |   // False otherwise. | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 136 |   bool powerwash_required{false}; | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 137 |  | 
| Sen Jiang | 02c4942 | 2017-10-31 15:14:11 -0700 | [diff] [blame] | 138 |   // True if the updated slot should be marked active on success. | 
 | 139 |   // False otherwise. | 
 | 140 |   bool switch_slot_on_reboot{true}; | 
 | 141 |  | 
 | 142 |   // True if the update should run its post-install step. | 
 | 143 |   // False otherwise. | 
 | 144 |   bool run_post_install{true}; | 
 | 145 |  | 
| Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 146 |   // True if this update is a rollback. | 
 | 147 |   bool is_rollback{false}; | 
 | 148 |  | 
| Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 149 |   // True if this rollback should preserve some system data. | 
 | 150 |   bool rollback_data_save_requested{false}; | 
 | 151 |  | 
| Sen Jiang | 3eeaf7d | 2018-10-11 13:55:32 -0700 | [diff] [blame] | 152 |   // True if the update should write verity. | 
 | 153 |   // False otherwise. | 
 | 154 |   bool write_verity{true}; | 
 | 155 |  | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 156 |   // If not blank, a base-64 encoded representation of the PEM-encoded | 
 | 157 |   // public key in the response. | 
 | 158 |   std::string public_key_rsa; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 159 | }; | 
 | 160 |  | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 161 | class InstallPlanAction; | 
 | 162 |  | 
| Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 163 | template <> | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 164 | class ActionTraits<InstallPlanAction> { | 
 | 165 |  public: | 
 | 166 |   // Takes the install plan as input | 
 | 167 |   typedef InstallPlan InputObjectType; | 
 | 168 |   // Passes the install plan as output | 
 | 169 |   typedef InstallPlan OutputObjectType; | 
 | 170 | }; | 
 | 171 |  | 
 | 172 | // Basic action that only receives and sends Install Plans. | 
 | 173 | // Can be used to construct an Install Plan to send to any other Action that | 
 | 174 | // accept an InstallPlan. | 
 | 175 | class InstallPlanAction : public Action<InstallPlanAction> { | 
 | 176 |  public: | 
 | 177 |   InstallPlanAction() {} | 
| Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 178 |   explicit InstallPlanAction(const InstallPlan& install_plan) | 
 | 179 |       : install_plan_(install_plan) {} | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 180 |  | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 181 |   void PerformAction() override { | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 182 |     if (HasOutputPipe()) { | 
 | 183 |       SetOutputObject(install_plan_); | 
 | 184 |     } | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 185 |     processor_->ActionComplete(this, ErrorCode::kSuccess); | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 186 |   } | 
 | 187 |  | 
| Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 188 |   InstallPlan* install_plan() { return &install_plan_; } | 
 | 189 |  | 
 | 190 |   static std::string StaticType() { return "InstallPlanAction"; } | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 191 |   std::string Type() const override { return StaticType(); } | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 192 |  | 
 | 193 |   typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType; | 
 | 194 |   typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType; | 
 | 195 |  | 
 | 196 |  private: | 
 | 197 |   InstallPlan install_plan_; | 
 | 198 |  | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 199 |   DISALLOW_COPY_AND_ASSIGN(InstallPlanAction); | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 200 | }; | 
 | 201 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 202 | }  // namespace chromeos_update_engine | 
 | 203 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 204 | #endif  // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_ |