appstore: hash-check split APKs for every URL source
- Commit
737f50710de87ef67c13629d54e3f2a953c4c371- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 19:38 UTC (28 days ago)
- Parents
5ed27fa
Symptom: for F-Droid, IzzyOnDroid and Modern Apps installs, split sibling APKs were installed with no SHA-256 check at all, even though the signed index publishes a hash for every split file. Only the proprietary mirror's requirement branch keyed the split hashes in. The signer check still ran, so this was a missing defence layer rather than a bypass, but a split whose bytes were swapped in transit (same signer is not required to produce the hash the index published) would pass verification. Root cause: InstallCoordinator built expectedSha256 per source; the PROPRIETARY branch included splitFiles, the MODERN_APPS and else (F-Droid/Izzy) branches only mapped the base APK. Fix: one shared expectedSha256ByFile() builder, keyed by the staged file names DownloadCache assigns (base + splitN), used by all three URL-source branches. Verification: new ExpectedSha256ByFileTest pins base+split keying for all four URL sources and the empty case; existing :appstore:testDevUnitTest and :appstore:compileDevKotlin pass.
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.ktindex 2f08cb67f5..ea2a28ba3a 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt@@ -212,8 +212,7 @@ class InstallCoordinator( AppSource.MODERN_APPS -> InstallRequirement( expectedPackage = app.packageName, requiredSigners = ownSigningCertificates(),- expectedSha256 = app.apkSha256- ?.let { mapOf("${app.packageName}.apk" to it) } ?: emptyMap(),+ expectedSha256 = expectedSha256ByFile(app), signerOrigin = "this store", requireTvCompatible = isTv, )@@ -226,20 +225,14 @@ class InstallCoordinator( AppSource.PROPRIETARY -> InstallRequirement( expectedPackage = app.packageName, requiredSigners = app.expectedSigners.toSet(),- expectedSha256 = buildMap {- app.apkSha256?.let { put("${app.packageName}.apk", it) }- app.splitFiles.forEachIndexed { index, split ->- split.sha256?.let { put("${app.packageName}.split$index.apk", it) }- }- },+ expectedSha256 = expectedSha256ByFile(app), signerOrigin = "this store's Play mirror", requireTvCompatible = isTv, ) else -> InstallRequirement( expectedPackage = app.packageName, requiredSigners = app.expectedSigners.toSet(),- expectedSha256 = app.apkSha256- ?.let { mapOf("${app.packageName}.apk" to it) } ?: emptyMap(),+ expectedSha256 = expectedSha256ByFile(app), signerOrigin = when (app.source) { AppSource.IZZY -> "IzzyOnDroid's signed app list" else -> "F-Droid's signed app list"@@ -602,3 +595,17 @@ class InstallCoordinator( private const val COPY_BUFFER_SIZE = 64 * 1024 } }++/**+ * Published SHA-256 per staged file, keyed by the local file name the verifier+ * matches on ([DownloadCache.apkName] for the base, [DownloadCache.splitApkName]+ * for siblings). Every URL source publishes a hash per split in its signed+ * index, so every source gets the same coverage: a split absent here would be+ * installed with no hash check at all.+ */+internal fun expectedSha256ByFile(app: UnifiedApp): Map<String, String> = buildMap {+ app.apkSha256?.let { put(DownloadCache.apkName(app.packageName), it) }+ app.splitFiles.forEachIndexed { index, split ->+ split.sha256?.let { put(DownloadCache.splitApkName(app.packageName, index), it) }+ }+}
appstore/src/test/java/com/vayunmathur/appstore/data/ExpectedSha256ByFileTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/data/ExpectedSha256ByFileTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/data/ExpectedSha256ByFileTest.ktnew file mode 100644index 0000000000..3bb7394dee--- /dev/null+++ b/appstore/src/test/java/com/vayunmathur/appstore/data/ExpectedSha256ByFileTest.kt@@ -0,0 +1,41 @@+package com.vayunmathur.appstore.data++import com.vayunmathur.appstore.data.installer.expectedSha256ByFile+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Regression: only the proprietary mirror's branch keyed split hashes into+ * the install requirement, so F-Droid/Izzy/Modern split siblings installed+ * with no hash check even though the signed index published one per file.+ */+class ExpectedSha256ByFileTest {++ private fun app(source: AppSource) = UnifiedApp(+ packageName = "com.example.app",+ source = source,+ name = "Example",+ apkSha256 = "basehash",+ splitFiles = listOf(+ SplitFile(fileName = "config.arm64.apk", url = "https://x/a", sha256 = "splithash0", size = 1),+ SplitFile(fileName = "config.en.apk", url = "https://x/b", sha256 = null, size = 1),+ ),+ )++ @Test+ fun `every url source hashes base and splits by staged name`() {+ val expected = mapOf(+ "com.example.app.apk" to "basehash",+ "com.example.app.split0.apk" to "splithash0",+ )+ for (source in listOf(AppSource.FDROID, AppSource.IZZY, AppSource.MODERN_APPS, AppSource.PROPRIETARY)) {+ assertEquals(expected, expectedSha256ByFile(app(source)), "source $source")+ }+ }++ @Test+ fun `no published hashes means no hash check`() {+ val bare = UnifiedApp(packageName = "com.example.app", source = AppSource.FDROID, name = "E")+ assertEquals(emptyMap(), expectedSha256ByFile(bare))+ }+}