appstore: fail closed instead of crashing on bad Accrescent data
- Commit
420b8bbda7581928418c8ea47229ab414a7c88ef- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 02:07 UTC (17 days ago)
- Parents
88fc046
AccrescentRepoDataFetcher.fetch documented that every failure returns Result.failure, but a signed yet malformed repodata document threw SerializationException (an IllegalArgumentException) from decodeFromString, which none of its catches handled. It escaped through AccrescentRepository.refreshRepoData into viewModelScope update checks, the update worker and InstallCoordinator, crashing the caller instead of leaving the cached allowlist untouched. Catch IllegalArgumentException there and return Result.failure like the other paths. SignifyNative loaded its library in an init block, so on an ABI without the shipped .so, touching the object threw ExceptionInInitializerError / UnsatisfiedLinkError. Those are Errors, so Signify.verify's catch (Exception) fail-closed path never ran. Load with runCatching into an available flag (the pattern astronomy already uses), return false from verify when unavailable, and catch Throwable in verify so any linkage error also fails closed. Verified: ./gradlew :appstore:testDevUnitTest and ./check appstore both pass.
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.ktindex ea783a873b..df07eaaa38 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt@@ -86,6 +86,13 @@ open class AccrescentRepoDataFetcher(private val context: Context) { } catch (expected: IllegalStateException) { Log.status(TAG, "repodata fetch/verify failed", expected) Result.failure(expected)+ } catch (expected: IllegalArgumentException) {+ // Malformed (but signed) repodata: decodeFromString throws+ // SerializationException, an IllegalArgumentException. It must+ // fail closed like every other failure here, not escape and+ // crash the update-check / install caller.+ Log.status(TAG, "repodata fetch/verify failed", expected)+ Result.failure(expected) } catch (expected: java.io.IOException) { Log.status(TAG, "repodata fetch/verify failed", expected) Result.failure(expected)
appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/SignifyNative.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/SignifyNative.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/SignifyNative.ktindex 5a066f21b9..ab32ba54f8 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/SignifyNative.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/SignifyNative.kt@@ -14,7 +14,11 @@ package com.vayunmathur.appstore.data.accrescent internal object SignifyNative { external fun nativeVerify(pubkey: ByteArray, message: ByteArray, signature: ByteArray): Boolean - init {- System.loadLibrary("appstore_signify")- }+ /**+ * Whether the native library loaded. A missing `.so` (an ABI the APK+ * does not ship) must fail closed as "signature does not verify", not+ * crash class initialisation with an [UnsatisfiedLinkError], which is+ * an [Error] and escapes every `catch (Exception)` fail-closed path.+ */+ val available: Boolean = runCatching { System.loadLibrary("appstore_signify") }.isSuccess }
appstore/src/main/java/com/vayunmathur/appstore/data/security/Signify.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/security/Signify.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/security/Signify.ktindex fcca8d5820..5e68213ef1 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/security/Signify.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/security/Signify.kt@@ -41,6 +41,7 @@ object Signify { signature: String, base64PublicKey: String, ): Boolean {+ if (!SignifyNative.available) return false return try { val pubKeyBytes = decodeRange(base64PublicKey, PUBKEY_HEADER, PUBKEY_END) ?: return false @@ -54,7 +55,9 @@ object Signify { val sigBytes = decodeRange(sigBase64, SIG_HEADER, SIG_END) ?: return false SignifyNative.nativeVerify(pubKeyBytes, message, sigBytes)- } catch (_: Exception) {+ } catch (_: Throwable) {+ // Fail closed on linkage errors as well as parsing failures:+ // a verifier that cannot run must never crash its caller. false } }