Darin Petkov | 7ed561b | 2011-10-04 02:59:03 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/omaha_response_handler_action.h" |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 6 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 7 | #include <string> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 8 | |
| 9 | #include <base/logging.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 10 | #include <base/strings/string_util.h> |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 11 | #include <policy/device_policy.h> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 12 | |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 13 | #include "update_engine/constants.h" |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 14 | #include "update_engine/delta_performer.h" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 15 | #include "update_engine/hardware_interface.h" |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 16 | #include "update_engine/omaha_request_params.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 17 | #include "update_engine/payload_state_interface.h" |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 18 | #include "update_engine/prefs_interface.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | #include "update_engine/utils.h" |
| 20 | |
| 21 | using std::string; |
| 22 | |
| 23 | namespace chromeos_update_engine { |
| 24 | |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 25 | const char OmahaResponseHandlerAction::kDeadlineFile[] = |
| 26 | "/tmp/update-check-response-deadline"; |
| 27 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 28 | OmahaResponseHandlerAction::OmahaResponseHandlerAction( |
| 29 | SystemState* system_state) |
| 30 | : system_state_(system_state), |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 31 | got_no_update_response_(false), |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 32 | key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath), |
| 33 | deadline_file_(kDeadlineFile) {} |
| 34 | |
| 35 | OmahaResponseHandlerAction::OmahaResponseHandlerAction( |
| 36 | SystemState* system_state, const string& deadline_file) |
| 37 | : system_state_(system_state), |
| 38 | got_no_update_response_(false), |
| 39 | key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath), |
| 40 | deadline_file_(deadline_file) {} |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 41 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 42 | void OmahaResponseHandlerAction::PerformAction() { |
| 43 | CHECK(HasInputObject()); |
| 44 | ScopedActionCompleter completer(processor_, this); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 45 | const OmahaResponse& response = GetInputObject(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | if (!response.update_exists) { |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 47 | got_no_update_response_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 48 | LOG(INFO) << "There are no updates. Aborting."; |
| 49 | return; |
| 50 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 51 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 52 | // Note: policy decision to not update to a version we rolled back from. |
| 53 | string rollback_version = |
| 54 | system_state_->payload_state()->GetRollbackVersion(); |
Chris Sosa | b3dcdb3 | 2013-09-04 15:22:12 -0700 | [diff] [blame] | 55 | if(!rollback_version.empty()) { |
| 56 | LOG(INFO) << "Detected previous rollback from version " << rollback_version; |
| 57 | if(rollback_version == response.version) { |
| 58 | LOG(INFO) << "Received version that we rolled back from. Aborting."; |
| 59 | return; |
| 60 | } |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 63 | // 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] | 64 | // make the current URL as the download URL. |
| 65 | string current_url = system_state_->payload_state()->GetCurrentUrl(); |
| 66 | if (current_url.empty()) { |
| 67 | // This shouldn't happen as we should always supply the HTTPS backup URL. |
| 68 | // Handling this anyway, just in case. |
| 69 | LOG(ERROR) << "There are no suitable URLs in the response to use."; |
| 70 | completer.set_code(kErrorCodeOmahaResponseInvalid); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | install_plan_.download_url = current_url; |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 75 | install_plan_.version = response.version; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 76 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 77 | OmahaRequestParams* params = system_state_->request_params(); |
| 78 | |
| 79 | // If we're using p2p to download and there is a local peer, use it. |
| 80 | if (params->use_p2p_for_downloading() && !params->p2p_url().empty()) { |
| 81 | LOG(INFO) << "Replacing URL " << install_plan_.download_url |
| 82 | << " with local URL " << params->p2p_url() |
| 83 | << " since p2p is enabled."; |
| 84 | install_plan_.download_url = params->p2p_url(); |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 85 | system_state_->payload_state()->SetUsingP2PForDownloading(true); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 88 | // Fill up the other properties based on the response. |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 89 | install_plan_.payload_size = response.size; |
| 90 | install_plan_.payload_hash = response.hash; |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 91 | install_plan_.metadata_size = response.metadata_size; |
| 92 | install_plan_.metadata_signature = response.metadata_signature; |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 93 | install_plan_.public_key_rsa = response.public_key_rsa; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 94 | install_plan_.hash_checks_mandatory = AreHashChecksMandatory(response); |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 95 | install_plan_.is_resume = |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 96 | DeltaPerformer::CanResumeUpdate(system_state_->prefs(), response.hash); |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 97 | if (install_plan_.is_resume) { |
| 98 | system_state_->payload_state()->UpdateResumed(); |
| 99 | } else { |
Jay Srinivasan | 19409b7 | 2013-04-12 19:23:36 -0700 | [diff] [blame] | 100 | system_state_->payload_state()->UpdateRestarted(); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 101 | LOG_IF(WARNING, !DeltaPerformer::ResetUpdateProgress( |
| 102 | system_state_->prefs(), false)) |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 103 | << "Unable to reset the update progress."; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 104 | LOG_IF(WARNING, !system_state_->prefs()->SetString( |
| 105 | kPrefsUpdateCheckResponseHash, response.hash)) |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 106 | << "Unable to save the update check response hash."; |
| 107 | } |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 108 | install_plan_.is_full_update = !response.is_delta_payload; |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 109 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 110 | TEST_AND_RETURN(utils::GetInstallDev( |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 111 | (!boot_device_.empty() ? boot_device_ : |
| 112 | system_state_->hardware()->BootDevice()), |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 113 | &install_plan_.install_path)); |
| 114 | install_plan_.kernel_install_path = |
J. Richard Barnette | 3084293 | 2013-10-28 15:04:23 -0700 | [diff] [blame] | 115 | utils::KernelDeviceOfBootDevice(install_plan_.install_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 116 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 117 | if (params->to_more_stable_channel() && params->is_powerwash_allowed()) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 118 | install_plan_.powerwash_required = true; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 119 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 120 | |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 121 | TEST_AND_RETURN(HasOutputPipe()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 122 | if (HasOutputPipe()) |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 123 | SetOutputObject(install_plan_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 124 | LOG(INFO) << "Using this install plan:"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 125 | install_plan_.Dump(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 126 | |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 127 | // Send the deadline data (if any) to Chrome through a file. This is a pretty |
| 128 | // hacky solution but should be OK for now. |
| 129 | // |
| 130 | // TODO(petkov): Rearchitect this to avoid communication through a |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 131 | // file. Ideally, we would include this information in D-Bus's GetStatus |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 132 | // method and UpdateStatus signal. A potential issue is that update_engine may |
| 133 | // be unresponsive during an update download. |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 134 | utils::WriteFile(deadline_file_.c_str(), |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 135 | response.deadline.data(), |
| 136 | response.deadline.size()); |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 137 | chmod(deadline_file_.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 138 | |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 139 | completer.set_code(kErrorCodeSuccess); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 142 | bool OmahaResponseHandlerAction::AreHashChecksMandatory( |
| 143 | const OmahaResponse& response) { |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 144 | // All our internal testing uses dev server which doesn't generate |
| 145 | // metadata signatures by default. So, in order not to break |
| 146 | // image_to_live or other AU tools, we should waive the hash checks |
| 147 | // for those cases, except if the response indicates that the |
| 148 | // payload is signed. |
| 149 | // |
| 150 | // Since all internal testing is done using a dev_image or |
| 151 | // test_image, we can use that as a criteria for waiving. This |
| 152 | // criteria reduces the attack surface as opposed to waiving the |
| 153 | // checks when we're in dev mode, because we do want to enforce the |
| 154 | // hash checks when our end customers run in dev mode if they are |
| 155 | // using an official build, so that they are protected more. |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 156 | if (!system_state_->hardware()->IsOfficialBuild()) { |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 157 | if (!response.public_key_rsa.empty()) { |
David Zeuthen | bc27aac | 2013-11-26 11:17:48 -0800 | [diff] [blame] | 158 | // The autoupdate_CatchBadSignatures test checks for this string |
| 159 | // in log-files. Keep in sync. |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 160 | LOG(INFO) << "Mandating payload hash checks since Omaha Response " |
| 161 | << "for unofficial build includes public RSA key."; |
| 162 | return true; |
| 163 | } else { |
| 164 | LOG(INFO) << "Waiving payload hash checks for unofficial builds"; |
| 165 | return false; |
| 166 | } |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 167 | } |
| 168 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 169 | // If we're using p2p, |install_plan_.download_url| may contain a |
| 170 | // HTTP URL even if |response.payload_urls| contain only HTTPS URLs. |
| 171 | if (!StartsWithASCII(install_plan_.download_url, "https://", false)) { |
| 172 | LOG(INFO) << "Mandating hash checks since download_url is not HTTPS."; |
| 173 | return true; |
| 174 | } |
| 175 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 176 | // TODO(jaysri): VALIDATION: For official builds, we currently waive hash |
| 177 | // checks for HTTPS until we have rolled out at least once and are confident |
| 178 | // nothing breaks. chromium-os:37082 tracks turning this on for HTTPS |
| 179 | // eventually. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 180 | |
| 181 | // Even if there's a single non-HTTPS URL, make the hash checks as |
| 182 | // mandatory because we could be downloading the payload from any URL later |
| 183 | // on. It's really hard to do book-keeping based on each byte being |
| 184 | // downloaded to see whether we only used HTTPS throughout. |
| 185 | for (size_t i = 0; i < response.payload_urls.size(); i++) { |
| 186 | if (!StartsWithASCII(response.payload_urls[i], "https://", false)) { |
| 187 | LOG(INFO) << "Mandating payload hash checks since Omaha response " |
| 188 | << "contains non-HTTPS URL(s)"; |
| 189 | return true; |
| 190 | } |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 193 | LOG(INFO) << "Waiving payload hash checks since Omaha response " |
| 194 | << "only has HTTPS URL(s)"; |
| 195 | return false; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 196 | } |
| 197 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 198 | } // namespace chromeos_update_engine |