| 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 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/cros/omaha_response_handler_action.h" | 
| Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 18 |  | 
| Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame] | 19 | #include <limits> | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 20 | #include <string> | 
| Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 21 |  | 
 | 22 | #include <base/logging.h> | 
| Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 23 | #include <base/strings/string_number_conversions.h> | 
| Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 24 | #include <base/version.h> | 
| Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 25 | #include <policy/device_policy.h> | 
| Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 26 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 27 | #include "update_engine/common/constants.h" | 
 | 28 | #include "update_engine/common/hardware_interface.h" | 
 | 29 | #include "update_engine/common/prefs_interface.h" | 
 | 30 | #include "update_engine/common/utils.h" | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 31 | #include "update_engine/cros/connection_manager_interface.h" | 
 | 32 | #include "update_engine/cros/omaha_request_params.h" | 
 | 33 | #include "update_engine/cros/payload_state_interface.h" | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 34 | #include "update_engine/payload_consumer/delta_performer.h" | 
| Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 35 | #include "update_engine/update_manager/policy.h" | 
 | 36 | #include "update_engine/update_manager/update_manager.h" | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 |  | 
| Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 38 | using chromeos_update_manager::kRollforwardInfinity; | 
| Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 39 | using chromeos_update_manager::Policy; | 
 | 40 | using chromeos_update_manager::UpdateManager; | 
| Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame] | 41 | using std::numeric_limits; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 42 | using std::string; | 
 | 43 |  | 
 | 44 | namespace chromeos_update_engine { | 
 | 45 |  | 
| Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 46 | OmahaResponseHandlerAction::OmahaResponseHandlerAction( | 
 | 47 |     SystemState* system_state) | 
| Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 48 |     : system_state_(system_state), | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 49 |       deadline_file_(constants::kOmahaResponseDeadlineFile) {} | 
| Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 50 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 51 | void OmahaResponseHandlerAction::PerformAction() { | 
 | 52 |   CHECK(HasInputObject()); | 
 | 53 |   ScopedActionCompleter completer(processor_, this); | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 54 |   const OmahaResponse& response = GetInputObject(); | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 55 |   if (!response.update_exists) { | 
 | 56 |     LOG(INFO) << "There are no updates. Aborting."; | 
| Sen Jiang | 3978ddd | 2018-03-22 18:05:44 -0700 | [diff] [blame] | 57 |     completer.set_code(ErrorCode::kNoUpdate); | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 58 |     return; | 
 | 59 |   } | 
| Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 60 |  | 
 | 61 |   // All decisions as to which URL should be used have already been done. So, | 
| Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 62 |   // make the current URL as the download URL. | 
 | 63 |   string current_url = system_state_->payload_state()->GetCurrentUrl(); | 
 | 64 |   if (current_url.empty()) { | 
 | 65 |     // This shouldn't happen as we should always supply the HTTPS backup URL. | 
 | 66 |     // Handling this anyway, just in case. | 
 | 67 |     LOG(ERROR) << "There are no suitable URLs in the response to use."; | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 68 |     completer.set_code(ErrorCode::kOmahaResponseInvalid); | 
| Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 69 |     return; | 
 | 70 |   } | 
 | 71 |  | 
| Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 72 |   // This is the url to the first package, not all packages. | 
| Jae Hoon Kim | 694eeb0 | 2020-06-01 14:24:08 -0700 | [diff] [blame] | 73 |   // (For updates): All |Action|s prior to this must pass in non-excluded URLs | 
 | 74 |   // within the |OmahaResponse|, reference exlusion logic in | 
 | 75 |   // |OmahaRequestAction| and keep the enforcement of exclusions for updates. | 
| Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 76 |   install_plan_.download_url = current_url; | 
| Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 77 |   install_plan_.version = response.version; | 
| Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 78 |  | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 79 |   OmahaRequestParams* const params = system_state_->request_params(); | 
 | 80 |   PayloadStateInterface* const payload_state = system_state_->payload_state(); | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 81 |  | 
 | 82 |   // If we're using p2p to download and there is a local peer, use it. | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 83 |   if (payload_state->GetUsingP2PForDownloading() && | 
 | 84 |       !payload_state->GetP2PUrl().empty()) { | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 85 |     LOG(INFO) << "Replacing URL " << install_plan_.download_url | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 86 |               << " with local URL " << payload_state->GetP2PUrl() | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 87 |               << " since p2p is enabled."; | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 88 |     install_plan_.download_url = payload_state->GetP2PUrl(); | 
 | 89 |     payload_state->SetUsingP2PForDownloading(true); | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 90 |   } | 
 | 91 |  | 
| Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 92 |   // Fill up the other properties based on the response. | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 93 |   string update_check_response_hash; | 
 | 94 |   for (const auto& package : response.packages) { | 
 | 95 |     brillo::Blob raw_hash; | 
 | 96 |     if (!base::HexStringToBytes(package.hash, &raw_hash)) { | 
 | 97 |       LOG(ERROR) << "Failed to convert payload hash from hex string to bytes: " | 
 | 98 |                  << package.hash; | 
 | 99 |       completer.set_code(ErrorCode::kOmahaResponseInvalid); | 
 | 100 |       return; | 
 | 101 |     } | 
 | 102 |     install_plan_.payloads.push_back( | 
| Jae Hoon Kim | 8da11e2 | 2019-12-23 11:26:17 -0800 | [diff] [blame] | 103 |         {.payload_urls = package.payload_urls, | 
 | 104 |          .size = package.size, | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 105 |          .metadata_size = package.metadata_size, | 
 | 106 |          .metadata_signature = package.metadata_signature, | 
| Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 107 |          .hash = raw_hash, | 
 | 108 |          .type = package.is_delta ? InstallPayloadType::kDelta | 
 | 109 |                                   : InstallPayloadType::kFull}); | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 110 |     update_check_response_hash += package.hash + ":"; | 
| Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 111 |   } | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 112 |   install_plan_.public_key_rsa = response.public_key_rsa; | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 113 |   install_plan_.hash_checks_mandatory = AreHashChecksMandatory(response); | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 114 |   install_plan_.is_resume = DeltaPerformer::CanResumeUpdate( | 
 | 115 |       system_state_->prefs(), update_check_response_hash); | 
| Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 116 |   if (install_plan_.is_resume) { | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 117 |     payload_state->UpdateResumed(); | 
| Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 118 |   } else { | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 119 |     payload_state->UpdateRestarted(); | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 120 |     LOG_IF(WARNING, | 
 | 121 |            !DeltaPerformer::ResetUpdateProgress(system_state_->prefs(), false)) | 
| Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 122 |         << "Unable to reset the update progress."; | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 123 |     LOG_IF(WARNING, | 
 | 124 |            !system_state_->prefs()->SetString(kPrefsUpdateCheckResponseHash, | 
 | 125 |                                               update_check_response_hash)) | 
| Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 126 |         << "Unable to save the update check response hash."; | 
 | 127 |   } | 
 | 128 |  | 
| Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 129 |   if (params->is_install()) { | 
 | 130 |     install_plan_.target_slot = system_state_->boot_control()->GetCurrentSlot(); | 
 | 131 |     install_plan_.source_slot = BootControlInterface::kInvalidSlot; | 
 | 132 |   } else { | 
 | 133 |     install_plan_.source_slot = system_state_->boot_control()->GetCurrentSlot(); | 
 | 134 |     install_plan_.target_slot = install_plan_.source_slot == 0 ? 1 : 0; | 
 | 135 |   } | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 136 |  | 
| Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 137 |   // The Omaha response doesn't include the channel name for this image, so we | 
 | 138 |   // use the download_channel we used during the request to tag the target slot. | 
 | 139 |   // This will be used in the next boot to know the channel the image was | 
 | 140 |   // downloaded from. | 
 | 141 |   string current_channel_key = | 
 | 142 |       kPrefsChannelOnSlotPrefix + std::to_string(install_plan_.target_slot); | 
 | 143 |   system_state_->prefs()->SetString(current_channel_key, | 
 | 144 |                                     params->download_channel()); | 
 | 145 |  | 
| Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 146 |   // Checking whether device is able to boot up the returned rollback image. | 
 | 147 |   if (response.is_rollback) { | 
 | 148 |     if (!params->rollback_allowed()) { | 
 | 149 |       LOG(ERROR) << "Received rollback image but rollback is not allowed."; | 
 | 150 |       completer.set_code(ErrorCode::kOmahaResponseInvalid); | 
 | 151 |       return; | 
 | 152 |     } | 
| Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 153 |  | 
 | 154 |     // Calculate the values on the version values on current device. | 
| Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 155 |     auto min_kernel_key_version = static_cast<uint32_t>( | 
 | 156 |         system_state_->hardware()->GetMinKernelKeyVersion()); | 
 | 157 |     auto min_firmware_key_version = static_cast<uint32_t>( | 
 | 158 |         system_state_->hardware()->GetMinFirmwareKeyVersion()); | 
| Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 159 |  | 
| Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame] | 160 |     uint32_t kernel_key_version = | 
 | 161 |         static_cast<uint32_t>(response.rollback_key_version.kernel_key) << 16 | | 
 | 162 |         static_cast<uint32_t>(response.rollback_key_version.kernel); | 
 | 163 |     uint32_t firmware_key_version = | 
 | 164 |         static_cast<uint32_t>(response.rollback_key_version.firmware_key) | 
 | 165 |             << 16 | | 
 | 166 |         static_cast<uint32_t>(response.rollback_key_version.firmware); | 
 | 167 |  | 
| Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 168 |     LOG(INFO) << "Rollback image versions:" | 
 | 169 |               << " device_kernel_key_version=" << min_kernel_key_version | 
 | 170 |               << " image_kernel_key_version=" << kernel_key_version | 
 | 171 |               << " device_firmware_key_version=" << min_firmware_key_version | 
 | 172 |               << " image_firmware_key_version=" << firmware_key_version; | 
 | 173 |  | 
| Zentaro Kavanagh | 0ff621c | 2018-07-13 13:06:56 -0700 | [diff] [blame] | 174 |     // Don't attempt a rollback if the versions are incompatible or the | 
 | 175 |     // target image does not specify the version information. | 
 | 176 |     if (kernel_key_version == numeric_limits<uint32_t>::max() || | 
 | 177 |         firmware_key_version == numeric_limits<uint32_t>::max() || | 
 | 178 |         kernel_key_version < min_kernel_key_version || | 
 | 179 |         firmware_key_version < min_firmware_key_version) { | 
| Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 180 |       LOG(ERROR) << "Device won't be able to boot up the rollback image."; | 
 | 181 |       completer.set_code(ErrorCode::kRollbackNotPossible); | 
 | 182 |       return; | 
 | 183 |     } | 
 | 184 |     install_plan_.is_rollback = true; | 
| Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 185 |     install_plan_.rollback_data_save_requested = | 
 | 186 |         params->rollback_data_save_requested(); | 
| Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 187 |   } | 
 | 188 |  | 
| Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 189 |   // Powerwash if either the response requires it or the parameters indicated | 
| Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 190 |   // powerwash (usually because there was a channel downgrade) and we are | 
 | 191 |   // downgrading the version. Enterprise rollback, indicated by | 
 | 192 |   // |response.is_rollback| is dealt with separately above. | 
| Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 193 |   if (response.powerwash_required) { | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 194 |     install_plan_.powerwash_required = true; | 
| Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 195 |   } else if (params->ShouldPowerwash() && !response.is_rollback) { | 
| Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 196 |     base::Version new_version(response.version); | 
 | 197 |     base::Version current_version(params->app_version()); | 
 | 198 |  | 
 | 199 |     if (!new_version.IsValid()) { | 
 | 200 |       LOG(WARNING) << "Not powerwashing," | 
 | 201 |                    << " the update's version number is unreadable." | 
 | 202 |                    << " Update's version number: " << response.version; | 
 | 203 |     } else if (!current_version.IsValid()) { | 
 | 204 |       LOG(WARNING) << "Not powerwashing," | 
 | 205 |                    << " the current version number is unreadable." | 
 | 206 |                    << " Current version number: " << params->app_version(); | 
 | 207 |     } else if (new_version < current_version) { | 
 | 208 |       install_plan_.powerwash_required = true; | 
| Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 209 |       // Always try to preserve enrollment and wifi data for enrolled devices. | 
 | 210 |       install_plan_.rollback_data_save_requested = | 
 | 211 |           system_state_ && system_state_->device_policy() && | 
 | 212 |           system_state_->device_policy()->IsEnterpriseEnrolled(); | 
| Miriam Polzer | ad67198 | 2020-04-23 16:25:58 +0200 | [diff] [blame] | 213 |     } | 
 | 214 |   } | 
| Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 215 |  | 
| Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 216 |   TEST_AND_RETURN(HasOutputPipe()); | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 217 |   if (HasOutputPipe()) | 
| Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 218 |     SetOutputObject(install_plan_); | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 219 |   LOG(INFO) << "Using this install plan:"; | 
| Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 220 |   install_plan_.Dump(); | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 221 |  | 
| Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 222 |   // Send the deadline data (if any) to Chrome through a file. This is a pretty | 
 | 223 |   // hacky solution but should be OK for now. | 
 | 224 |   // | 
| Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 225 |   // TODO(petkov): Re-architect this to avoid communication through a | 
| Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 226 |   // file. Ideally, we would include this information in D-Bus's GetStatus | 
| Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 227 |   // method and UpdateStatus signal. A potential issue is that update_engine may | 
 | 228 |   // be unresponsive during an update download. | 
| Alex Deymo | 6dd160a | 2015-10-09 18:45:14 -0700 | [diff] [blame] | 229 |   if (!deadline_file_.empty()) { | 
| Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 230 |     if (payload_state->GetRollbackHappened()) { | 
 | 231 |       // Don't do forced update if rollback has happened since the last update | 
 | 232 |       // check where policy was present. | 
 | 233 |       LOG(INFO) << "Not forcing update because a rollback happened."; | 
 | 234 |       utils::WriteFile(deadline_file_.c_str(), nullptr, 0); | 
 | 235 |     } else { | 
 | 236 |       utils::WriteFile(deadline_file_.c_str(), | 
 | 237 |                        response.deadline.data(), | 
 | 238 |                        response.deadline.size()); | 
 | 239 |     } | 
| Alex Deymo | 6dd160a | 2015-10-09 18:45:14 -0700 | [diff] [blame] | 240 |     chmod(deadline_file_.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); | 
 | 241 |   } | 
| Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 242 |  | 
| Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 243 |   // Check the generated install-plan with the Policy to confirm that | 
 | 244 |   // it can be applied at this time (or at all). | 
 | 245 |   UpdateManager* const update_manager = system_state_->update_manager(); | 
 | 246 |   CHECK(update_manager); | 
 | 247 |   auto ec = ErrorCode::kSuccess; | 
 | 248 |   update_manager->PolicyRequest( | 
 | 249 |       &Policy::UpdateCanBeApplied, &ec, &install_plan_); | 
 | 250 |   completer.set_code(ec); | 
