Home | History | Annotate | Download | only in payload_consumer
      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 //
     16 
     17 #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
     18 #define UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
     19 
     20 #include <string>
     21 #include <vector>
     22 
     23 #include <base/macros.h>
     24 #include <brillo/secure_blob.h>
     25 
     26 #include "update_engine/common/action.h"
     27 #include "update_engine/common/boot_control_interface.h"
     28 
     29 // InstallPlan is a simple struct that contains relevant info for many
     30 // parts of the update system about the install that should happen.
     31 namespace chromeos_update_engine {
     32 
     33 enum class InstallPayloadType {
     34   kUnknown,
     35   kFull,
     36   kDelta,
     37 };
     38 
     39 std::string InstallPayloadTypeToString(InstallPayloadType type);
     40 
     41 struct InstallPlan {
     42   InstallPlan() = default;
     43 
     44   bool operator==(const InstallPlan& that) const;
     45   bool operator!=(const InstallPlan& that) const;
     46 
     47   void Dump() const;
     48 
     49   // Load the |source_path| and |target_path| of all |partitions| based on the
     50   // |source_slot| and |target_slot| if available. Returns whether it succeeded
     51   // to load all the partitions for the valid slots.
     52   bool LoadPartitionsFromSlots(BootControlInterface* boot_control);
     53 
     54   bool is_resume{false};
     55   InstallPayloadType payload_type{InstallPayloadType::kUnknown};
     56   std::string download_url;  // url to download from
     57   std::string version;       // version we are installing.
     58 
     59   uint64_t payload_size{0};              // size of the payload
     60   std::string payload_hash;              // SHA256 hash of the payload
     61   uint64_t metadata_size{0};             // size of the metadata
     62   std::string metadata_signature;        // signature of the  metadata
     63 
     64   // The partition slots used for the update.
     65   BootControlInterface::Slot source_slot{BootControlInterface::kInvalidSlot};
     66   BootControlInterface::Slot target_slot{BootControlInterface::kInvalidSlot};
     67 
     68   // The vector below is used for partition verification. The flow is:
     69   //
     70   // 1. FilesystemVerifierAction computes and fills in the source partition
     71   // hash based on the guessed source size for delta major version 1 updates.
     72   //
     73   // 2. DownloadAction verifies the source partition sizes and hashes against
     74   // the expected values transmitted in the update manifest. It fills in the
     75   // expected target partition sizes and hashes based on the manifest.
     76   //
     77   // 3. FilesystemVerifierAction computes and verifies the applied partition
     78   // sizes and hashes against the expected values in target_partition_hashes.
     79   struct Partition {
     80     bool operator==(const Partition& that) const;
     81 
     82     // The name of the partition.
     83     std::string name;
     84 
     85     std::string source_path;
     86     uint64_t source_size{0};
     87     brillo::Blob source_hash;
     88 
     89     std::string target_path;
     90     uint64_t target_size{0};
     91     brillo::Blob target_hash;
     92 
     93     // Whether we should run the postinstall script from this partition and the
     94     // postinstall parameters.
     95     bool run_postinstall{false};
     96     std::string postinstall_path;
     97     std::string filesystem_type;
     98     bool postinstall_optional{false};
     99   };
    100   std::vector<Partition> partitions;
    101 
    102   // True if payload hash checks are mandatory based on the system state and
    103   // the Omaha response.
    104   bool hash_checks_mandatory{false};
    105 
    106   // True if Powerwash is required on reboot after applying the payload.
    107   // False otherwise.
    108   bool powerwash_required{false};
    109 
    110   // If not blank, a base-64 encoded representation of the PEM-encoded
    111   // public key in the response.
    112   std::string public_key_rsa;
    113 };
    114 
    115 class InstallPlanAction;
    116 
    117 template<>
    118 class ActionTraits<InstallPlanAction> {
    119  public:
    120   // Takes the install plan as input
    121   typedef InstallPlan InputObjectType;
    122   // Passes the install plan as output
    123   typedef InstallPlan OutputObjectType;
    124 };
    125 
    126 // Basic action that only receives and sends Install Plans.
    127 // Can be used to construct an Install Plan to send to any other Action that
    128 // accept an InstallPlan.
    129 class InstallPlanAction : public Action<InstallPlanAction> {
    130  public:
    131   InstallPlanAction() {}
    132   explicit InstallPlanAction(const InstallPlan& install_plan):
    133     install_plan_(install_plan) {}
    134 
    135   void PerformAction() override {
    136     if (HasOutputPipe()) {
    137       SetOutputObject(install_plan_);
    138     }
    139     processor_->ActionComplete(this, ErrorCode::kSuccess);
    140   }
    141 
    142   InstallPlan* install_plan() { return &install_plan_; }
    143 
    144   static std::string StaticType() { return "InstallPlanAction"; }
    145   std::string Type() const override { return StaticType(); }
    146 
    147   typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
    148   typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
    149 
    150  private:
    151   InstallPlan install_plan_;
    152 
    153   DISALLOW_COPY_AND_ASSIGN(InstallPlanAction);
    154 };
    155 
    156 }  // namespace chromeos_update_engine
    157 
    158 #endif  // UPDATE_ENGINE_PAYLOAD_CONSUMER_INSTALL_PLAN_H_
    159