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 | |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 13 | #include "update_engine/connection_manager_interface.h" |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 14 | #include "update_engine/constants.h" |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 15 | #include "update_engine/delta_performer.h" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 16 | #include "update_engine/hardware_interface.h" |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 17 | #include "update_engine/omaha_request_params.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 18 | #include "update_engine/payload_state_interface.h" |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 19 | #include "update_engine/prefs_interface.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 20 | #include "update_engine/utils.h" |
| 21 | |
| 22 | using std::string; |
| 23 | |
| 24 | namespace chromeos_update_engine { |
| 25 | |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 26 | const char OmahaResponseHandlerAction::kDeadlineFile[] = |
| 27 | "/tmp/update-check-response-deadline"; |
| 28 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 29 | OmahaResponseHandlerAction::OmahaResponseHandlerAction( |
| 30 | SystemState* system_state) |
| 31 | : system_state_(system_state), |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 32 | got_no_update_response_(false), |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 33 | key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath), |
| 34 | deadline_file_(kDeadlineFile) {} |
| 35 | |
| 36 | OmahaResponseHandlerAction::OmahaResponseHandlerAction( |
| 37 | SystemState* system_state, const string& deadline_file) |
| 38 | : system_state_(system_state), |
| 39 | got_no_update_response_(false), |
| 40 | key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath), |
| 41 | deadline_file_(deadline_file) {} |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 42 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 43 | void OmahaResponseHandlerAction::PerformAction() { |
| 44 | CHECK(HasInputObject()); |
| 45 | ScopedActionCompleter completer(processor_, this); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 46 | const OmahaResponse& response = GetInputObject(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 47 | if (!response.update_exists) { |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 48 | got_no_update_response_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 49 | LOG(INFO) << "There are no updates. Aborting."; |
| 50 | return; |
| 51 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 52 | |
| 53 | // 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] | 54 | // make the current URL as the download URL. |
| 55 | string current_url = system_state_->payload_state()->GetCurrentUrl(); |
| 56 | if (current_url.empty()) { |
| 57 | // This shouldn't happen as we should always supply the HTTPS backup URL. |
| 58 | // Handling this anyway, just in case. |
| 59 | LOG(ERROR) << "There are no suitable URLs in the response to use."; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 60 | completer.set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 61 | return; |
| 62 | } |
| 63 | |
| 64 | install_plan_.download_url = current_url; |
Chris Sosa | fb1020e | 2013-07-29 17:27:33 -0700 | [diff] [blame] | 65 | install_plan_.version = response.version; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 66 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 67 | OmahaRequestParams* const params = system_state_->request_params(); |
| 68 | PayloadStateInterface* const payload_state = system_state_->payload_state(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 69 | |
| 70 | // 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] | 71 | if (payload_state->GetUsingP2PForDownloading() && |
| 72 | !payload_state->GetP2PUrl().empty()) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 73 | LOG(INFO) << "Replacing URL " << install_plan_.download_url |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 74 | << " with local URL " << payload_state->GetP2PUrl() |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 75 | << " since p2p is enabled."; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 76 | install_plan_.download_url = payload_state->GetP2PUrl(); |
| 77 | payload_state->SetUsingP2PForDownloading(true); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 80 | // Fill up the other properties based on the response. |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 81 | install_plan_.payload_size = response.size; |
| 82 | install_plan_.payload_hash = response.hash; |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 83 | install_plan_.metadata_size = response.metadata_size; |
| 84 | install_plan_.metadata_signature = response.metadata_signature; |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 85 | install_plan_.public_key_rsa = response.public_key_rsa; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 86 | install_plan_.hash_checks_mandatory = AreHashChecksMandatory(response); |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 87 | install_plan_.is_resume = |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 88 | DeltaPerformer::CanResumeUpdate(system_state_->prefs(), response.hash); |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 89 | if (install_plan_.is_resume) { |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 90 | payload_state->UpdateResumed(); |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 91 | } else { |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 92 | payload_state->UpdateRestarted(); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 93 | LOG_IF(WARNING, !DeltaPerformer::ResetUpdateProgress( |
| 94 | system_state_->prefs(), false)) |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 95 | << "Unable to reset the update progress."; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 96 | LOG_IF(WARNING, !system_state_->prefs()->SetString( |
| 97 | kPrefsUpdateCheckResponseHash, response.hash)) |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 98 | << "Unable to save the update check response hash."; |
| 99 | } |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 100 | install_plan_.is_full_update = !response.is_delta_payload; |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 101 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 102 | TEST_AND_RETURN(utils::GetInstallDev( |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 103 | (!boot_device_.empty() ? boot_device_ : |
| 104 | system_state_->hardware()->BootDevice()), |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 105 | &install_plan_.install_path)); |
| 106 | install_plan_.kernel_install_path = |
J. Richard Barnette | 3084293 | 2013-10-28 15:04:23 -0700 | [diff] [blame] | 107 | utils::KernelDeviceOfBootDevice(install_plan_.install_path); |
Allie Wood | 9f6f0a5 | 2015-03-30 11:25:47 -0700 | [diff] [blame] | 108 | install_plan_.source_path = system_state_->hardware()->BootDevice(); |
| 109 | install_plan_.kernel_source_path = |
| 110 | utils::KernelDeviceOfBootDevice(install_plan_.source_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 111 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 112 | if (params->to_more_stable_channel() && params->is_powerwash_allowed()) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 113 | install_plan_.powerwash_required = true; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 114 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 115 | |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 116 | TEST_AND_RETURN(HasOutputPipe()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 117 | if (HasOutputPipe()) |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 118 | SetOutputObject(install_plan_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 119 | LOG(INFO) << "Using this install plan:"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 120 | install_plan_.Dump(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 121 | |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 122 | // Send the deadline data (if any) to Chrome through a file. This is a pretty |
| 123 | // hacky solution but should be OK for now. |
| 124 | // |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 125 | // TODO(petkov): Re-architect this to avoid communication through a |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 126 | // file. Ideally, we would include this information in D-Bus's GetStatus |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 127 | // method and UpdateStatus signal. A potential issue is that update_engine may |
| 128 | // be unresponsive during an update download. |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 129 | utils::WriteFile(deadline_file_.c_str(), |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 130 | response.deadline.data(), |
| 131 | response.deadline.size()); |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 132 | 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] | 133 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 134 | completer.set_code(ErrorCode::kSuccess); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 137 | bool OmahaResponseHandlerAction::AreHashChecksMandatory( |
| 138 | const OmahaResponse& response) { |
David Pursell | 907b4fa | 2015-01-27 10:27:38 -0800 | [diff] [blame] | 139 | // We sometimes need to waive the hash checks in order to download from |
| 140 | // sources that don't provide hashes, such as dev server. |
| 141 | // At this point UpdateAttempter::IsAnyUpdateSourceAllowed() has already been |
| 142 | // checked, so an unofficial update URL won't get this far unless it's OK to |
| 143 | // use without a hash. Additionally, we want to always waive hash checks on |
| 144 | // unofficial builds (i.e. dev/test images). |
| 145 | // The end result is this: |
| 146 | // * Base image: |
| 147 | // - Official URLs require a hash. |
| 148 | // - Unofficial URLs only get this far if the IsAnyUpdateSourceAllowed() |
| 149 | // devmode/debugd checks pass, in which case the hash is waived. |
| 150 | // * Dev/test image: |
| 151 | // - Any URL is allowed through with no hash checking. |
| 152 | if (!system_state_->request_params()->IsUpdateUrlOfficial() || |
| 153 | !system_state_->hardware()->IsOfficialBuild()) { |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 154 | // Still do a hash check if a public key is included. |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 155 | if (!response.public_key_rsa.empty()) { |
David Zeuthen | bc27aac | 2013-11-26 11:17:48 -0800 | [diff] [blame] | 156 | // The autoupdate_CatchBadSignatures test checks for this string |
| 157 | // in log-files. Keep in sync. |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 158 | LOG(INFO) << "Mandating payload hash checks since Omaha Response " |
| 159 | << "for unofficial build includes public RSA key."; |
| 160 | return true; |
| 161 | } else { |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 162 | LOG(INFO) << "Waiving payload hash checks for unofficial update URL."; |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 163 | return false; |
| 164 | } |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 165 | } |
| 166 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 167 | // If we're using p2p, |install_plan_.download_url| may contain a |
| 168 | // HTTP URL even if |response.payload_urls| contain only HTTPS URLs. |
Alex Vakulenko | 6a9d349 | 2015-06-15 12:53:22 -0700 | [diff] [blame] | 169 | if (!base::StartsWithASCII(install_plan_.download_url, "https://", false)) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 170 | LOG(INFO) << "Mandating hash checks since download_url is not HTTPS."; |
| 171 | return true; |
| 172 | } |
| 173 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 174 | // TODO(jaysri): VALIDATION: For official builds, we currently waive hash |
| 175 | // checks for HTTPS until we have rolled out at least once and are confident |
| 176 | // nothing breaks. chromium-os:37082 tracks turning this on for HTTPS |
| 177 | // eventually. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 178 | |
| 179 | // Even if there's a single non-HTTPS URL, make the hash checks as |
| 180 | // mandatory because we could be downloading the payload from any URL later |
| 181 | // on. It's really hard to do book-keeping based on each byte being |
| 182 | // downloaded to see whether we only used HTTPS throughout. |
| 183 | for (size_t i = 0; i < response.payload_urls.size(); i++) { |
Alex Vakulenko | 6a9d349 | 2015-06-15 12:53:22 -0700 | [diff] [blame] | 184 | if (!base::StartsWithASCII(response.payload_urls[i], "https://", false)) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 185 | LOG(INFO) << "Mandating payload hash checks since Omaha response " |
| 186 | << "contains non-HTTPS URL(s)"; |
| 187 | return true; |
| 188 | } |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 191 | LOG(INFO) << "Waiving payload hash checks since Omaha response " |
| 192 | << "only has HTTPS URL(s)"; |
| 193 | return false; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 194 | } |
| 195 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 196 | } // namespace chromeos_update_engine |