diff --git a/README.md b/README.md index 84b6bbcd79..dcc90bd5be 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V
Stores -- Epic Games and GOG build on [Phobos](https://github.com/phobos665)'s adaptation of [Legendary](https://github.com/legendary-gl/legendary) and [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl). GOG install script registry entries are read the way [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher) (GPL-3.0) reads them. +- Epic Games and GOG build on [Phobos](https://github.com/phobos665)'s adaptation of [Legendary](https://github.com/legendary-gl/legendary) and [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl). GOG install script registry entries are read the way [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher) (GPL-3.0) reads them. GOG cloud storage requests send the Galaxy communication-service User-Agent that gogdl and [Lutris](https://github.com/lutris/lutris) (GPL-3.0) send. - Epic's official Linux launcher preview runs through FEX. That setup is outside Epic's listed Linux support. - The launcher's .deb gets the WebKitGTK and GTK 3 libraries it needs from unmodified [Debian](https://www.debian.org) 13 packages, following [@zooluis](https://github.com/zooluis)'s research in [#2268](https://github.com/Droid-Deck/DroidDeck/pull/2268). - Battle.net is by [@kayakyakr](https://github.com/kayakyakr). It runs Blizzard's own client in Proton (downloaded from Blizzard, not included) and shows key art from the [Battle.net Shop](https://shop.battle.net). Without Steam, its games see the pad as an Xbox 360 controller via `PROTON_SPOOF_STEAMINPUT_VIDPID` in [Proton](https://github.com/ValveSoftware/wine)'s `dlls/winebus.sys`. diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt index 106719d559..45b1be5429 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt @@ -25,9 +25,11 @@ object CloudSaves { private const val PARALLEL = 6 private const val CLOUD_LAYOUT = 2 - class Result(val result: String, val files: Int, val bytes: Long, val reason: String, val conflicts: Int = 0) { + class Result(val result: String, val files: Int, val bytes: Long, val reason: String, val conflicts: Int = 0, val detail: String = "") { val ok: Boolean get() = result != "failed" - val line: String get() = "result=$result files=$files bytes=$bytes reason=$reason" + if (conflicts > 0) " conflicts=$conflicts" else "" + val line: String get() = "result=$result files=$files bytes=$bytes reason=$reason" + + (if (conflicts > 0) " conflicts=$conflicts" else "") + + if (detail.isNotEmpty()) " detail=\"$detail\"" else "" } class Status(val supported: Boolean, val folder: File?, val lastSync: Long, val reason: String, val conflicts: List = emptyList()) @@ -126,7 +128,7 @@ object CloudSaves { ) if (picked == null) GogConfig("", "") else GogConfig(picked.name, picked.template) } catch (e: Exception) { - Log.w(TAG, "gog remote-config: ${e.javaClass.simpleName}") + Log.w(TAG, "gog remote-config: ${cloudFailureDetail(e)}") null } } @@ -166,7 +168,7 @@ object CloudSaves { val galaxy = GogAuth.validToken(context) val clientId = gogClientId(context, id, folder) if (userId.isEmpty() || galaxy == null || clientId == null) null - else GogCloud(userId, clientId, gogScopedToken(context, id, clientId) ?: galaxy, gogLocationName(context, id, folder)) + else GogCloud(userId, clientId, gogScopedToken(context, id, clientId) ?: galaxy, gogLocationName(context, id, folder), tempDir = context.cacheDir) } Store.EPIC -> { val token = EpicCredentialStore.getValidAccessToken(context) @@ -312,7 +314,7 @@ object CloudSaves { rememberNoCloud(prefs(context, store), id) Result("skipped", 0, 0, "no-cloud-saves") } catch (e: Exception) { - Result("failed", 0, 0, e.javaClass.simpleName) + Result("failed", 0, 0, e.javaClass.simpleName, detail = cloudFailureDetail(e)) } return done(store, id, way, result) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt index ecf318068e..2971bb61ca 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt @@ -59,6 +59,69 @@ private fun httpDate(s: String?): Long = try { SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US).apply { timeZone = TimeZone.getTimeZone("GMT") }.parse(s!!.trim())?.time ?: -1L } catch (e: Exception) { -1L } +private val SECRET_PARAM = Regex("(?i)(token|secret|code|password|authorization)([\"']?\\s*[:=]\\s*[\"']?)[^\\s&\"',;}]+") +private val BEARER = Regex("(?i)bearer\\s+\\S+") +private val URL_TEXT = Regex("(?i)https?://(?:[^/\\s?#@]*@)?([^/\\s?#@]+)[^\\s]*") +private val LONG_TOKEN = Regex("[A-Za-z0-9._~+/=-]{32,}") +private val SPACES = Regex("\\s+") +private const val DETAIL_MAX = 400 + +internal fun scrubCloudText(text: String, longTokens: Boolean = true): String = text + .replace(BEARER, "Bearer ") + .replace(URL_TEXT) { it.groupValues[1] } + .replace(SECRET_PARAM) { it.groupValues[1] + it.groupValues[2] + "" } + .let { if (longTokens) it.replace(LONG_TOKEN, "") else it } + .replace(SPACES, " ") + .trim() + +internal fun cloudFailureDetail(e: Throwable): String { + val parts = ArrayList() + var t: Throwable? = e + while (t != null && parts.size < 3) { + val message = t.message?.let { scrubCloudText(it, longTokens = false) }.orEmpty() + parts += if (message.isEmpty()) t.javaClass.simpleName else "${t.javaClass.simpleName}: $message" + t = t.cause?.takeIf { it !== t } + } + return parts.joinToString(" <- ").take(DETAIL_MAX) +} + +private const val SNIPPET_READ_MAX = 4096 +private const val SNIPPET_MAX = 120 + +private data class CloudErrorPrefix(val text: String, val truncated: Boolean) { + fun snippet(): String { + val safe = if (truncated) text.substring(0, text.indexOfLast { it.isWhitespace() }.coerceAtLeast(0)) else text + return scrubCloudText(safe).take(SNIPPET_MAX) + } +} + +private fun cloudErrorPrefix(input: InputStream?): CloudErrorPrefix { + if (input == null) return CloudErrorPrefix("", false) + return input.use { stream -> + val buffer = ByteArray(SNIPPET_READ_MAX + 1) + var read = 0 + while (read < buffer.size) { + val n = stream.read(buffer, read, buffer.size - read) + if (n < 0) break + read += n + } + CloudErrorPrefix(buffer.decodeToString(0, minOf(read, SNIPPET_READ_MAX)), read > SNIPPET_READ_MAX) + } +} + +internal fun cloudErrorSnippet(input: InputStream?): String = + cloudErrorPrefix(input).snippet() + +private fun HttpURLConnection.errorSnippet(): String = + runCatching { cloudErrorSnippet(errorStream) }.getOrDefault("") + +private fun httpFailure(step: String, name: String?, code: Int, error: String): java.io.IOException = + java.io.IOException(buildString { + append("GOG cloud ").append(step).append(" HTTP ").append(code) + if (name != null) append(" file=").append(name) + if (error.isNotEmpty()) append(" body=").append(error) + }) + internal fun isGzip(data: ByteArray) = data.size >= 10 && data[0] == 0x1f.toByte() && data[1] == 0x8b.toByte() && data[2] == 0x08.toByte() @@ -183,6 +246,8 @@ private fun gzipFile(src: File, dst: File): GzipFile { } } +internal const val GOG_CLOUD_UA = "GOGGalaxyCommunicationService/2.0.13.27 (Windows_32bit) dont_sync_marker/true installation_source/gog" + /** GOG Galaxy parses `X-Object-Meta-LocalLastModified`; objects without it fail as "invalid data". */ private val GOG_STAMP = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx", Locale.US) @@ -195,9 +260,10 @@ class GogCloud( private val token: String, private val location: String? = null, baseUrl: String? = null, + private val tempDir: File? = null, ) : CloudTransport { private val base = baseUrl ?: "https://cloudstorage.gog.com/v1/$userId/$clientId" - private val ua = "GOG Galaxy" + private val ua = GOG_CLOUD_UA private var prefix: String? = location?.let { "$it/" } private fun key(name: String) = URLEncoder.encode(name, "UTF-8").replace("+", "%20") @@ -209,10 +275,10 @@ class GogCloud( val code = c.responseCode if (code == 404) { c.disconnect(); return emptyList() } if (code !in 200..299) { - val err = runCatching { c.errorStream?.readBytes()?.decodeToString().orEmpty() }.getOrDefault("") + val err = runCatching { cloudErrorPrefix(c.errorStream) }.getOrDefault(CloudErrorPrefix("", false)) c.disconnect() - if ("not_enabled_for_client" in err || "disabled" in err) throw NoCloudSaves() - throw java.io.IOException("GOG cloud list HTTP $code") + if ("not_enabled_for_client" in err.text || "disabled" in err.text) throw NoCloudSaves() + throw httpFailure("list", null, code, err.snippet()) } val text = c.body().decodeToString().trim() c.disconnect() @@ -255,12 +321,20 @@ class GogCloud( override fun get(file: CloudFile): Pair { val c = open("$base/${cloudKey(file.name)}", "GET", token, ua) c.setRequestProperty("Accept-Encoding", "identity") - if (c.responseCode !in 200..299) { val code = c.responseCode; c.disconnect(); throw java.io.IOException("GOG cloud get HTTP $code") } + if (c.responseCode !in 200..299) { + val code = c.responseCode + val err = c.errorSnippet() + c.disconnect() + throw httpFailure("get", file.name, code, err) + } val modified = httpDate(c.getHeaderField("Last-Modified")) val encoding = c.getHeaderField("Content-Encoding") - val data = c.body() - c.disconnect() - return gogDecodeCloudBody(data, encoding) to modified + val data = try { c.body() } finally { c.disconnect() } + return try { + gogDecodeCloudBody(data, encoding) to modified + } catch (e: java.io.IOException) { + throw java.io.IOException("GOG cloud get file=${file.name} bytes=${data.size} encoding=$encoding", e) + } } override fun put(files: Map, modifiedMs: Map): Map = files.mapValues { (name, data) -> @@ -269,7 +343,11 @@ class GogCloud( } override fun putFiles(files: Map, modifiedMs: Map): Map = files.mapValues { (name, file) -> - val compressed = File.createTempFile("gog-cloud-", ".gz") + val compressed = try { + File.createTempFile("gog-cloud-", ".gz", tempDir?.apply { mkdirs() }) + } catch (e: java.io.IOException) { + throw java.io.IOException("GOG cloud put file=$name temp file", e) + } try { val gz = gzipFile(file, compressed) val modified = putBody(name, compressed.inputStream(), gz.length, gz.etag, modifiedMs[name] ?: file.lastModified()) @@ -287,10 +365,16 @@ class GogCloud( c.setRequestProperty("Content-Encoding", "gzip") c.setRequestProperty("Etag", etag) c.setRequestProperty("X-Object-Meta-LocalLastModified", gogStamp(modified)) + c.setRequestProperty("X-Object-Meta-User-Agent", ua) c.setFixedLengthStreamingMode(length) - c.outputStream.use { out -> source.use { it.copyTo(out, 64 * 1024) } } + try { + c.outputStream.use { out -> source.use { it.copyTo(out, 64 * 1024) } } + } catch (e: java.io.IOException) { + val code = runCatching { c.responseCode }.getOrNull() + throw java.io.IOException("GOG cloud put file=$name bytes=$length" + (code?.let { " HTTP $it" } ?: ""), e) + } val code = c.responseCode - if (code !in 200..299) throw java.io.IOException("GOG cloud put HTTP $code") + if (code !in 200..299) throw httpFailure("put", name, code, c.errorSnippet()) return CloudFile(name, -1L).also { details(it) }.modifiedMs } finally { c.disconnect() diff --git a/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt index 025dbce9b8..d6667e2a12 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt @@ -59,15 +59,193 @@ class GogCloudKeysTest { @Test fun putUploadsTheGogGzipBodyWithEncodingAndCompressedHash() { val raw = "savegame0".toByteArray() - val server = java.net.ServerSocket(0, 4, java.net.InetAddress.getByName("127.0.0.1")) - val requests = java.util.concurrent.CopyOnWriteArrayList() - val worker = Thread { - repeat(2) { + val requests = serve(2, ::okResponse) { url -> + val cloud = GogCloud("user", "client", "token", "saves", url) + val source = java.io.File.createTempFile("save", ".sav").apply { writeBytes(raw) } + val result = try { + cloud.putFiles(mapOf("save.sav" to source), mapOf("save.sav" to 1_793_490_825_000L)).getValue("save.sav") + } finally { + source.delete() + } + assertTrue(result.modifiedMs > 0) + assertEquals(CloudSaves.md5(raw), result.md5) + } + val put = requests[0] + assertEquals("PUT", put.method) + assertEquals("/v1/user/client/saves%2Fsave.sav", put.path) + assertEquals("gzip", put.headers["content-encoding"]) + assertEquals("2026-10-31T23:53:45+00:00", put.headers["x-object-meta-locallastmodified"]) + assertArrayEquals(gzipGogPut(raw), put.body) + assertEquals(CloudSaves.md5(put.body), put.headers["etag"]) + assertArrayEquals(raw, gogDecodeCloudBody(put.body, put.headers["content-encoding"])) + assertEquals("HEAD", requests[1].method) + } + + @Test fun putStagesInAMissingTempDirByCreatingIt() { + val root = java.nio.file.Files.createTempDirectory("gog-cloud-test").toFile() + val temp = java.io.File(root, "cache") + val source = java.io.File(root, "save.sav").apply { writeBytes("savegame0".toByteArray()) } + try { + val requests = serve(2, ::okResponse) { url -> + GogCloud("user", "client", "token", "saves", url, tempDir = temp).putFiles(mapOf("save.sav" to source)) + } + assertEquals("PUT", requests[0].method) + assertTrue(temp.isDirectory) + assertEquals(0, temp.listFiles()!!.size) + } finally { + temp.delete(); source.delete(); root.delete() + } + } + + @Test fun rejectedPutNamesStepStatusAndFileWithoutTheToken() { + val secret = "eyJhbGciOiJIUzI1NiJ9.c2VjcmV0LXRva2VuLXZhbHVlLWxvbmc.c2lnbmF0dXJl" + val source = java.io.File.createTempFile("save", ".sav").apply { writeBytes("savegame0".toByteArray()) } + try { + val failure = runCatching { + serve(1, { _ -> + val body = "{\"error\":\"invalid_grant\",\"access_token\":\"$secret\"}" + "HTTP/1.1 403 Forbidden\r\nContent-Length: ${body.length}\r\nConnection: close\r\n\r\n$body" + }) { url -> GogCloud("user", "client", secret, "saves", url).putFiles(mapOf("Save 3.ess" to source)) } + }.exceptionOrNull() + assertTrue(failure is java.io.IOException) + val detail = cloudFailureDetail(failure!!) + assertTrue(detail, detail.contains("GOG cloud put HTTP 403 file=Save 3.ess")) + assertTrue(detail, detail.contains("invalid_grant")) + assertFalse(detail, detail.contains(secret)) + } finally { + source.delete() + } + } + + @Test fun failureDetailKeepsTheCauseChainAndDropsCredentials() { + val e = java.io.IOException( + "GOG cloud put file=Save12_C2B8E7B0_0_507269736F6E6572_Tamriel_000027.ess bytes=10", + java.io.IOException("refused https://auth.gog.com/token?client_secret=abc&refresh_token=def Bearer xyz123", java.net.UnknownHostException("cloudstorage.gog.com")), + ) + val detail = cloudFailureDetail(e) + assertTrue(detail, detail.startsWith("IOException: GOG cloud put file=Save12_C2B8E7B0_0_507269736F6E6572_Tamriel_000027.ess")) + assertTrue(detail, detail.contains("IOException: refused auth.gog.com")) + assertTrue(detail, detail.endsWith("UnknownHostException: cloudstorage.gog.com")) + for (leak in listOf("abc", "def", "xyz123", "client_secret", "/token")) assertFalse(detail, detail.contains(leak)) + assertEquals("IOException", cloudFailureDetail(java.io.IOException())) + } + + @Test fun urlCredentialsAreDroppedAndOnlyTheHostIsKept() { + val scrubbed = scrubCloudText("see https://alice:shortpass@example.com/private?x=1 and http://bob@gog.com:443/a") + assertEquals("see example.com and gog.com:443", scrubbed) + assertEquals("cloudstorage.gog.com", scrubCloudText("https://cloudstorage.gog.com/v1/user/saves")) + } + + @Test fun errorSnippetReadsABoundedPrefixAndDropsATokenCutAtTheBoundary() { + val read = java.util.concurrent.atomic.AtomicLong() + val huge = object : java.io.InputStream() { + override fun read(): Int { read.incrementAndGet(); return 'a'.code } + override fun read(b: ByteArray, off: Int, len: Int): Int { + val prefix = "invalid_grant " + for (i in 0 until len) { + val at = read.getAndIncrement() + b[off + i] = (if (at < prefix.length) prefix[at.toInt()] else 'q').code.toByte() + } + return len + } + } + val snippet = cloudErrorSnippet(huge) + assertTrue(read.get() <= 4097) + assertEquals("invalid_grant", snippet) + val cut = " ".repeat(4090) + "pw=shortsecretvalue-continues" + assertEquals("", cloudErrorSnippet(cut.byteInputStream())) + assertEquals("pw=shortsecretvalue-continues", cloudErrorSnippet((" ".repeat(10) + "pw=shortsecretvalue-continues").byteInputStream())) + assertEquals("forbidden", cloudErrorSnippet("forbidden".byteInputStream())) + assertEquals("", cloudErrorSnippet(null)) + } + + @Test fun everyCloudRequestIdentifiesAsTheGalaxyCommunicationService() { + val raw = "savegame0".toByteArray() + val requests = serve(5, { request -> + when { + request.method == "GET" && request.path == "/v1/user/client" -> + "HTTP/1.1 200 OK\r\nContent-Length: 14\r\nConnection: close\r\n\r\nsaves/save.sav" + request.method == "GET" -> + "HTTP/1.1 200 OK\r\nContent-Length: ${raw.size}\r\nConnection: close\r\n\r\n${raw.decodeToString()}" + else -> okResponse(request) + } + }) { url -> + val cloud = GogCloud("user", "client", "token", "saves", url) + val file = cloud.list().single() + cloud.details(file) + assertArrayEquals(raw, cloud.get(file).first) + cloud.put(mapOf("save.sav" to raw), mapOf("save.sav" to 1_793_490_825_000L)) + } + assertEquals(listOf("GET", "HEAD", "GET", "PUT", "HEAD"), requests.map { it.method }) + requests.forEach { assertEquals(it.method, GOG_CLOUD_UA, it.headers["user-agent"]) } + assertTrue(GOG_CLOUD_UA.startsWith("GOGGalaxyCommunicationService/2.")) + assertEquals(GOG_CLOUD_UA, requests[3].headers["x-object-meta-user-agent"]) + requests.forEach { assertEquals("Bearer token", it.headers["authorization"]) } + } + + @Test fun rejectedListKeepsTheServerErrorInTheDetail() { + val body = "{\"error\":\"invalid_version\",\"error_description\":\"not supported with this version\"}" + val failure = runCatching { + serve(1, { "HTTP/1.1 400 Bad Request\r\nContent-Length: ${body.length}\r\nConnection: close\r\n\r\n$body" }) { url -> + GogCloud("user", "client", "token", "saves", url).list() + } + }.exceptionOrNull() + assertTrue(failure is java.io.IOException) + val detail = cloudFailureDetail(failure!!) + assertTrue(detail, detail.contains("GOG cloud list HTTP 400")) + assertTrue(detail, detail.contains("invalid_version")) + } + + @Test fun disabledListErrorsRemainRecognized() { + for (error in listOf("disabled", "not_enabled_for_client")) { + for (padding in listOf("", ",\"padding\":\"${"x".repeat(100_000)}\"")) { + val body = "{\"error\":\"$error\"$padding}" + val failure = runCatching { + serve(1, { "HTTP/1.1 403 Forbidden\r\nContent-Length: ${body.length}\r\nConnection: close\r\n\r\n$body" }, allowEarlyClose = padding.isNotEmpty()) { url -> + GogCloud("user", "client", "token", "saves", url).list() + } + }.exceptionOrNull() + assertTrue("$error: $failure", failure is NoCloudSaves) + } + } + } + + @Test fun largeListErrorIsBoundedAndSanitized() { + val body = "invalid_version " + "x".repeat(100_000) + val failure = runCatching { + serve(1, { "HTTP/1.1 400 Bad Request\r\nContent-Length: ${body.length}\r\nConnection: close\r\n\r\n$body" }, allowEarlyClose = true) { url -> + GogCloud("user", "client", "token", "saves", url).list() + } + }.exceptionOrNull() + assertTrue("$failure", failure is java.io.IOException) + assertTrue(failure!!.message!!.contains("invalid_version")) + assertTrue(failure.message!!.length < 200) + } + + @Test fun failedResultLineCarriesTheDetailAndOtherLinesAreUnchanged() { + assertEquals("result=failed files=0 bytes=0 reason=IOException detail=\"IOException: x\"", + CloudSaves.Result("failed", 0, 0, "IOException", detail = "IOException: x").line) + assertEquals("result=ok files=1 bytes=2 reason=uploaded conflicts=3", CloudSaves.Result("ok", 1, 2, "uploaded", 3).line) + } +} + +private fun okResponse(request: Request): String = + if (request.method == "PUT") "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nConnection: close\r\n\r\n" + else "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n" + + "Etag: \"${CloudSaves.md5(request.body)}\"\r\n" + + "Last-Modified: Tue, 20 Oct 2026 10:00:00 GMT\r\nConnection: close\r\n\r\n" + +private fun serve(count: Int, respond: (Request) -> String, allowEarlyClose: Boolean = false, block: (String) -> Unit): List { + val server = java.net.ServerSocket(0, 4, java.net.InetAddress.getByName("127.0.0.1")) + val requests = java.util.concurrent.CopyOnWriteArrayList() + val failure = java.util.concurrent.atomic.AtomicReference() + val worker = Thread { + try { + repeat(count) { server.accept().use { client -> client.soTimeout = 5_000 val input = client.getInputStream() - val line = readLine(input) - val parts = line.split(' ') + val parts = readLine(input).split(' ') val headers = LinkedHashMap() while (true) { val h = readLine(input) @@ -83,42 +261,36 @@ class GogCloudKeysTest { if (n < 0) break offset += n } - requests += Request(parts[0], parts[1], headers, body) - val response = if (parts[0] == "PUT") { - "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nConnection: close\r\n\r\n" - } else { - "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n" + - "Etag: \"${CloudSaves.md5(body)}\"\r\n" + - "Last-Modified: Tue, 20 Oct 2026 10:00:00 GMT\r\nConnection: close\r\n\r\n" + val request = Request(parts[0], parts[1], headers, body) + requests += request + val response = respond(request).toByteArray() + try { + client.getOutputStream().apply { write(response); flush() } + } catch (e: java.io.IOException) { + if (!allowEarlyClose) throw e } - client.getOutputStream().apply { write(response.toByteArray()); flush() } } } - }.apply { isDaemon = true; start() } - try { - val cloud = GogCloud("user", "client", "token", "saves", "http://127.0.0.1:${server.localPort}/v1/user/client") - val source = java.io.File.createTempFile("save", ".sav").apply { writeBytes(raw) } - val result = try { - cloud.putFiles(mapOf("save.sav" to source), mapOf("save.sav" to 1_793_490_825_000L)).getValue("save.sav") - } finally { - source.delete() - } - assertTrue(result.modifiedMs > 0) - assertEquals(CloudSaves.md5(raw), result.md5) - val put = requests[0] - assertEquals("PUT", put.method) - assertEquals("/v1/user/client/saves%2Fsave.sav", put.path) - assertEquals("gzip", put.headers["content-encoding"]) - assertEquals("2026-10-31T23:53:45+00:00", put.headers["x-object-meta-locallastmodified"]) - assertArrayEquals(gzipGogPut(raw), put.body) - assertEquals(CloudSaves.md5(put.body), put.headers["etag"]) - assertArrayEquals(raw, gogDecodeCloudBody(put.body, put.headers["content-encoding"])) - assertEquals("HEAD", requests[1].method) - } finally { - server.close() - worker.join(2_000) + } catch (t: Throwable) { + failure.set(t) } + }.apply { isDaemon = true; start() } + val result = runCatching { + block("http://127.0.0.1:${server.localPort}/v1/user/client") } + val cleanup = runCatching { + server.close() + worker.join(2_000) + check(!worker.isAlive) { "Server worker did not finish" } + failure.get()?.let { throw AssertionError("Server worker failed", it) } + check(requests.size == count) { "Expected $count requests, received ${requests.size}" } + } + result.exceptionOrNull()?.let { primary -> + cleanup.exceptionOrNull()?.let { primary.addSuppressed(it) } + throw primary + } + cleanup.getOrThrow() + return requests } private class Request(val method: String, val path: String, val headers: Map, val body: ByteArray) diff --git a/docs/development/stores.md b/docs/development/stores.md index 278c0cbd8d..e8ff8fcbd0 100644 --- a/docs/development/stores.md +++ b/docs/development/stores.md @@ -296,7 +296,10 @@ it, the cloud copies before an upload replaces them, under A game launched before Proton has made its prefix (a first launch) gets its download deferred: the request is answered at once (`result=deferred reason=no-prefix`) and the download runs as soon as the prefix's user folder appears, within a minute. Every path logs -`cloud down|up result=ok|skipped|deferred|failed files= bytes= reason=`. +`cloud down|up result=ok|skipped|deferred|failed files= bytes= reason=`. A failure adds +`detail="..."`: the exception chain with the step (`list`, `get`, `put`), HTTP status, file and the +start of the server's error body, with URLs cut to their host and tokens, secrets and codes redacted. +GOG uploads stage their gzip body in the app's cache folder, which is created if it is missing. - **The folder:** GOG's public remote-config gives a location template per game (by its Galaxy client id), e.g. `/Hyperstrange/ELDERBORN`; Epic's catalog gives @@ -328,7 +331,10 @@ the prefix's user folder appears, within a minute. Every path logs migration runs once per game (`cloud_layout_`), so a game that legitimately keeps a folder named like the location is not relocated again; a non-prefixed listing is left unchanged. - **The services:** GOG `cloudstorage.gog.com/v1//` with a token issued to the game's - own client (the client secret is kept at install; the Galaxy token is the fallback); Epic's + own client (the client secret is kept at install; the Galaxy token is the fallback). Every + cloudstorage request sends Galaxy's communication-service `User-Agent` (`GOG_CLOUD_UA`, the + same string Heroic's gogdl and Lutris send), and PUT repeats it as `X-Object-Meta-User-Agent`; + the bare `GOG Galaxy` value is now refused with HTTP 400 `invalid_version`. Epic's savesync data storage with signed read and write links (`EpicCloud` → `EpicSaveSync` → the Rust `epic/savesync.rs`; the template's root token and `{EpicId}` / `{AppName}` are read by `EpicSaveTemplate`).