Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2019 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 | #include "update_engine/omaha_request_builder_xml.h" |
| 18 | |
| 19 | #include <inttypes.h> |
| 20 | |
| 21 | #include <string> |
| 22 | |
Jae Hoon Kim | 6ada591 | 2019-06-14 10:11:34 -0700 | [diff] [blame] | 23 | #include <base/guid.h> |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 24 | #include <base/logging.h> |
| 25 | #include <base/strings/string_number_conversions.h> |
| 26 | #include <base/strings/string_util.h> |
| 27 | #include <base/strings/stringprintf.h> |
| 28 | #include <base/time/time.h> |
| 29 | |
| 30 | #include "update_engine/common/constants.h" |
| 31 | #include "update_engine/common/prefs_interface.h" |
| 32 | #include "update_engine/common/utils.h" |
| 33 | #include "update_engine/omaha_request_params.h" |
| 34 | |
| 35 | using std::string; |
| 36 | |
| 37 | namespace chromeos_update_engine { |
| 38 | |
Jae Hoon Kim | 5fc00a2 | 2020-01-08 20:15:42 -0800 | [diff] [blame] | 39 | const char kNoVersion[] = "0.0.0.0"; |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 40 | const int kPingNeverPinged = -1; |
| 41 | const int kPingUnknownValue = -2; |
| 42 | const int kPingActiveValue = 1; |
| 43 | const int kPingInactiveValue = 0; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 44 | |
| 45 | bool XmlEncode(const string& input, string* output) { |
| 46 | if (std::find_if(input.begin(), input.end(), [](const char c) { |
| 47 | return c & 0x80; |
| 48 | }) != input.end()) { |
| 49 | LOG(WARNING) << "Invalid ASCII-7 string passed to the XML encoder:"; |
| 50 | utils::HexDumpString(input); |
| 51 | return false; |
| 52 | } |
| 53 | output->clear(); |
| 54 | // We need at least input.size() space in the output, but the code below will |
| 55 | // handle it if we need more. |
| 56 | output->reserve(input.size()); |
| 57 | for (char c : input) { |
| 58 | switch (c) { |
| 59 | case '\"': |
| 60 | output->append("""); |
| 61 | break; |
| 62 | case '\'': |
| 63 | output->append("'"); |
| 64 | break; |
| 65 | case '&': |
| 66 | output->append("&"); |
| 67 | break; |
| 68 | case '<': |
| 69 | output->append("<"); |
| 70 | break; |
| 71 | case '>': |
| 72 | output->append(">"); |
| 73 | break; |
| 74 | default: |
| 75 | output->push_back(c); |
| 76 | } |
| 77 | } |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | string XmlEncodeWithDefault(const string& input, const string& default_value) { |
| 82 | string output; |
| 83 | if (XmlEncode(input, &output)) |
| 84 | return output; |
| 85 | return default_value; |
| 86 | } |
| 87 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 88 | string OmahaRequestBuilderXml::GetPing() const { |
| 89 | // Returns an XML ping element attribute assignment with attribute |
| 90 | // |name| and value |ping_days| if |ping_days| has a value that needs |
| 91 | // to be sent, or an empty string otherwise. |
| 92 | auto GetPingAttribute = [](const char* name, int ping_days) -> string { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 93 | if (ping_days > 0 || ping_days == kPingNeverPinged) |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 94 | return base::StringPrintf(" %s=\"%d\"", name, ping_days); |
| 95 | return ""; |
| 96 | }; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 97 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 98 | string ping_active = GetPingAttribute("a", ping_active_days_); |
| 99 | string ping_roll_call = GetPingAttribute("r", ping_roll_call_days_); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 100 | if (!ping_active.empty() || !ping_roll_call.empty()) { |
| 101 | return base::StringPrintf(" <ping active=\"1\"%s%s></ping>\n", |
| 102 | ping_active.c_str(), |
| 103 | ping_roll_call.c_str()); |
| 104 | } |
| 105 | return ""; |
| 106 | } |
| 107 | |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 108 | string OmahaRequestBuilderXml::GetPingDateBased( |
| 109 | const OmahaRequestParams::AppParams& app_params) const { |
| 110 | if (!app_params.send_ping) |
| 111 | return ""; |
| 112 | string ping_active = ""; |
| 113 | string ping_ad = ""; |
| 114 | if (app_params.ping_active == kPingActiveValue) { |
| 115 | ping_active = |
| 116 | base::StringPrintf(" active=\"%" PRId64 "\"", app_params.ping_active); |
| 117 | ping_ad = base::StringPrintf(" ad=\"%" PRId64 "\"", |
| 118 | app_params.ping_date_last_active); |
| 119 | } |
| 120 | |
| 121 | string ping_rd = base::StringPrintf(" rd=\"%" PRId64 "\"", |
| 122 | app_params.ping_date_last_rollcall); |
| 123 | |
| 124 | return base::StringPrintf(" <ping%s%s%s></ping>\n", |
| 125 | ping_active.c_str(), |
| 126 | ping_ad.c_str(), |
| 127 | ping_rd.c_str()); |
| 128 | } |
| 129 | |
| 130 | string OmahaRequestBuilderXml::GetAppBody(const OmahaAppData& app_data) const { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 131 | string app_body; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 132 | if (event_ == nullptr) { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 133 | if (app_data.app_params.send_ping) { |
| 134 | switch (app_data.app_params.active_counting_type) { |
| 135 | case OmahaRequestParams::kDayBased: |
| 136 | app_body = GetPing(); |
| 137 | break; |
| 138 | case OmahaRequestParams::kDateBased: |
| 139 | app_body = GetPingDateBased(app_data.app_params); |
| 140 | break; |
| 141 | default: |
| 142 | NOTREACHED(); |
| 143 | } |
| 144 | } |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 145 | if (!ping_only_) { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 146 | if (!app_data.skip_update) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 147 | app_body += " <updatecheck"; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 148 | if (!params_->target_version_prefix().empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 149 | app_body += base::StringPrintf( |
| 150 | " targetversionprefix=\"%s\"", |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 151 | XmlEncodeWithDefault(params_->target_version_prefix()).c_str()); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 152 | // Rollback requires target_version_prefix set. |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 153 | if (params_->rollback_allowed()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 154 | app_body += " rollback_allowed=\"true\""; |
| 155 | } |
| 156 | } |
Amin Hassani | 37b6723 | 2020-08-13 09:29:48 -0700 | [diff] [blame] | 157 | if (!params_->lts_tag().empty()) { |
| 158 | app_body += base::StringPrintf( |
| 159 | " ltstag=\"%s\"", |
| 160 | XmlEncodeWithDefault(params_->lts_tag()).c_str()); |
| 161 | } |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 162 | app_body += "></updatecheck>\n"; |
| 163 | } |
| 164 | |
| 165 | // If this is the first update check after a reboot following a previous |
| 166 | // update, generate an event containing the previous version number. If |
| 167 | // the previous version preference file doesn't exist the event is still |
| 168 | // generated with a previous version of 0.0.0.0 -- this is relevant for |
| 169 | // older clients or new installs. The previous version event is not sent |
| 170 | // for ping-only requests because they come before the client has |
| 171 | // rebooted. The previous version event is also not sent if it was already |
| 172 | // sent for this new version with a previous updatecheck. |
| 173 | string prev_version; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 174 | if (!prefs_->GetString(kPrefsPreviousVersion, &prev_version)) { |
Jae Hoon Kim | 5fc00a2 | 2020-01-08 20:15:42 -0800 | [diff] [blame] | 175 | prev_version = kNoVersion; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 176 | } |
| 177 | // We only store a non-empty previous version value after a successful |
| 178 | // update in the previous boot. After reporting it back to the server, |
| 179 | // we clear the previous version value so it doesn't get reported again. |
| 180 | if (!prev_version.empty()) { |
| 181 | app_body += base::StringPrintf( |
| 182 | " <event eventtype=\"%d\" eventresult=\"%d\" " |
| 183 | "previousversion=\"%s\"></event>\n", |
| 184 | OmahaEvent::kTypeRebootedAfterUpdate, |
| 185 | OmahaEvent::kResultSuccess, |
Jae Hoon Kim | 5fc00a2 | 2020-01-08 20:15:42 -0800 | [diff] [blame] | 186 | XmlEncodeWithDefault(prev_version, kNoVersion).c_str()); |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 187 | LOG_IF(WARNING, !prefs_->SetString(kPrefsPreviousVersion, "")) |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 188 | << "Unable to reset the previous version."; |
| 189 | } |
| 190 | } |
| 191 | } else { |
Jae Hoon Kim | 3e69b4c | 2020-06-16 09:23:39 -0700 | [diff] [blame] | 192 | int event_result = event_->result; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 193 | // The error code is an optional attribute so append it only if the result |
| 194 | // is not success. |
| 195 | string error_code; |
Jae Hoon Kim | 3e69b4c | 2020-06-16 09:23:39 -0700 | [diff] [blame] | 196 | if (event_result != OmahaEvent::kResultSuccess) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 197 | error_code = base::StringPrintf(" errorcode=\"%d\"", |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 198 | static_cast<int>(event_->error_code)); |
Jae Hoon Kim | 3e69b4c | 2020-06-16 09:23:39 -0700 | [diff] [blame] | 199 | } else if (app_data.is_dlc && !app_data.app_params.updated) { |
| 200 | // On a |OmahaEvent::kResultSuccess|, if the event is for an update |
| 201 | // completion and the App is a DLC, send error for excluded DLCs as they |
| 202 | // did not update. |
| 203 | event_result = OmahaEvent::Result::kResultError; |
| 204 | error_code = base::StringPrintf( |
| 205 | " errorcode=\"%d\"", |
| 206 | static_cast<int>(ErrorCode::kPackageExcludedFromUpdate)); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 207 | } |
| 208 | app_body = base::StringPrintf( |
| 209 | " <event eventtype=\"%d\" eventresult=\"%d\"%s></event>\n", |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 210 | event_->type, |
Jae Hoon Kim | 3e69b4c | 2020-06-16 09:23:39 -0700 | [diff] [blame] | 211 | event_result, |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 212 | error_code.c_str()); |
| 213 | } |
| 214 | |
| 215 | return app_body; |
| 216 | } |
| 217 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 218 | string OmahaRequestBuilderXml::GetCohortArg(const string arg_name, |
Askar Aitzhan | 18fff84 | 2019-06-21 23:24:37 +0200 | [diff] [blame] | 219 | const string prefs_key, |
| 220 | const string override_value) const { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 221 | string cohort_value; |
Askar Aitzhan | 18fff84 | 2019-06-21 23:24:37 +0200 | [diff] [blame] | 222 | if (!override_value.empty()) { |
| 223 | // |override_value| take precedence over pref value. |
| 224 | cohort_value = override_value; |
| 225 | } else { |
| 226 | // There's nothing wrong with not having a given cohort setting, so we check |
| 227 | // existence first to avoid the warning log message. |
| 228 | if (!prefs_->Exists(prefs_key)) |
| 229 | return ""; |
| 230 | if (!prefs_->GetString(prefs_key, &cohort_value) || cohort_value.empty()) |
| 231 | return ""; |
| 232 | } |
Kelvin Zhang | ebd5e25 | 2020-07-22 18:27:06 -0400 | [diff] [blame] | 233 | // This is a validity check to avoid sending a huge XML file back to Ohama due |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 234 | // to a compromised stateful partition making the update check fail in low |
| 235 | // network environments envent after a reboot. |
| 236 | if (cohort_value.size() > 1024) { |
| 237 | LOG(WARNING) << "The omaha cohort setting " << arg_name |
| 238 | << " has a too big value, which must be an error or an " |
| 239 | "attacker trying to inhibit updates."; |
| 240 | return ""; |
| 241 | } |
| 242 | |
| 243 | string escaped_xml_value; |
| 244 | if (!XmlEncode(cohort_value, &escaped_xml_value)) { |
| 245 | LOG(WARNING) << "The omaha cohort setting " << arg_name |
| 246 | << " is ASCII-7 invalid, ignoring it."; |
| 247 | return ""; |
| 248 | } |
| 249 | |
| 250 | return base::StringPrintf( |
| 251 | "%s=\"%s\" ", arg_name.c_str(), escaped_xml_value.c_str()); |
| 252 | } |
| 253 | |
| 254 | bool IsValidComponentID(const string& id) { |
| 255 | for (char c : id) { |
| 256 | if (!isalnum(c) && c != '-' && c != '_' && c != '.') |
| 257 | return false; |
| 258 | } |
| 259 | return true; |
| 260 | } |
| 261 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 262 | string OmahaRequestBuilderXml::GetApp(const OmahaAppData& app_data) const { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 263 | string app_body = GetAppBody(app_data); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 264 | string app_versions; |
| 265 | |
| 266 | // If we are downgrading to a more stable channel and we are allowed to do |
| 267 | // powerwash, then pass 0.0.0.0 as the version. This is needed to get the |
| 268 | // highest-versioned payload on the destination channel. |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 269 | if (params_->ShouldPowerwash()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 270 | LOG(INFO) << "Passing OS version as 0.0.0.0 as we are set to powerwash " |
| 271 | << "on downgrading to the version in the more stable channel"; |
Jae Hoon Kim | 5fc00a2 | 2020-01-08 20:15:42 -0800 | [diff] [blame] | 272 | app_versions = "version=\"" + string(kNoVersion) + "\" from_version=\"" + |
| 273 | XmlEncodeWithDefault(app_data.version, kNoVersion) + "\" "; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 274 | } else { |
| 275 | app_versions = "version=\"" + |
Jae Hoon Kim | 5fc00a2 | 2020-01-08 20:15:42 -0800 | [diff] [blame] | 276 | XmlEncodeWithDefault(app_data.version, kNoVersion) + "\" "; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 279 | string download_channel = params_->download_channel(); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 280 | string app_channels = |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 281 | "track=\"" + XmlEncodeWithDefault(download_channel) + "\" "; |
| 282 | if (params_->current_channel() != download_channel) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 283 | app_channels += "from_track=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 284 | XmlEncodeWithDefault(params_->current_channel()) + "\" "; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Jae Hoon Kim | 5fc00a2 | 2020-01-08 20:15:42 -0800 | [diff] [blame] | 287 | string delta_okay_str = |
| 288 | params_->delta_okay() && !params_->is_install() ? "true" : "false"; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 289 | |
| 290 | // If install_date_days is not set (e.g. its value is -1 ), don't |
| 291 | // include the attribute. |
| 292 | string install_date_in_days_str = ""; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 293 | if (install_date_in_days_ >= 0) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 294 | install_date_in_days_str = |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 295 | base::StringPrintf("installdate=\"%d\" ", install_date_in_days_); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | string app_cohort_args; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 299 | app_cohort_args += GetCohortArg("cohort", kPrefsOmahaCohort); |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 300 | app_cohort_args += GetCohortArg("cohortname", kPrefsOmahaCohortName); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 301 | |
Askar Aitzhan | 18fff84 | 2019-06-21 23:24:37 +0200 | [diff] [blame] | 302 | // Policy provided value overrides pref. |
| 303 | string autoupdate_token = params_->autoupdate_token(); |
| 304 | app_cohort_args += GetCohortArg("cohorthint", |
| 305 | kPrefsOmahaCohortHint, |
| 306 | autoupdate_token /* override_value */); |
| 307 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 308 | string fingerprint_arg; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 309 | if (!params_->os_build_fingerprint().empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 310 | fingerprint_arg = "fingerprint=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 311 | XmlEncodeWithDefault(params_->os_build_fingerprint()) + |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 312 | "\" "; |
| 313 | } |
| 314 | |
| 315 | string buildtype_arg; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 316 | if (!params_->os_build_type().empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 317 | buildtype_arg = "os_build_type=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 318 | XmlEncodeWithDefault(params_->os_build_type()) + "\" "; |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | string product_components_args; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 322 | if (!params_->ShouldPowerwash() && !app_data.product_components.empty()) { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 323 | brillo::KeyValueStore store; |
| 324 | if (store.LoadFromString(app_data.product_components)) { |
| 325 | for (const string& key : store.GetKeys()) { |
| 326 | if (!IsValidComponentID(key)) { |
| 327 | LOG(ERROR) << "Invalid component id: " << key; |
| 328 | continue; |
| 329 | } |
| 330 | string version; |
| 331 | if (!store.GetString(key, &version)) { |
| 332 | LOG(ERROR) << "Failed to get version for " << key |
| 333 | << " in product_components."; |
| 334 | continue; |
| 335 | } |
| 336 | product_components_args += |
| 337 | base::StringPrintf("_%s.version=\"%s\" ", |
| 338 | key.c_str(), |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 339 | XmlEncodeWithDefault(version).c_str()); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 340 | } |
| 341 | } else { |
| 342 | LOG(ERROR) << "Failed to parse product_components:\n" |
| 343 | << app_data.product_components; |
| 344 | } |
| 345 | } |
| 346 | |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 347 | string requisition_arg; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 348 | if (!params_->device_requisition().empty()) { |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 349 | requisition_arg = "requisition=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 350 | XmlEncodeWithDefault(params_->device_requisition()) + |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 351 | "\" "; |
| 352 | } |
| 353 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 354 | // clang-format off |
| 355 | string app_xml = " <app " |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 356 | "appid=\"" + XmlEncodeWithDefault(app_data.id) + "\" " + |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 357 | app_cohort_args + |
| 358 | app_versions + |
| 359 | app_channels + |
| 360 | product_components_args + |
| 361 | fingerprint_arg + |
| 362 | buildtype_arg + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 363 | "board=\"" + XmlEncodeWithDefault(params_->os_board()) + "\" " + |
| 364 | "hardware_class=\"" + XmlEncodeWithDefault(params_->hwid()) + "\" " + |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame] | 365 | "delta_okay=\"" + delta_okay_str + "\" " + |
| 366 | install_date_in_days_str + |
| 367 | |
| 368 | // DLC excluded for installs and updates. |
| 369 | (app_data.is_dlc ? "" : |
| 370 | "lang=\"" + XmlEncodeWithDefault(params_->app_lang(), "en-US") + "\" " + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 371 | "fw_version=\"" + XmlEncodeWithDefault(params_->fw_version()) + "\" " + |
| 372 | "ec_version=\"" + XmlEncodeWithDefault(params_->ec_version()) + "\" " + |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame] | 373 | requisition_arg) + |
| 374 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 375 | ">\n" + |
| 376 | app_body + |
| 377 | " </app>\n"; |
| 378 | // clang-format on |
| 379 | return app_xml; |
| 380 | } |
| 381 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 382 | string OmahaRequestBuilderXml::GetOs() const { |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 383 | string os_xml = |
| 384 | " <os " |
| 385 | "version=\"" + |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 386 | XmlEncodeWithDefault(params_->os_version()) + "\" " + "platform=\"" + |
| 387 | XmlEncodeWithDefault(params_->os_platform()) + "\" " + "sp=\"" + |
| 388 | XmlEncodeWithDefault(params_->os_sp()) + |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 389 | "\">" |
| 390 | "</os>\n"; |
| 391 | return os_xml; |
| 392 | } |
| 393 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 394 | string OmahaRequestBuilderXml::GetRequest() const { |
| 395 | string os_xml = GetOs(); |
| 396 | string app_xml = GetApps(); |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 397 | |
| 398 | string request_xml = base::StringPrintf( |
| 399 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 400 | "<request requestid=\"%s\" sessionid=\"%s\"" |
Jae Hoon Kim | 6ada591 | 2019-06-14 10:11:34 -0700 | [diff] [blame] | 401 | " protocol=\"3.0\" updater=\"%s\" updaterversion=\"%s\"" |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 402 | " installsource=\"%s\" ismachine=\"1\">\n%s%s</request>\n", |
Jae Hoon Kim | 6ada591 | 2019-06-14 10:11:34 -0700 | [diff] [blame] | 403 | base::GenerateGUID().c_str() /* requestid */, |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 404 | session_id_.c_str(), |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 405 | constants::kOmahaUpdaterID, |
| 406 | kOmahaUpdaterVersion, |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 407 | params_->interactive() ? "ondemandupdate" : "scheduler", |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 408 | os_xml.c_str(), |
| 409 | app_xml.c_str()); |
| 410 | |
| 411 | return request_xml; |
| 412 | } |
| 413 | |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 414 | string OmahaRequestBuilderXml::GetApps() const { |
| 415 | string app_xml = ""; |
| 416 | OmahaAppData product_app = { |
| 417 | .id = params_->GetAppId(), |
| 418 | .version = params_->app_version(), |
| 419 | .product_components = params_->product_components(), |
| 420 | // Skips updatecheck for platform app in case of an install operation. |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame] | 421 | .skip_update = params_->is_install(), |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 422 | .is_dlc = false, |
| 423 | |
| 424 | .app_params = {.active_counting_type = OmahaRequestParams::kDayBased, |
| 425 | .send_ping = include_ping_}}; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 426 | app_xml += GetApp(product_app); |
| 427 | if (!params_->system_app_id().empty()) { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 428 | OmahaAppData system_app = { |
| 429 | .id = params_->system_app_id(), |
| 430 | .version = params_->system_version(), |
| 431 | .skip_update = false, |
| 432 | .is_dlc = false, |
| 433 | .app_params = {.active_counting_type = OmahaRequestParams::kDayBased, |
| 434 | .send_ping = include_ping_}}; |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 435 | app_xml += GetApp(system_app); |
| 436 | } |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 437 | for (const auto& it : params_->dlc_apps_params()) { |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 438 | OmahaAppData dlc_app_data = { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 439 | .id = it.first, |
Jae Hoon Kim | 5fc00a2 | 2020-01-08 20:15:42 -0800 | [diff] [blame] | 440 | .version = params_->is_install() ? kNoVersion : params_->app_version(), |
Jae Hoon Kim | 37d1537 | 2020-01-08 18:11:26 -0800 | [diff] [blame] | 441 | .skip_update = false, |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 442 | .is_dlc = true, |
| 443 | .app_params = it.second}; |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 444 | app_xml += GetApp(dlc_app_data); |
Jae Hoon Kim | b7ee387 | 2019-06-06 14:59:03 -0700 | [diff] [blame] | 445 | } |
| 446 | return app_xml; |
| 447 | } |
| 448 | |
Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame] | 449 | } // namespace chromeos_update_engine |