| Zentaro Kavanagh | 0ef9a2f | 2018-07-02 12:05:07 -0700 | [diff] [blame] | 251 |  | 
 | 252 |   const auto allowed_milestones = params->rollback_allowed_milestones(); | 
 | 253 |   if (allowed_milestones > 0) { | 
 | 254 |     auto max_firmware_rollforward = numeric_limits<uint32_t>::max(); | 
 | 255 |     auto max_kernel_rollforward = numeric_limits<uint32_t>::max(); | 
 | 256 |  | 
 | 257 |     // Determine the version to update the max rollforward verified boot | 
 | 258 |     // value. | 
 | 259 |     OmahaResponse::RollbackKeyVersion version = | 
 | 260 |         response.past_rollback_key_version; | 
 | 261 |  | 
 | 262 |     // Determine the max rollforward values to be set in the TPM. | 
 | 263 |     max_firmware_rollforward = static_cast<uint32_t>(version.firmware_key) | 
 | 264 |                                    << 16 | | 
 | 265 |                                static_cast<uint32_t>(version.firmware); | 
 | 266 |     max_kernel_rollforward = static_cast<uint32_t>(version.kernel_key) << 16 | | 
 | 267 |                              static_cast<uint32_t>(version.kernel); | 
 | 268 |  | 
 | 269 |     // In the case that the value is 0xffffffff, log a warning because the | 
 | 270 |     // device should not be installing a rollback image without having version | 
 | 271 |     // information. | 
 | 272 |     if (max_firmware_rollforward == numeric_limits<uint32_t>::max() || | 
 | 273 |         max_kernel_rollforward == numeric_limits<uint32_t>::max()) { | 
 | 274 |       LOG(WARNING) | 
 | 275 |           << "Max rollforward values were not sent in rollback response: " | 
 | 276 |           << " max_kernel_rollforward=" << max_kernel_rollforward | 
 | 277 |           << " max_firmware_rollforward=" << max_firmware_rollforward | 
 | 278 |           << " rollback_allowed_milestones=" | 
 | 279 |           << params->rollback_allowed_milestones(); | 
 | 280 |     } else { | 
 | 281 |       LOG(INFO) << "Setting the max rollforward values: " | 
 | 282 |                 << " max_kernel_rollforward=" << max_kernel_rollforward | 
 | 283 |                 << " max_firmware_rollforward=" << max_firmware_rollforward | 
 | 284 |                 << " rollback_allowed_milestones=" | 
 | 285 |                 << params->rollback_allowed_milestones(); | 
 | 286 |       system_state_->hardware()->SetMaxKernelKeyRollforward( | 
 | 287 |           max_kernel_rollforward); | 
 | 288 |       // TODO(crbug/783998): Set max firmware rollforward when implemented. | 
 | 289 |     } | 
 | 290 |   } else { | 
 | 291 |     LOG(INFO) << "Rollback is not allowed. Setting max rollforward values" | 
 | 292 |               << " to infinity"; | 
 | 293 |     // When rollback is not allowed, explicitly set the max roll forward to | 
 | 294 |     // infinity. | 
 | 295 |     system_state_->hardware()->SetMaxKernelKeyRollforward(kRollforwardInfinity); | 
 | 296 |     // TODO(crbug/783998): Set max firmware rollforward when implemented. | 
 | 297 |   } | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 298 | } | 
 | 299 |  | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 300 | bool OmahaResponseHandlerAction::AreHashChecksMandatory( | 
 | 301 |     const OmahaResponse& response) { | 
| David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 302 |   // We sometimes need to waive the hash checks in order to download from | 
 | 303 |   // sources that don't provide hashes, such as dev server. | 
 | 304 |   // At this point UpdateAttempter::IsAnyUpdateSourceAllowed() has already been | 
 | 305 |   // checked, so an unofficial update URL won't get this far unless it's OK to | 
 | 306 |   // use without a hash. Additionally, we want to always waive hash checks on | 
 | 307 |   // unofficial builds (i.e. dev/test images). | 
 | 308 |   // The end result is this: | 
 | 309 |   //  * Base image: | 
 | 310 |   //    - Official URLs require a hash. | 
 | 311 |   //    - Unofficial URLs only get this far if the IsAnyUpdateSourceAllowed() | 
 | 312 |   //      devmode/debugd checks pass, in which case the hash is waived. | 
 | 313 |   //  * Dev/test image: | 
 | 314 |   //    - Any URL is allowed through with no hash checking. | 
 | 315 |   if (!system_state_->request_params()->IsUpdateUrlOfficial() || | 
 | 316 |       !system_state_->hardware()->IsOfficialBuild()) { | 
| David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 317 |     // Still do a hash check if a public key is included. | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 318 |     if (!response.public_key_rsa.empty()) { | 
| David Zeuthen | bc27aac | 2013-11-26 11:17:48 -0800 | [diff] [blame] | 319 |       // The autoupdate_CatchBadSignatures test checks for this string | 
 | 320 |       // in log-files. Keep in sync. | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 321 |       LOG(INFO) << "Mandating payload hash checks since Omaha Response " | 
 | 322 |                 << "for unofficial build includes public RSA key."; | 
 | 323 |       return true; | 
 | 324 |     } else { | 
| David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 325 |       LOG(INFO) << "Waiving payload hash checks for unofficial update URL."; | 
| David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 326 |       return false; | 
 | 327 |     } | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 328 |   } | 
 | 329 |  | 
| Sen Jiang | 81c705b | 2018-10-04 14:15:05 -0700 | [diff] [blame] | 330 |   LOG(INFO) << "Mandating hash checks for official URL on official build."; | 
 | 331 |   return true; | 
| Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 332 | } | 
 | 333 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 334 | }  // namespace chromeos_update_engine |