Play your Steam library's Windows games on a jailbroken PS5.
C++
Name a DNS-blocked Steam Cloud storage host
Leonardo Lobatob17df49d5039
diff --git a/src/steam/backend/cloud_sync.cpp b/src/steam/backend/cloud_sync.cppindex e4ef97c..62aaf8d 100644--- a/src/steam/backend/cloud_sync.cpp+++ b/src/steam/backend/cloud_sync.cpp@@ -802,7 +802,10 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatirequest.max_response_bytes = static_cast<std::size_t>(std::max<std::uint64_t>(ticket->file_size, 1));const auto response = hooks_.http(request, cancel);if (!response.ok() || response.status_code != 200) {- failure = "A Cloud save could not be downloaded. Try again.";+ // A DNS server that blocks the storage host (a sinkhole address) fails here every time.+ failure = response.error == HttpError::kNameResolutionFailed+ ? "The PS5 couldn't reach Steam Cloud's storage. Check its DNS settings, then try again."+ : "A Cloud save could not be downloaded. Try again.";detail = named + " http error=" + HttpFailureName(response) + " status=" + std::to_string(response.status_code) +" host=" + ticket->host + " file_size=" + std::to_string(ticket->file_size) +" raw_size=" + std::to_string(ticket->raw_file_size) + " body=" + std::to_string(response.body.size());diff --git a/src/steam/backend/http_client.cpp b/src/steam/backend/http_client.cppindex 69f3c78..4f717a2 100644--- a/src/steam/backend/http_client.cpp+++ b/src/steam/backend/http_client.cpp@@ -210,6 +210,7 @@ const char* HttpErrorName(HttpError error) {std::string HttpFailureName(const HttpResponse& response) {std::string name = HttpErrorName(response.error);if (response.transport_code != 0) name += " curl=" + std::to_string(response.transport_code);+ if (!response.ok() && !response.address.empty()) name += " addr=" + response.address;return name;}@@ -305,6 +306,7 @@ class HttpClient::Impl {const auto start = Clock::now();resolve_error = resolution_cache_.Attach(easy, request.url, request.timeout_ms, cancel,&resolve_entries_, Clock::now());+ transfer.response.address = resolution_cache_.address();#if PLAYDEN_PLATFORM_PS5transfer.response.timing.resolve_ms = static_cast<std::uint32_t>(std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start).count());diff --git a/src/steam/backend/http_client.h b/src/steam/backend/http_client.hindex ce7f3a7..f67a4fc 100644--- a/src/steam/backend/http_client.h+++ b/src/steam/backend/http_client.h@@ -70,11 +70,15 @@ struct HttpResponse {// The transport library's numeric result code when the transfer failed (0 otherwise), for logs:// several codes share one HttpError, such as a TLS handshake failure and kProtocolError.int transport_code = 0;+ // The server's numeric address from the console's resolver, for logs (empty on host builds, where+ // curl resolves): a DNS server that blocks a host answers one no server listens on.+ std::string address;bool ok() const { return error == HttpError::kNone; }};-// HttpErrorName plus the transport code when there is one, such as "protocol_error curl=35".+// HttpErrorName plus the transport code and the server's address when there are, such as+// "connection_failed curl=7 addr=203.0.113.5".std::string HttpFailureName(const HttpResponse& response);// One worker thread owns each instance and calls Perform synchronously. The cancel flag may bediff --git a/src/steam/backend/native_network.cpp b/src/steam/backend/native_network.cppindex 9437d08..f688a57 100644--- a/src/steam/backend/native_network.cpp+++ b/src/steam/backend/native_network.cpp@@ -131,6 +131,10 @@ bool InitializeNativeNetwork() {#endif}+bool UnusableResolvedAddress(const std::string& numeric) {+ return numeric == "0.0.0.0" || numeric.rfind("127.", 0) == 0;+}+NativeResolveError AttachNativeResolution(CURL* easy, const std::string& url,std::uint32_t timeout_ms,const std::atomic<bool>& cancel,@@ -175,7 +179,9 @@ NativeResolveError AttachNativeResolution(CURL* easy, const std::string& url,ok = false;} else {ok = native_result == 0 && inet_ntop(AF_INET, &address, numeric, sizeof(numeric));- resolve_error = ok ? NativeResolveError::kNone : NativeResolveError::kFailed;+ resolve_error = !ok ? NativeResolveError::kFailed+ : UnusableResolvedAddress(numeric) ? NativeResolveError::kUnusableAddress+ : NativeResolveError::kNone;}} else {ok = false;@@ -189,6 +195,8 @@ NativeResolveError AttachNativeResolution(CURL* easy, const std::string& url,ok = curl_easy_setopt(easy, CURLOPT_RESOLVE, *entries) == CURLE_OK;}if (!ok) resolve_error = NativeResolveError::kFailed;+ // Attached for the log only: the caller refuses the request before curl runs it.+ if (resolve_error == NativeResolveError::kUnusableAddress) ok = false;}if (resolver >= 0) sceNetResolverDestroy(resolver);if (pool >= 0) sceNetPoolDestroy(pool);diff --git a/src/steam/backend/native_network.h b/src/steam/backend/native_network.hindex a7edc04..6a9949b 100644--- a/src/steam/backend/native_network.h+++ b/src/steam/backend/native_network.h@@ -25,8 +25,14 @@ enum class NativeResolveError {kFailed,kTimeout,kCanceled,+ // The DNS server answered an address no server listens on (0.0.0.0 or loopback): a blocking DNS+ // server's answer. The entries list still holds it, for the log.+ kUnusableAddress,};+// True for a resolved IPv4 address in dotted form that can't reach a server: 0.0.0.0 or 127.0.0.0/8.+bool UnusableResolvedAddress(const std::string& numeric);+NativeResolveError AttachNativeResolution(CURL* easy, const std::string& url,std::uint32_t timeout_ms,const std::atomic<bool>& cancel,diff --git a/src/steam/backend/native_resolution_cache.h b/src/steam/backend/native_resolution_cache.hindex 389cf81..cc7c105 100644--- a/src/steam/backend/native_resolution_cache.h+++ b/src/steam/backend/native_resolution_cache.h@@ -65,6 +65,7 @@ class NativeResolutionCache {NativeResolveError Attach(CURL* easy, const std::string& url, std::uint32_t timeout_ms,const std::atomic<bool>& cancel, curl_slist** active,Clock::time_point now) {+ address_.clear();if (!easy || !active) return NativeResolveError::kFailed;curl_slist_free_all(*active);*active = nullptr;@@ -82,6 +83,11 @@ class NativeResolutionCache {replacement = cached->resolution;} else {const auto error = resolver_(easy, url, timeout_ms, cancel, active);+ if (error == NativeResolveError::kUnusableAddress && *active) {+ // Never cached; the next request asks the DNS server again.+ const std::string refused = (*active)->data;+ address_ = refused.substr(refused.rfind(':') + 1);+ }if (error != NativeResolveError::kNone) return error;// Host builds deliberately leave the list null and use curl's normal resolver.if (!*active) return NativeResolveError::kNone;@@ -118,14 +124,20 @@ class NativeResolutionCache {return now >= entry.expires || entry.key == evicted_key;}), entries_.end());if (cache_miss) entries_.push_back({key, replacement, now + std::chrono::minutes(5)});+ address_ = replacement.substr(replacement.rfind(':') + 1);return NativeResolveError::kNone;}+ // The numeric address the last Attach gave curl, or the unusable one it refused; empty when the+ // resolver left the choice to curl (host builds) or failed.+ const std::string& address() const { return address_; }+private:struct Entry { std::string key, resolution; Clock::time_point expires; };static constexpr std::size_t kCapacity = 32;Resolver resolver_;std::vector<Entry> entries_;+ std::string address_;};} // namespace playden::steam::internaldiff --git a/tests/http_client_test.cpp b/tests/http_client_test.cppindex 26fdf55..365eb6a 100644--- a/tests/http_client_test.cpp+++ b/tests/http_client_test.cpp@@ -229,6 +229,18 @@ int main(int argc, char** argv) {Check(response.transport_code == 60 &&playden::steam::HttpFailureName(response) == "tls_verification_failed curl=60","a transport failure should keep curl's code for diagnostics");+ {+ // The console's resolver records the address; a failure names it, a success doesn't.+ playden::steam::HttpResponse blocked;+ blocked.error = HttpError::kConnectionFailed;+ blocked.transport_code = 7;+ blocked.address = "0.0.0.0";+ Check(playden::steam::HttpFailureName(blocked) == "connection_failed curl=7 addr=0.0.0.0",+ "a failure should name the server address when it is known");+ blocked.error = HttpError::kNone;+ blocked.transport_code = 0;+ Check(playden::steam::HttpFailureName(blocked) == "none", "a success names no address");+ }HttpRequest invalid_header = get;invalid_header.headers.emplace_back("Bad\r\nInjected", "value");diff --git a/tests/native_resolution_cache_test.cpp b/tests/native_resolution_cache_test.cppindex d8ac639..b6cbdd8 100644--- a/tests/native_resolution_cache_test.cpp+++ b/tests/native_resolution_cache_test.cpp@@ -18,6 +18,12 @@ void Check(bool condition, const char* message) {NativeResolveError Resolve(CURL* easy, const std::string& url, std::uint32_t,const std::atomic<bool>&, curl_slist** entries) {++calls;+ if (next_error == NativeResolveError::kUnusableAddress) {+ // As the console resolver does: the refused answer stays attached for the log, and the caller never performs.+ *entries = curl_slist_append(nullptr, (NativeResolutionCache::Key(url) + ":0.0.0.0").c_str());+ curl_easy_setopt(easy, CURLOPT_RESOLVE, *entries);+ return next_error;+ }if (next_error != NativeResolveError::kNone) return next_error;const std::string entry = NativeResolutionCache::Key(url) + ":" + address;*entries = curl_slist_append(nullptr, entry.c_str());@@ -85,6 +91,12 @@ void NoCachedAddress(CURLM* multi, const std::string& url) {} // namespaceint main() {Check(curl_global_init(CURL_GLOBAL_DEFAULT) == CURLE_OK, "curl initializes");+ Check(UnusableResolvedAddress("0.0.0.0") && UnusableResolvedAddress("127.0.0.1") &&+ UnusableResolvedAddress("127.255.0.9"),+ "a blocking DNS server's answers are unusable");+ Check(!UnusableResolvedAddress("142.250.203.219") && !UnusableResolvedAddress("10.0.1.9") &&+ !UnusableResolvedAddress("1.27.0.1"),+ "public and private addresses stay usable");std::atomic<bool> cancel{false};const auto start = NativeResolutionCache::Clock::time_point{};const std::string first = "https://CDN.EXAMPLE/chunk";@@ -128,9 +140,22 @@ int main() {Check(attach(first, start + std::chrono::minutes(5)) == NativeResolveError::kNone && calls == before_failure + 2,"native failure, timeout and cancel are never cached");}+ next_error = NativeResolveError::kUnusableAddress;+ cache.ResetTransport(multi);+ const auto before_unusable = calls;+ Check(attach(first, start + std::chrono::minutes(5)) == NativeResolveError::kUnusableAddress &&+ cache.address() == "0.0.0.0",+ "an unusable answer is refused and keeps its address for the log");+ Check(attach(first, start + std::chrono::minutes(5)) == NativeResolveError::kUnusableAddress &&+ calls == before_unusable + 2,+ "an unusable answer is never cached");+ next_error = NativeResolveError::kNone;+ Check(attach(first, start + std::chrono::minutes(5)) == NativeResolveError::kNone && cache.address() == address,+ "the address of an attached answer is kept for the log");next_error = NativeResolveError::kFailed;cache.ResetTransport(multi);- Check(attach(first, start + std::chrono::minutes(5)) == NativeResolveError::kFailed, "resolution failure propagates");+ Check(attach(first, start + std::chrono::minutes(5)) == NativeResolveError::kFailed && cache.address().empty(),+ "resolution failure propagates");next_error = NativeResolveError::kNone;const auto before_retry = calls;Check(attach(first, start + std::chrono::minutes(5)) == NativeResolveError::kNone && calls == before_retry + 1,@@ -187,6 +212,28 @@ int main() {Check(multi != nullptr, "failed transport recreates bounded multi");NoCachedAddress(multi, failed);+ // A refused (sinkhole) answer is attached to an easy handle that is never performed; the caller resets the+ // transport. The next request resolves again and curl uses only the new address.+ next_error = NativeResolveError::kUnusableAddress;+ const std::string blocked = "https://blocked-dns.invalid/";+ Probe refused;+ CURL* refused_easy = Easy(blocked, refused);+ Check(cache.Attach(refused_easy, blocked, 1000, cancel, &entries, start) == NativeResolveError::kUnusableAddress &&+ cache.address() == "0.0.0.0",+ "a refused answer is reported with its address");+ curl_easy_cleanup(refused_easy);+ cache.ResetTransport(multi);+ NoCachedAddress(multi, blocked);+ next_error = NativeResolveError::kNone;+ Probe retried;+ CURL* retry_easy = Easy(blocked, retried);+ Check(cache.Attach(retry_easy, blocked, 1000, cancel, &entries, start) == NativeResolveError::kNone &&+ cache.address() == address,+ "the next request resolves again after a refused answer");+ Perform(multi, retry_easy);+ Check(retried.socket_attempts == 1, "the retry connects with the newly resolved address");+ cache.ResetTransport(multi);+// Expiry builds a removal list, but cancellation/deadline before perform never consumes it.Probe expired_seed;easy = Easy(failed, expired_seed);diff --git a/tests/steam_cloud_test.cpp b/tests/steam_cloud_test.cppindex 3f01337..92d1fdc 100644--- a/tests/steam_cloud_test.cpp+++ b/tests/steam_cloud_test.cpp@@ -169,6 +169,7 @@ struct FakeCloud {bool corrupt_downloads = false;long download_status = 200; // another status refuses every downloadint download_transport_code = 0; // nonzero fails every download in transport with this curl code+ std::string download_blocked_address; // nonempty: every download's host resolves to this unusable addressstd::uint64_t next_batch = 700;std::map<std::string, std::vector<std::uint8_t>> pending; // uploads in the open batchstd::vector<std::string> pending_deletes;@@ -286,6 +287,13 @@ struct FakeCloud {response.status_code = download_status;response.body.clear();}+ if (!download_blocked_address.empty()) {+ response.error = HttpError::kNameResolutionFailed;+ response.transport_code = 6; // CURLE_COULDNT_RESOLVE_HOST+ response.address = download_blocked_address;+ response.status_code = 0;+ response.body.clear();+ }if (download_transport_code != 0) {response.error = HttpError::kProtocolError;response.transport_code = download_transport_code;@@ -575,6 +583,15 @@ void SyncEndToEnd() {CHECK(outcome.detail.find(" http error=protocol_error curl=35 status=0 ") != std::string::npos);cloud.download_transport_code = 0;+ // A DNS server that blocks the storage host: the player is pointed at the PS5's DNS settings, and the+ // log names the address it answered.+ plan = sync.Check(session, location, cancel);+ cloud.download_blocked_address = "0.0.0.0";+ outcome = sync.Apply(session, location, plan, Resolution::kUseCloud, true, cancel);+ CHECK(!outcome.ok && outcome.message == "The PS5 couldn't reach Steam Cloud's storage. Check its DNS settings, then try again.");+ CHECK(outcome.detail.find(" http error=name_resolution_failed curl=6 addr=0.0.0.0 status=0 ") != std::string::npos);+ cloud.download_blocked_address.clear();+// A game without Steam Cloud says so.cloud.declares_ufs = false;plan = sync.Check(session, location, cancel);