diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index fe489d49b1..4712f65e42 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -19,7 +19,9 @@ package com.droiddeck.launcher.core * The device's OWN addresses are not kept: the client's IPv6 check logs "external address " * about twenty times a session, and a public IPv6 address is the user's. [learnOwnAddresses] reads * the link the session was given (etc/bannerlator-net) and every address on the same /64 - privacy - * addresses rotate inside it - or an own public IPv4 is replaced wherever it appears. + * addresses rotate inside it - or an own public IPv4 is replaced wherever it appears. Likewise every + * Steam account and persona name on the device ([learnAccounts]), for users who sign in with an + * account name rather than an email. */ object LogRedactor { private val EMAIL = Regex("[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}") @@ -59,6 +61,44 @@ object LogRedactor { /** An IPv6 literal: "::" somewhere, or all eight groups (a clock's 10:03:05 is neither). */ private val IPV6 = Regex("(? 2 1 0 0"): a + * user who signs in with a plain account name, not an email, had it in every log. The single + * space then a non-space keeps "OnLoginStateChange 0 1 0 0" (no account yet) as it is. + */ + private val LOGIN_STATE = Regex("(OnLoginStateChange )(\\S+)") + private val LOGIN_USERS = Regex("(OnLoginUsersChanged )(\\S.*)$") + + /** The device's Steam accounts and persona names as patterns (see [learnAccounts]). */ + @Volatile + private var accounts: List = emptyList() + + /** + * Learns every Steam account on the device from the client's loginusers.vdf - its AccountName + * and PersonaName - so they are replaced wherever a log mentions them, whoever the user is. + * Names under three characters are skipped: blanking every "a" would ruin a log. + */ + fun learnAccounts(loginUsers: java.io.File) { + val found = ArrayList() + try { + if (loginUsers.isFile) { + val kv = Regex("\"(AccountName|PersonaName)\"\\s+\"([^\"]*)\"") + kv.findAll(loginUsers.readText()).map { it.groupValues[2].trim() }.filter { it.length >= 3 }.distinct().forEach { name -> + found += Regex("(?i)(? = emptyList() @@ -174,6 +214,9 @@ object LogRedactor { } out = EXTERNAL_ADDR.replace(out) { "${it.groupValues[1]}" } for (r in own) out = r.replace(out, "") + out = LOGIN_STATE.replace(out) { "${it.groupValues[1]}" } + out = LOGIN_USERS.replace(out) { "${it.groupValues[1]}" } + for (r in accounts) out = r.replace(out, "") out = EMAIL.replace(out, "") out = RESIDUAL.replace(out) { "${it.groupValues[1]}=" } out = LONG_TOKEN.replace(out, "") diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 7c8116eda8..5f8726e41d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -31,8 +31,8 @@ object SessionArtifacts { /** Written last; a folder without it did not get its ending. */ const val COMPLETE_MARKER = ".complete" - /** Every file in the folder has been through the redactor, own addresses included. */ - private const val SCRUBBED_MARKER = ".scrubbed" + /** Every file in the folder has been through the redactor, own addresses and accounts included (-2: accounts added). */ + private const val SCRUBBED_MARKER = ".scrubbed-2" /** Everything the end of a session gathers, into [dir]. Safe to call for a dead session. */ fun collect(context: Context, dir: File, reason: String) { @@ -43,7 +43,7 @@ object SessionArtifacts { src.copyTo(wayland, overwrite = true) } } - LogRedactor.learnOwnAddresses(File(LinuxRuntime.rootDir(context), "etc/bannerlator-net")) + LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) copySteamLogs(context, dir) // A session the system killed leaves its trace here and nowhere else. SessionLogCapture.dumpCrashBuffer(File(dir, "crash.log")) @@ -69,7 +69,7 @@ object SessionArtifacts { f.isDirectory && f.name.startsWith("session-") && f != current && !File(f, SCRUBBED_MARKER).exists() } ?: return if (dirs.isEmpty()) return - LogRedactor.learnOwnAddresses(File(LinuxRuntime.rootDir(context), "etc/bannerlator-net")) + LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) dirs.forEach { dir -> scrubFolder(dir) File(dir, "steam").takeIf { it.isDirectory }?.let { scrubFolder(it) } @@ -128,7 +128,7 @@ object SessionArtifacts { }?.sortedBy { it.name } ?: return if (abandoned.isEmpty()) return val current = SessionPaths.current() - LogRedactor.learnOwnAddresses(File(LinuxRuntime.rootDir(context), "etc/bannerlator-net")) + LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) abandoned.forEachIndexed { i, dir -> if (dir == current) return@forEachIndexed val newest = i == abandoned.lastIndex diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt index 843c1c1904..37b766df12 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt @@ -34,7 +34,7 @@ object SessionLogShare { val zip = File(out, "DroidDeck-${folder.name}.zip") // Scrubbed on the way into the zip: a session shared while it runs has not had its end-of- // session pass yet, and the redactor changes nothing in a line that is already clean. - LogRedactor.learnOwnAddresses(File(LinuxRuntime.rootDir(context), "etc/bannerlator-net")) + LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) ZipOutputStream(zip.outputStream().buffered()).use { z -> files.forEach { f -> z.putNextEntry(ZipEntry(folder.name + "/" + f.relativeTo(folder).path))