Xbox Cloud Gaming app for PS5 Homebrew
C
fix: handle out-of-order TLS chains, F2P already-owned claims, and auth/DNS resilience
Rafael Abud Ferreirae7e893a991ae
diff --git a/src/app/worker.cpp b/src/app/worker.cppindex 6b291d7..ca340f9 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -658,6 +658,13 @@ void tryInstantCachedBoot(auth::AuthManager& am) {}} // namespace+bool isDnsOrSinkholeError(const std::string& err) {+ return err.find("DNS lookup failed") != std::string::npos ||+ err.find("0x8041013d") != std::string::npos ||+ err.find("0x804101e1") != std::string::npos ||+ err.find("(errno 61)") != std::string::npos;+}+void signInAndLoad(auth::AuthManager& am, xcloud::GssvClient& gssv) {if (!platform::dataDirWritable()) {std::string pathAndErr = platform::dataDir() + " (errno " + std::to_string(platform::dataDirErrno()) + ")";@@ -692,12 +699,12 @@ void signInAndLoad(auth::AuthManager& am, xcloud::GssvClient& gssv) {} else if (net::lastTlsProblem() == net::TlsProblem::Untrusted ||net::lastTlsProblem() == net::TlsProblem::NameMismatch) {g_ui->showError(ui::tr(ui::Str::ConnectionIntercepted));- } else if (err.find("DNS lookup failed") != std::string::npos ||- err.find("0x8041013d") != std::string::npos) {+ } else if (isDnsOrSinkholeError(err)) {g_ui->showError(ui::tr(ui::Str::DnsBlockedNanoDns));} else if (err.find("2148916233") != std::string::npos ||err.find("no Xbox profile") != std::string::npos) {- g_ui->showError(ui::tr(ui::Str::XboxProfileMissing), "https://www.xbox.com");+ g_ui->showError(ui::tr(ui::Str::XboxProfileMissing),+ am.redirectUrl().empty() ? "https://www.xbox.com" : am.redirectUrl());} else if (err.find("user interaction is required") != std::string::npos ||err.find("invalid_grant") != std::string::npos ||err.find("authorization_declined") != std::string::npos) {@@ -805,8 +812,7 @@ void loadLibrary(auth::AuthManager& am, xcloud::GssvClient& gssv) {},err);if (!ok) {- if (err.find("DNS lookup failed") != std::string::npos ||- err.find("0x8041013d") != std::string::npos) {+ if (isDnsOrSinkholeError(err)) {g_ui->showError(ui::tr(ui::Str::DnsBlockedNanoDns));} else {g_ui->showError(ui::trf(ui::Str::LibraryFailed, err));@@ -900,7 +906,8 @@ void worker() {if (g_autoplay.tlsCheck) {// How refused certificates are told apart, on the console's own TLS.static const char* kNames[] = {"none", "clock", "untrusted", "name mismatch", "other"};- for (const char* url : {"https://login.live.com/", "https://expired.badssl.com/", "https://self-signed.badssl.com/",+ for (const char* url : {"https://login.live.com/", "https://CIA.core.gssv-play-prod.xboxlive.com/",+ "https://expired.badssl.com/", "https://self-signed.badssl.com/","https://wrong.host.badssl.com/"}) {net::Request req;req.url = url;@@ -921,11 +928,14 @@ void worker() {switch (cmd) {case kSignIn:signInAndLoad(am, gssv);- if (!g_quit) loadConsoles(am, home); // empty when the sign-in failed+ if (!g_quit && am.signedIn()) loadConsoles(am, home);break;case kConsoles: loadConsoles(am, home); break;case kUpdate: runUpdate(); break;- case kReloadLibrary: loadLibrary(am, gssv); break; // e.g. after a language change+ case kReloadLibrary:+ if (am.signedIn()) loadLibrary(am, gssv);+ else signInAndLoad(am, gssv);+ break;case kSignOut:// Nothing of this account stays for the next one: its library// stops loading, its cache goes, the lists empty.@@ -947,7 +957,7 @@ void worker() {g_ui->setPlaytime(-1, -1);XC_LOGI("signed out: library and its cache cleared");signInAndLoad(am, gssv);- if (!g_quit) loadConsoles(am, home);+ if (!g_quit && am.signedIn()) loadConsoles(am, home);break;case kPlay: {stopHydration();@@ -997,7 +1007,7 @@ void worker() {g_ui->showHome(endedToast(result));g_playingHome = false;autoplayFinished(result);- if (!g_quit) loadConsoles(am, home); // its state changed+ if (!g_quit && am.signedIn()) loadConsoles(am, home); // its state changedbreak;}bool automatic;@@ -1041,8 +1051,12 @@ void worker() {tile.name),tile);} else if (failed) {- if (result.find("DNS lookup failed") != std::string::npos ||- result.find("0x8041013d") != std::string::npos) {+ if (net::lastTlsProblem() == net::TlsProblem::Clock) {+ g_ui->showError(ui::trf(shell::caps().console ? ui::Str::ClockWrong : ui::Str::ClockWrongPc, net::todayText()));+ } else if (net::lastTlsProblem() == net::TlsProblem::Untrusted ||+ net::lastTlsProblem() == net::TlsProblem::NameMismatch) {+ g_ui->showError(ui::tr(ui::Str::ConnectionIntercepted));+ } else if (isDnsOrSinkholeError(result)) {g_ui->showError(ui::tr(ui::Str::DnsBlockedNanoDns));} else {g_ui->showError(result.rfind("ERROR: ", 0) == 0 ? result.substr(7) : result);@@ -1065,6 +1079,10 @@ void worker() {tile.name.c_str(), tile.productId.c_str(), tile.titleId.c_str());std::string err;+ if (!keepSignedIn(am, gssv, err)) {+ XC_LOGW("claim: sign-in renewal: %s", err.c_str());+ err.clear();+ }xcloud::PurchaseOffer offer;std::string market = gssv.session().market.empty() ? "US" : gssv.session().market;std::string lang = ui::catalogLanguage();@@ -1082,7 +1100,11 @@ void worker() {std::string authHeader;if (!am.marketplaceAuthorization(authHeader, err)) {XC_LOGW("claim: marketplace auth failed: %s", err.c_str());- g_ui->showPlayError(ui::trf(ui::Str::ClaimFailed, err), tile);+ if (err == "not signed in") {+ g_ui->showError(ui::trf(ui::Str::ClaimFailed, err));+ } else {+ g_ui->showPlayError(ui::trf(ui::Str::ClaimFailed, err), tile);+ }break;}if (!xcloud::claimFreeProduct(authHeader, offer, market, ui::catalogLanguage(), err)) {diff --git a/src/auth/auth_manager.cpp b/src/auth/auth_manager.cppindex 479dc7b..f23750f 100644--- a/src/auth/auth_manager.cpp+++ b/src/auth/auth_manager.cpp@@ -120,7 +120,10 @@ bool AuthManager::xboxChain(xcloud::GssvClient* gssv, std::string& err, bool ful// fall back to "d=" in case the service expects the MSAL form.if (!xblUserToken(tokens_.accessToken, "t=", user, err, &redirectUrl_)) {std::string err2;- if (!xblUserToken(tokens_.accessToken, "d=", user, err2, &redirectUrl_)) return false;+ if (err.find("HTTP ") == std::string::npos ||+ !xblUserToken(tokens_.accessToken, "d=", user, err2, &redirectUrl_)) {+ return false;+ }err.clear();}@@ -455,15 +458,44 @@ bool AuthManager::marketplaceAuthorization(std::string& outAuthHeader, std::strioutAuthHeader = marketplaceXsts_.authorizationHeader();return true;}- if (tokens_.accessToken.empty()) {- err = "not signed in";- return false;+ bool refreshedMsa = false;+ if (tokens_.accessToken.empty() || (tokens_.expiresAt > 0 && refreshDue(tokens_.expiresAt, unixNow()))) {+ if (tokens_.refreshToken.empty()) {+ err = "not signed in";+ return false;+ }+ MsaTokens t;+ if (!msa_.refresh(tokens_.refreshToken, t, err)) return false;+ if (t.userId.empty()) t.userId = tokens_.userId;+ tokens_ = t;+ save();+ refreshedMsa = true;}XblToken userToken;- if (!xblUserToken(tokens_.accessToken, "t=", userToken, err, &redirectUrl_)) {+ auto fetchUserToken = [&]() {+ if (xblUserToken(tokens_.accessToken, "t=", userToken, err, &redirectUrl_)) return true;std::string err2;- if (!xblUserToken(tokens_.accessToken, "d=", userToken, err2, &redirectUrl_)) return false;- err.clear();+ if (err.find("HTTP ") != std::string::npos &&+ xblUserToken(tokens_.accessToken, "d=", userToken, err2, &redirectUrl_)) {+ err.clear();+ return true;+ }+ return false;+ };+ if (!fetchUserToken()) {+ if (!refreshedMsa && !tokens_.refreshToken.empty() && err.find("HTTP ") != std::string::npos) {+ MsaTokens t;+ if (msa_.refresh(tokens_.refreshToken, t, err)) {+ if (t.userId.empty()) t.userId = tokens_.userId;+ tokens_ = t;+ save();+ if (!fetchUserToken()) return false;+ } else {+ return false;+ }+ } else {+ return false;+ }}if (!xstsToken(userToken, rp::kMarketplace, marketplaceXsts_, err, &redirectUrl_)) {return false;diff --git a/src/auth/msa.cpp b/src/auth/msa.cppindex ad546bb..88fb4a0 100644--- a/src/auth/msa.cpp+++ b/src/auth/msa.cpp@@ -50,9 +50,17 @@ std::string describe(const net::Response& r) {int64_t unixNow() { return static_cast<int64_t>(std::time(nullptr)); }bool MsaClient::startDeviceCode(DeviceCode& out, std::string& err) const {- auto r = postForm(kConnectUrl, {{"client_id", cfg_.clientId},- {"scope", cfg_.scope},- {"response_type", "device_code"}});+ net::Response r;+ constexpr int kTries = 3;+ for (int attempt = 1; attempt <= kTries; ++attempt) {+ r = postForm(kConnectUrl, {{"client_id", cfg_.clientId},+ {"scope", cfg_.scope},+ {"response_type", "device_code"}});+ bool transient = r.status == 0 || r.status == 408 || r.status == 429 || r.status >= 500;+ if (!transient || attempt == kTries) break;+ XC_LOGW("device code request: %s, trying again (%d/%d)", describe(r).c_str(), attempt + 1, kTries);+ platform::sleepMs(1000u << (attempt - 1));+ }auto j = json::parse(r.body);if (!r.ok() || !j) {err = "device code request failed: " + describe(r);diff --git a/src/net/http.cpp b/src/net/http.cppindex 39db7dc..bbb4090 100644--- a/src/net/http.cpp+++ b/src/net/http.cpp@@ -113,6 +113,16 @@ void setTimeouts(int fd, int timeoutMs) {int connectTcp(const std::string& host, int port, int timeoutMs, std::string& err) {uint32_t ip = 0;if (!platform::resolveIPv4(host, ip, err)) return -1;+ uint32_t hostOrderIp = ntohl(ip);+ char ipStr[32];+ std::snprintf(ipStr, sizeof ipStr, "%u.%u.%u.%u",+ (hostOrderIp >> 24) & 0xFF, (hostOrderIp >> 16) & 0xFF,+ (hostOrderIp >> 8) & 0xFF, hostOrderIp & 0xFF);+ if (host != "localhost" && host != "127.0.0.1" &&+ (hostOrderIp == 0 || (hostOrderIp >> 24) == 127)) {+ err = "DNS lookup failed for " + host + " (sinkhole IP " + ipStr + ")";+ return -1;+ }sockaddr_in sa{};sa.sin_family = AF_INET;sa.sin_port = htons(static_cast<uint16_t>(port));@@ -144,20 +154,20 @@ int connectTcp(const std::string& host, int port, int timeoutMs, std::string& erint connectTimeout = (timeoutMs > 0) ? std::min(timeoutMs, 10000) : 10000;int pr = ::poll(&pfd, 1, connectTimeout);if (pr <= 0) {- err = (pr == 0) ? "connect timed out to " + host + ":" + std::to_string(port)- : "poll failed connecting to " + host + ":" + std::to_string(port) + " (errno " + std::to_string(errno) + ")";+ err = (pr == 0) ? "connect timed out to " + host + ":" + std::to_string(port) + " [" + ipStr + "]"+ : "poll failed connecting to " + host + ":" + std::to_string(port) + " [" + ipStr + "] (errno " + std::to_string(errno) + ")";::close(fd);return -1;}int so_error = 0;socklen_t len = sizeof so_error;if (::getsockopt(fd, SOL_SOCKET, SO_ERROR, &so_error, &len) < 0 || so_error != 0) {- err = "connect failed to " + host + ":" + std::to_string(port) + " (errno " + std::to_string(so_error ? so_error : errno) + ")";+ err = "connect failed to " + host + ":" + std::to_string(port) + " [" + ipStr + "] (errno " + std::to_string(so_error ? so_error : errno) + ")";::close(fd);return -1;}} else {- err = "connect failed to " + host + ":" + std::to_string(port) + " (errno " + std::to_string(errno) + ")";+ err = "connect failed to " + host + ":" + std::to_string(port) + " [" + ipStr + "] (errno " + std::to_string(errno) + ")";::close(fd);return -1;}@@ -478,6 +488,79 @@ void shutdownTls() {namespace {+struct VerifyChainCtx {+ mbedtls_x509_crt* ca = nullptr;+ const char* host = nullptr;+ uint32_t deferredFlags = 0;+};++// Some regional Azure load balancers (e.g. CIA.core.gssv-play-prod.xboxlive.com+// in Central India) deliver intermediate certificates out of RFC 5246 order+// ([leaf, root, intermediate2, intermediate1] where intermediate1 signs leaf+// and intermediate2 signs intermediate1). Stock mbedTLS only searches+// child->next for each parent, failing with MBEDTLS_X509_BADCERT_NOT_TRUSTED.+// When that happens on a multi-certificate peer chain, reconstruct the+// issuer-ordered chain from the full peer list and re-verify it against `ca`.+int verifyPeerChainCallback(void* data, mbedtls_x509_crt* crt, int depth, uint32_t* flags) {+ auto* ctx = static_cast<VerifyChainCtx*>(data);+ if (!ctx || !ctx->ca || !crt || !flags) return 0;+ if (depth > 0) {+ if (*flags & MBEDTLS_X509_BADCERT_NOT_TRUSTED) {+ ctx->deferredFlags |= (*flags & MBEDTLS_X509_BADCERT_NOT_TRUSTED);+ *flags &= ~static_cast<uint32_t>(MBEDTLS_X509_BADCERT_NOT_TRUSTED);+ }+ return 0;+ }+ *flags |= ctx->deferredFlags;+ ctx->deferredFlags = 0;+ if (!(*flags & MBEDTLS_X509_BADCERT_NOT_TRUSTED) || !crt->next) return 0;++ std::vector<const mbedtls_x509_crt*> all;+ for (const mbedtls_x509_crt* c = crt; c != nullptr && all.size() < 16; c = c->next)+ all.push_back(c);++ std::vector<const mbedtls_x509_crt*> ordered;+ ordered.push_back(crt);+ bool orderChanged = false;+ while (ordered.size() < all.size()) {+ const mbedtls_x509_crt* child = ordered.back();+ const mbedtls_x509_crt* nextParent = nullptr;+ for (const mbedtls_x509_crt* cand : all) {+ if (std::find(ordered.begin(), ordered.end(), cand) != ordered.end()) continue;+ if (child->issuer_raw.len == cand->subject_raw.len &&+ std::memcmp(child->issuer_raw.p, cand->subject_raw.p, child->issuer_raw.len) == 0) {+ nextParent = cand;+ break;+ }+ }+ if (!nextParent) break;+ if (nextParent != child->next) orderChanged = true;+ ordered.push_back(nextParent);+ }+ if (!orderChanged) return 0;++ mbedtls_x509_crt reordered;+ mbedtls_x509_crt_init(&reordered);+ bool parsedOk = true;+ for (const mbedtls_x509_crt* c : ordered) {+ if (mbedtls_x509_crt_parse_der(&reordered, c->raw.p, c->raw.len) != 0) {+ parsedOk = false;+ break;+ }+ }+ if (parsedOk) {+ uint32_t newFlags = 0;+ int vrc = mbedtls_x509_crt_verify(&reordered, ctx->ca, nullptr, ctx->host, &newFlags, nullptr, nullptr);+ if (vrc == 0) {+ *flags = 0;+ } else if (vrc == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {+ *flags = newFlags;+ }+ }+ mbedtls_x509_crt_free(&reordered);+ return 0;+}+// One request on one connection: a kept-alive one from the pool when// `reuse` and there is one, else a new one. `stale` is set (and nothing// else is to be trusted in the answer) when a kept-alive connection failed@@ -530,6 +613,8 @@ Response exchange(const Request& req, const Url& url, bool reuse, bool& stale) {if (rc) return finish("ssl_config_defaults: " + tlsError(rc));mbedtls_ssl_conf_authmode(&conn->conf, MBEDTLS_SSL_VERIFY_REQUIRED);mbedtls_ssl_conf_ca_chain(&conn->conf, &g.ca, nullptr);+ VerifyChainCtx verifyCtx{&g.ca, url.host.c_str(), 0};+ mbedtls_ssl_conf_verify(&conn->conf, verifyPeerChainCallback, &verifyCtx);mbedtls_ssl_conf_rng(&conn->conf, mbedtls_ctr_drbg_random, &g.drbg);if ((rc = mbedtls_ssl_setup(&conn->ssl, &conn->conf))) return finish("ssl_setup: " + tlsError(rc));if ((rc = mbedtls_ssl_set_hostname(&conn->ssl, url.host.c_str()))) return finish("set_hostname: " + tlsError(rc));diff --git a/src/xcloud/purchase.cpp b/src/xcloud/purchase.cppindex e22885f..51165fd 100644--- a/src/xcloud/purchase.cpp+++ b/src/xcloud/purchase.cpp@@ -40,6 +40,9 @@ bool fetchPurchaseOffer(const std::string& productId, const std::string& market,out.skuId.clear();out.availabilityId.clear();+ PurchaseOffer fallbackFree{};+ PurchaseOffer fallbackAny{};+for (const auto& dsa : p["DisplaySkuAvailabilities"].items()) {std::string skuId = dsa["Sku"]["SkuId"].str();for (const auto& av : dsa["Availabilities"].items()) {@@ -48,19 +51,37 @@ bool fetchPurchaseOffer(const std::string& productId, const std::string& market,const auto& price = av["OrderManagementData"]["Price"];if (!purchase || !price.isObject()) continue;- out.skuId = skuId.empty() ? av["SkuId"].str() : skuId;- out.availabilityId = av["AvailabilityId"].str();- out.listPrice = price["ListPrice"].asNumber();- out.msrp = price["MSRP"].asNumber();- out.currency = price["CurrencyCode"].str();- if (out.listPrice <= 0.005 && out.msrp <= 0.005) {- out.isFree = true;- }- if (!out.availabilityId.empty()) {+ PurchaseOffer cand;+ cand.productId = productId;+ cand.skuId = skuId.empty() ? av["SkuId"].str() : skuId;+ cand.availabilityId = av["AvailabilityId"].str();+ cand.listPrice = price["ListPrice"].asNumber();+ cand.msrp = price["MSRP"].asNumber();+ cand.currency = price["CurrencyCode"].str();+ cand.isFree = (cand.listPrice <= 0.005 && cand.msrp <= 0.005);+ if (cand.availabilityId.empty()) continue;++ bool remediation = av["RemediationRequired"].asBool();+ if (cand.isFree && !remediation) {+ out = cand;return true;}+ if (cand.isFree && fallbackFree.availabilityId.empty()) {+ fallbackFree = cand;+ }+ if (fallbackAny.availabilityId.empty()) {+ fallbackAny = cand;+ }}}+ if (!fallbackFree.availabilityId.empty()) {+ out = fallbackFree;+ return true;+ }+ if (!fallbackAny.availabilityId.empty()) {+ out = fallbackAny;+ return true;+ }err = "no purchase availability found for " + productId;return false;}@@ -77,23 +98,40 @@ std::string uuid4() {return s;}+bool isAlreadyOwnedError(const net::Response& r) {+ if (r.body.find("UserAlreadyOwnsContent") != std::string::npos) return true;+ auto j = json::parse(r.body);+ if (!j) return false;+ return (*j)["innererror"]["code"].str() == "UserAlreadyOwnsContent" ||+ (*j)["code"].str() == "UserAlreadyOwnsContent";+}+std::string extractErrorDetail(const net::Response& r) {auto j = json::parse(r.body);if (!j) return r.error.empty() ? ("HTTP " + std::to_string(r.status)) : r.error;- if ((*j)["innererror"]["data"].isArray() && (*j)["innererror"]["data"].size() > 0 &&- (*j)["innererror"]["data"][0].isString()) {- return (*j)["innererror"]["data"][0].str();- }+ std::string innerCode = (*j)["innererror"]["code"].str();if ((*j)["innererror"]["details"].isArray() && (*j)["innererror"]["details"].size() > 0 &&(*j)["innererror"]["details"][0]["message"].isString()) {- return (*j)["innererror"]["details"][0]["message"].str();+ std::string msg = (*j)["innererror"]["details"][0]["message"].str();+ return innerCode.empty() ? msg : (innerCode + ": " + msg);}if ((*j)["innererror"]["message"].isString()) {- return (*j)["innererror"]["message"].str();+ std::string msg = (*j)["innererror"]["message"].str();+ return innerCode.empty() ? msg : (innerCode + ": " + msg);+ }+ if (!innerCode.empty()) {+ return innerCode;}if ((*j)["message"].isString()) {return (*j)["message"].str();}+ if ((*j)["code"].isString()) {+ return (*j)["code"].str();+ }+ if ((*j)["innererror"]["data"].isArray() && (*j)["innererror"]["data"].size() > 0 &&+ (*j)["innererror"]["data"][0].isString()) {+ return (*j)["innererror"]["data"][0].str();+ }return "HTTP " + std::to_string(r.status);}} // namespace@@ -153,6 +191,11 @@ bool claimFreeProduct(const std::string& marketplaceAuthHeader, const PurchaseOfauto r = net::perform(req);if (!r.ok()) {+ if (isAlreadyOwnedError(r)) {+ XC_LOGI("claimFreeProduct: account already owns %s (UserAlreadyOwnsContent on create)",+ offer.productId.c_str());+ return true;+ }err = extractErrorDetail(r);XC_LOGW("claimFreeProduct: create order failed for %s: %s (status %d)",offer.productId.c_str(), err.c_str(), r.status);@@ -172,6 +215,11 @@ bool claimFreeProduct(const std::string& marketplaceAuthHeader, const PurchaseOfauto finRes = net::perform(finReq);if (!finRes.ok()) {+ if (isAlreadyOwnedError(finRes)) {+ XC_LOGI("claimFreeProduct: account already owns %s (UserAlreadyOwnsContent on finalize)",+ offer.productId.c_str());+ return true;+ }err = extractErrorDetail(finRes);XC_LOGW("claimFreeProduct: finalize order failed for %s (order %s): %s (status %d)",offer.productId.c_str(), orderId.c_str(), err.c_str(), finRes.status);diff --git a/tests/test_main.cpp b/tests/test_main.cppindex ac87c60..2e47966 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -2472,15 +2472,62 @@ static void testPurchase() {auto putJson = json::parse(lastPutReq.body);CHECK(putJson && (*putJson)["orderState"].str() == "Purchased");- // 6. claimFreeProduct error handling+ // 6. claimFreeProduct error handling (must extract innererror code/message, not innererror.data[0] productId)net::setTestTransport([&](const net::Request&) {net::Response r;r.status = 400;- r.body = R"({"code":"PaymentRequired","innererror":{"message":"Payment method needed"}})";+ r.body = R"({"code":"PaymentRequired","innererror":{"code":"MissingPaymentInstrument","data":["FREE123"],"message":"Payment method needed"}})";return r;});CHECK(!claimFreeProduct("XBL3.0 x=test;token", offer, "US", "en-US", err));CHECK(err.find("Payment method needed") != std::string::npos);+ CHECK(err != "FREE123");++ // 7. UserAlreadyOwnsContent on finalize (HTTP 403, Issue #104) is treated as already acquired+ net::setTestTransport([&](const net::Request& req) {+ net::Response r;+ if (req.method == "POST") {+ r.status = 201;+ r.body = R"({"orderId":"ORDER-12345","orderState":"Editing"})";+ } else {+ r.status = 403;+ r.body = R"({"code":"Forbidden","innererror":{"code":"UserAlreadyOwnsContent","data":["9P22THR57FV7"],"message":"Purchase policy restricts user from purchasing certain content multiple times"}})";+ }+ return r;+ });+ CHECK(claimFreeProduct("XBL3.0 x=test;token", offer, "US", "en-US", err));++ // 8. fetchPurchaseOffer skips RemediationRequired upsells and picks the non-remediated free availability+ net::setTestTransport([&](const net::Request&) {+ net::Response r;+ r.status = 200;+ r.body = R"({+ "Products": [{+ "DisplaySkuAvailabilities": [{+ "Sku": {"SkuId": "0001"},+ "Availabilities": [+ {+ "AvailabilityId": "AVAIL_UPSELL_REMEDIATION",+ "Actions": ["Purchase"],+ "RemediationRequired": true,+ "OrderManagementData": {"Price": {"ListPrice": 0.0, "MSRP": 0.0, "CurrencyCode": "USD"}}+ },+ {+ "AvailabilityId": "AVAIL_DIRECT_FREE",+ "Actions": ["Purchase"],+ "RemediationRequired": false,+ "OrderManagementData": {"Price": {"ListPrice": 0.0, "MSRP": 0.0, "CurrencyCode": "USD"}}+ }+ ]+ }]+ }]+ })";+ return r;+ });+ PurchaseOffer directOffer;+ CHECK(fetchPurchaseOffer("FREE123", "US", "en-us", directOffer, err));+ CHECK(directOffer.isFree);+ CHECK(directOffer.availabilityId == "AVAIL_DIRECT_FREE");net::setTestTransport({});}