Modern Apps git

← Modern-Apps.git

auto: do not crash service on an unparsable GAL certificate

Commit
d5066c8e32b2a788b9562eecd8e13d8bb7f963d3
Author
Vayun Mathur <[email protected]>
When
2026-11-19 02:07 UTC (17 days ago)
Parents
a8e8049
publishCredentialExpiry documented that a parse failure leaves the credential-expiry flow unknown instead of failing the service, but only the asset read was inside runCatching. GalCredential.daysRemaining, called from the onSuccess lambda, parses the PEM with CertificateFactory and casts to X509Certificate, so a malformed or badly rotated asset threw CertificateException or ClassCastException out of onStartCommand and crashed ProjectionService at start. Move the parse inside runCatching and pass the computed days to onSuccess.

Verified: ./gradlew :auto:testDevUnitTest, ./gradlew :auto:protocol:testDebugUnitTest and ./check auto all pass.

Diff

auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt b/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.ktindex 91b0b87eef..91271ca1b3 100644--- a/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt+++ b/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt@@ -683,10 +683,14 @@ class ProjectionService : Service() {      * failure the flow stays null (unknown) instead of failing the service.      */     private fun publishCredentialExpiry() {+        // daysRemaining parses the PEM (CertificateFactory + an X509 cast),+        // so it belongs inside runCatching too: a malformed or rotated+        // asset must leave the expiry unknown, not crash onStartCommand.         runCatching {-            assets.open(GalCredential.CERT_ASSET).use { it.readBytes().decodeToString() }-        }.onSuccess { certPem ->-            AutoSessionState.onCredentialExpiry(GalCredential.daysRemaining(certPem))+            val certPem = assets.open(GalCredential.CERT_ASSET).use { it.readBytes().decodeToString() }+            GalCredential.daysRemaining(certPem)+        }.onSuccess { days ->+            AutoSessionState.onCredentialExpiry(days)         }.onFailure {             Log.status(TAG, "could not read GAL leaf expiry", it)         }