maauto: GAL cert expiry warnings + rotation runbook, fixtures
- Commit
6e26dd9c6a72776d85e06a1b33e388549b2604fd- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-12 18:56 UTC (2 months ago)
- Parents
6d1689e
Diff
auto/docs/HANDOFF.md
diff --git a/auto/docs/HANDOFF.md b/auto/docs/HANDOFF.mdindex 8b7251ba33..f514579152 100644--- a/auto/docs/HANDOFF.md+++ b/auto/docs/HANDOFF.md@@ -274,6 +274,53 @@ also has a remote-provisioning path (`rvf`, fed by six phenotype flags), so the could stop being accepted before that date. Keep `extract_key.py` working so it can be re-extracted from a newer gearhead. +### Expiry surfacing (Phase 8, landed)++The phone status screen shows the leaf's remaining validity, parsed at runtime so it+stays correct across a rotation with no code change: `GalCredential.daysRemaining()`+(`CertificateFactory`, pure JVM — `auto/protocol` stays Android-free) →+`ProjectionService.publishCredentialExpiry()` seeds `AutoSessionState.credentialDaysLeft`+once per service start (never reset per session; the credential outlives connections) →+`AutoViewModel` → `SessionSnapshot.credentialDaysLeft` → `SessionCard.CredentialRow`.+Quiet day-count while far out, escalating warnings at 90 / 30 / 7 days, expired notice+at zero; all text in `strings.xml` (`session_credential_*`, plurals per CONTRIBUTING.md).++### Renewal decision: re-extract, not rvf (Phase 8)++`rvg(Context)` reads six phenotype flags (`adbo.gu()` `a`–`f`): a cert PEM, an encrypted+key blob and a salt, each paired with a SHA-1 checksum, and builds `rvf` from them instead+of the hardcoded `rvd` when all three validate (`rvg.java:38-54`). `rvf` itself is a trivial+`rvh` holder — cert string, key blob, salt — decrypted by the same `rth`/`jca` path.++That path is Google's own rotation channel **into the genuine gearhead app**, not something+a third-party sender can tap: the phenotype values are delivered server-side to Google's+package, and we have no way to fetch or inject them. So `rvf` is unusable to us by+construction, regardless of what cert it would carry. **Recommendation: re-extract from+each new gearhead release.** `extract_key.py` is pinned to the 17.5.663214 decompile+(`rvg`/`rvd`/`rth` class names and array shapes); if a newer gearhead renames those+families the script needs re-pinning to the new names, then `verify_tls.sh` re-proves the+triple before it ships. Not yet re-run against a newer APK here — that needs a current+gearhead pull plus `jadx` and the `openssl` CLI, none of which this environment had.++### Rotation runbook++1. Pull the current gearhead APK and re-run `analysis/maauto/extract_key.py`. On+ `MATCH`, it writes `analysis/maauto/certs/` (`gal-client-cert.pem`,+ `gal-client-key.pem`, `gal-root.pem`).+2. Run `analysis/maauto/verify_tls.sh`: chain verifies against the GAL root, key+ modulus equals cert modulus, TLS 1.2 mutual-auth handshake returns 0 (ok).+3. Swap the three files under `auto/protocol/src/main/assets/gal/` — same names, same+ PEM formats (`BEGIN CERTIFICATE` leaf + root, PKCS#8 `BEGIN PRIVATE KEY`). No code+ change: `GalCredential.create()` parses whatever ships, and the session card reads+ the new expiry at the next service start.+4. Run `:auto:protocol:testDebugUnitTest` — `GalCredentialRotationTest` proves the+ fixture-swap shape (fresh CA + leaf + key through `create()` into a mutual-auth+ handshake), and `GalCredentialTest` re-proves the shipped triple.+5. Live leg: full DHU handshake per §6 with the rotated PEMs in place. Needs DHU ++ Pixel access — coordinate with the task 4 (DHU live-verification) owner via the+ `ma-auto-parity` team channel; the JVM leg above is the most that can be shown+ without it.+ --- ## 8. Suggested order from here
auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalCredential.kt
diff --git a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalCredential.kt b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalCredential.ktindex 9595a39d16..10b575827d 100644--- a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalCredential.kt+++ b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalCredential.kt@@ -41,6 +41,9 @@ object GalCredential { /** Keystore alias for the GAL root, matching gearhead's. */ private const val ROOT_ALIAS = "GAL" + /** Millis in a day; expiry is day-granular, so truncation, not rounding, is correct. */+ private const val DAY_MS = 86_400_000L+ /** * Builds the TLS context from PEM text. *@@ -99,6 +102,26 @@ object GalCredential { needClientAuth = true } + /**+ * Millis since the epoch at which the leaf in [certPem] stops being valid.+ *+ * Pure JVM (`CertificateFactory`, no Android), so expiry surfacing stays correct+ * after a rotation without any code change — the UI reads whatever leaf ships.+ */+ fun notAfterMillis(certPem: String): Long {+ val leaf = CertificateFactory.getInstance("X.509").generateCertificate(+ ByteArrayInputStream(certPem.toByteArray()),+ ) as X509Certificate+ return leaf.notAfter.time+ }++ /**+ * Whole days from [nowMillis] until the leaf in [certPem] expires, truncated+ * (a cert expiring in 30 days 23 hours reports 30). Negative once expired.+ */+ fun daysRemaining(certPem: String, nowMillis: Long = System.currentTimeMillis()): Long =+ (notAfterMillis(certPem) - nowMillis) / DAY_MS+ private fun parsePrivateKey(pem: String): PrivateKey { val body = pem .substringAfter("-----BEGIN PRIVATE KEY-----")
auto/protocol/src/test/assets/gal-rotated/client-cert.pem
diff --git a/auto/protocol/src/test/assets/gal-rotated/client-cert.pem b/auto/protocol/src/test/assets/gal-rotated/client-cert.pemnew file mode 100644index 0000000000..f608e944ac--- /dev/null+++ b/auto/protocol/src/test/assets/gal-rotated/client-cert.pem@@ -0,0 +1,19 @@+-----BEGIN CERTIFICATE-----+MIIDCzCCAfOgAwIBAgIUENiQwiTWG7ARijLuzQ3t7wW4W0cwDQYJKoZIhvcNAQEL+BQAwPDEfMB0GA1UECgwWVGVzdCBHQUwgUm90YXRpb24gUm9vdDEZMBcGA1UEAwwQ+VGVzdCBHQUwgUm9vdCBDQTAeFw0yNjA5MTExODUxMzhaFw0yNzA5MTIxODUxMzha+MDExEzARBgNVBAoMCkNhclNlcnZpY2UxGjAYBgNVBAMMEXJvdGF0ZWQtbGVhZi50+ZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9/ZBzMfXJn3HK7D/+PwpOyeqmbdemgMMPnmdirwL4pSFuoiFAHDitJxHlDcaAupOxnbDW9kN/ZCss7DUT+ja7ceADLzZImKwaFw7cMLwujVsc6HKQCBsKaO9GCrw3ig9gUMwS5K/FmHrOjKgoU+r1RTi/LxTb06ydxkDSVKF80+FppusJkxeSi7L5NRb9NDWh7VnBZ730Sce3TV6ndU+DwtJjgIb1ZKdLMJgGJi7QsE+CNvHYEhBqe7m5mWtGGN6VOJFGktjZ/Bb5NbcOeJA+jwtRbS1dD/Sl1TZjoHOmIHr4boWgKeSmKtYQLREViQ8teV0z9v2kDBQm/4SK/vz0+R4POGwIDAQABoxAwDjAMBgNVHRMBAf8EAjAAMA0GCSqGSIb3DQEBCwUAA4IBAQCx+4DliOtN5zEIi+U9JoAAYIFmqhBdHFj09jtxmAki4Jg2TiQ9GkroZwPEU0l+NzFN/+rkUtMTAP4ySOeNiD/X3QsssHAs1d94U9oBvUh9MyAiYDjOPis4xelGEwrriG+0UD+fcLprzRGOPSunuKUc/FTQdnQN5+PEjl/7QGisUf6DWnawS7rUA7j7RodkXYRAH4k+DYrqR1c1Q/vJ17cm6mVn9Yzj8w4lKYLclRElGk0IU93cPafMGGgWVujhLzqCnApZ+HzxVqI/pZDBZQb2W5aNFOpEmj6HNKLDhY27PRRAemElVh7frAUigP08gr5Wn7god+plCsJyU3RoBp7u9JWknK+-----END CERTIFICATE-----
auto/protocol/src/test/assets/gal-rotated/client-key.pem
diff --git a/auto/protocol/src/test/assets/gal-rotated/client-key.pem b/auto/protocol/src/test/assets/gal-rotated/client-key.pemnew file mode 100644index 0000000000..72a5f9aa67--- /dev/null+++ b/auto/protocol/src/test/assets/gal-rotated/client-key.pem@@ -0,0 +1,28 @@+-----BEGIN PRIVATE KEY-----+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD39kHMx9cmfccr+sP8/Ck7J6qZt16aAww+eZ2KvAvilIW6iIUAcOK0nEeUNxoC6k7GdsNb2Q39kKyzs+NRONrtx4AMvNkiYrBoXDtwwvC6NWxzocpAIGwpo70YKvDeKD2BQzBLkr8WYes6Mq+ChSvVFOL8vFNvTrJ3GQNJUoXzT4Wmm6wmTF5KLsvk1Fv00NaHtWcFnvfRJx7dNXq+d1QPC0mOAhvVkp0swmAYmLtCwT4I28dgSEGp7ubmZa0YY3pU4kUaS2Nn8Fvk1tw5+4kCPC1FtLV0P9KXVNmOgc6YgevhuhaAp5KYq1hAtERWJDy15XTP2/aQMFCb/hIr++/PRHg84bAgMBAAECggEAXnLTf3ADWKsCKXdC0j1X43tYp3BEALnMAjc5FJaaJTQF+0wW9SMKh2cbsK4IX2HmXZwxL5QOyy3HSq6pP52Dao28SMhxgI3VZkEHyBx10uwIp+9WzXRMHtQ6m7EHjGdhfhIcnDyqQplLoyBTpPxLTnGeCQ316bvPYQuh0hCs3nv22V+l2NT7FSFGs/3kGFFK2CIQMoLSGwfrwXMnzQwy5fH0ppVxqaaC77KYYpDM4s6Um6d+3vugnjJkpOOID0d9WOx1PX6v+50u54fzipDMSuJAXq8QNVmPQwfVQsx+ijPtTNNc+XsXOm3KwybKHiMyTNhcKhZQM44IKNRhDaYjGo8O5qQKBgQD+kwCqoVRmY3B8HhcO+pN20D2J8s6SU28W7aZ08rL4rTEmkYhUVpoO9ufOdiRArEAzBgdW+2QLBJnU8uFoM+m2aE2Kuw+MB85Umt+ABO8QjyC9KKIBbnKak9/1E7NKrTGiQVFUiD+Yi01kdk6qXX+rebmOrBSIwqzc7HYO8v5UJSzZQKBgQD5WcYmGWgf2LVLOtEJ7VKRkuop80IsXdc++9eAsNEfFXwSbf4vrpwL6hRMlhXKKFttjNzYFEaSMJRLwGvZrWfK62jN6vuDW4Qs3+UVAq/OpU85GT1Sdhhsu7OblHMfllsZLEIPHvSyRlK3TbUWd6lWJMvqUEd70K/ka4+XSZ/bNgjfwKBgQCRwXMJPvOG5/pYZhYHgWeal5BpG6XowOg2hKLNQY5kVfp4DtxJ+mBwnvdb45KgIL9lN1dueuLt2AWHwkRCl1TfeafvriJEVMWZ9H9h1WlYn15MFGJhk+ZBsNbyiAQIhp87ajB5uMTIv0FhesdRjdIylnukSH0p5m3p/90UbZCUUKbQKBgQDf+Q/P5PzyNb2P9RV/RDK+m6y5Ce67fvPKzTEL6MaGl50tf1Fe7nCI9oJQhP5jsbkTo+VJJI/aAhYDzRwsKsIrEFf8UiffEiVgTN9j/bDfTgNes+vFfzqleXf7sXNXcDCHnK+pVkbk2O2Nq/+hKgsCcAnyXhGRNR/GGjIQZfr9tCdDwKBgFxkM/sa0LaL6iXHQ3dq+WA5Y1ZvMAm2TCXpgUY2Mn9Q0XPByS1bHr8g+Qml8WKJDCvoIq1N8DAx+LksEuk+o+XQ37FHcS0af6hJKPbU1+7L/kisZ9A7KjAINWuSG141pcZKxdNUZHuPkntMAeYU92+EpbhVe8W4qQ8Wpn3Yxdt3ut9+-----END PRIVATE KEY-----
auto/protocol/src/test/assets/gal-rotated/root.pem
diff --git a/auto/protocol/src/test/assets/gal-rotated/root.pem b/auto/protocol/src/test/assets/gal-rotated/root.pemnew file mode 100644index 0000000000..235c3bb698--- /dev/null+++ b/auto/protocol/src/test/assets/gal-rotated/root.pem@@ -0,0 +1,20 @@+-----BEGIN CERTIFICATE-----+MIIDOzCCAiOgAwIBAgIUJNwGDN8Y71RInKoG9Ua+4wVJsEcwDQYJKoZIhvcNAQEL+BQAwPDEfMB0GA1UECgwWVGVzdCBHQUwgUm90YXRpb24gUm9vdDEZMBcGA1UEAwwQ+VGVzdCBHQUwgUm9vdCBDQTAeFw0yNjA5MTExODUxMzhaFw0zNjA5MDkxODUxMzha+MDwxHzAdBgNVBAoMFlRlc3QgR0FMIFJvdGF0aW9uIFJvb3QxGTAXBgNVBAMMEFRl+c3QgR0FMIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA+EmUIrlj5IUvAOBwNejJxHhj+T5os63Hkb6jnSgRLJdgl41yNAEoL39MYCqBw5LTC+PWoHez88IxCjlijyuYt+dtmjFQMcwBngJVAWGQVDPNx/qncqfYnuKnkqYvxz19+H+ZRH3ffB/5Ovf5ai2T1MVgRu+0zv22G9RffUoutmCnrMVXLcWN2tLXN0cbpY7RQtb+Eh7flLWddmtBGOBPOxkf1zi6/cAzo9nYmdkemovc+ZrAgkPAb2tq7AWYEVnYMd5D+cswefNqCMxeBch8PB/Qn4ScqA5nongBBvL235T7d0B7lBo2th79Qir2vkI8y0lL2+u3mZrOEBn7vQABfZqB8JAgMBAAGjNTAzMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYD+VR0OBBYEFG+FRkIrMnGAQTGKI95uioeizMtgMA0GCSqGSIb3DQEBCwUAA4IBAQB1+0Mj/F5jxFj9hwEkyYcNPSSTDP44pFGjQDR95MJkGkPkwV0kH0sfJPiTFM0B2dfc6+6FJZ3Ti/61AqGYQZHyvULG18KaRQTQLTxJcShI6+5d6k9IifzaM44Hh/2i9Iuf5d++ztXXrw2jDpjoLBFzqwopo/juEzqVjNxfSRVcJUql3wHrfmtsc/W2muNrYj7qYGu+OMRe757g8wnj4fpT/YqCTkXRbRl0W51GpX72VfXpO5XovqerBA9xf60NUQj7ls7d+uqsNH6g3/GXy4PlNjZSntYR8oK0yhrmWaphw58c3r1HylUsDbBpC2uabSDpfvrAR+jgcV4EhjLn/09jFqAd7a+-----END CERTIFICATE-----
auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalCredentialRotationTest.kt
diff --git a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalCredentialRotationTest.kt b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalCredentialRotationTest.ktnew file mode 100644index 0000000000..ccda2b44a1--- /dev/null+++ b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalCredentialRotationTest.kt@@ -0,0 +1,91 @@+package com.vayunmathur.auto.protocol++import java.io.File+import java.security.cert.CertificateFactory+import java.security.cert.X509Certificate+import java.util.concurrent.TimeUnit+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Proves a credential rotation is a PEM swap with zero code change.+ *+ * The `gal-rotated/` fixtures stand in for the next gearhead leaf: a fresh CA,+ * leaf and PKCS#8 key minted the same way (see `auto/docs/HANDOFF.md` §7).+ * Everything runs through [GalCredential.create] with fixture PEM strings —+ * exactly what a real rotation feeds it — and completes the same mutual-auth+ * handshake [GalCredentialTest] proves for the shipped credential.+ */+class GalCredentialRotationTest {++ private fun fixture(name: String): String {+ val file = File("src/test/assets/gal-rotated", name)+ assertTrue(file.exists(), "missing rotation fixture ${file.absolutePath}")+ return file.readText()+ }++ @Test+ fun `rotated fixtures chain to their own root, not the shipped GAL root`() {+ val shippedRoot = CertificateFactory.getInstance("X.509").generateCertificate(+ File("src/main/assets/gal", "root.pem").readBytes().inputStream(),+ ) as X509Certificate+ val rotatedLeaf = CertificateFactory.getInstance("X.509").generateCertificate(+ fixture("client-cert.pem").byteInputStream(),+ ) as X509Certificate+ assertTrue(+ rotatedLeaf.issuerX500Principal != shippedRoot.subjectX500Principal,+ "rotated leaf must chain to its own CA, saw ${rotatedLeaf.issuerX500Principal}",+ )+ }++ @Test+ fun `rotated leaf expires roughly a year out, far past the 2026-12-09 shipped expiry`() {+ val now = System.currentTimeMillis()+ val days = GalCredential.daysRemaining(fixture("client-cert.pem"), now)+ assertTrue(+ days in 300L..400L,+ "rotated leaf should be good for ~1 year, saw $days days",+ )+ val shippedDays = GalCredential.daysRemaining(+ File("src/main/assets/gal", "client-cert.pem").readText(),+ now,+ )+ assertTrue(+ shippedDays < days,+ "shipped leaf ($shippedDays days) must be nearer expiry than the rotation",+ )+ }++ @Test+ fun `rotated creds complete the mutual-auth handshake with zero code change`() {+ val context = GalCredential.create(+ certPem = fixture("client-cert.pem"),+ keyPem = fixture("client-key.pem"),+ rootPem = fixture("root.pem"),+ )+ val server = GalCredential.serverEngine(context)+ val car = TestTls.carEngine(context)++ TestTls.handshake(server, car)++ assertEquals("TLSv1.2", server.session.protocol)+ val peer = server.session.peerCertificates.first() as X509Certificate+ assertTrue(+ peer.subjectX500Principal.name.contains("rotated-leaf"),+ "server should have authenticated the rotated client, saw ${peer.subjectX500Principal}",+ )+ }++ @Test+ fun `expiry math truncates to whole days and goes negative past expiry`() {+ val notAfter = GalCredential.notAfterMillis(fixture("client-cert.pem"))+ val dayMs = TimeUnit.DAYS.toMillis(1)+ // 23 hours before expiry reads 0, not 1.+ assertEquals(0L, GalCredential.daysRemaining(fixture("client-cert.pem"), notAfter - 23 * 3_600_000))+ // One day plus a minute before expiry reads 1.+ assertEquals(1L, GalCredential.daysRemaining(fixture("client-cert.pem"), notAfter - dayMs - 60_000))+ // A day after expiry reads negative.+ assertTrue(GalCredential.daysRemaining(fixture("client-cert.pem"), notAfter + dayMs) < 0)+ }+}
auto/src/main/java/com/vayunmathur/auto/platform/AutoSessionState.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/AutoSessionState.kt b/auto/src/main/java/com/vayunmathur/auto/platform/AutoSessionState.ktindex 889482a568..5e91b019a8 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/AutoSessionState.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/AutoSessionState.kt@@ -149,6 +149,20 @@ object AutoSessionState { private val _sessionStartedAt = MutableStateFlow<Long?>(null) val sessionStartedAt: StateFlow<Long?> = _sessionStartedAt.asStateFlow() + /**+ * Whole days until the shipped GAL leaf expires, parsed at runtime from the+ * PEM so it stays correct across a rotation. Null until the service seeds it+ * (or when the leaf cannot be parsed). Deliberately outside [resetTelemetry]:+ * the credential outlives any one session.+ */+ private val _credentialDaysLeft = MutableStateFlow<Long?>(null)+ val credentialDaysLeft: StateFlow<Long?> = _credentialDaysLeft.asStateFlow()++ /** Records the days remaining on the shipped GAL leaf; see [credentialDaysLeft]. */+ fun onCredentialExpiry(daysLeft: Long) {+ _credentialDaysLeft.value = daysLeft+ }+ /** A socket was accepted; version negotiation and the TLS handshake are next. */ fun onSocketAccepted() { _video.value = null
auto/src/main/java/com/vayunmathur/auto/platform/AutoViewModel.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/AutoViewModel.kt b/auto/src/main/java/com/vayunmathur/auto/platform/AutoViewModel.ktindex 4929384f18..704c28e3e8 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/AutoViewModel.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/AutoViewModel.kt@@ -59,10 +59,14 @@ class AutoViewModel : ViewModel() { val encoderDrains: StateFlow<Long> = AutoSessionState.encoderDrains .stateIn(viewModelScope, SharingStarted.WhileSubscribed(STOP_TIMEOUT_MS), 0L) - /** Whether the virtual display + encoder input surface pair is currently up. */+ /** Whether the virtual display + encoder input surface pair is up. */ val surfaceValid: StateFlow<Boolean> = AutoSessionState.surfaceValid .stateIn(viewModelScope, SharingStarted.WhileSubscribed(STOP_TIMEOUT_MS), false) + /** Whole days until the shipped GAL leaf expires; null until the service seeds it. */+ val credentialDaysLeft: StateFlow<Long?> = AutoSessionState.credentialDaysLeft+ .stateIn(viewModelScope, SharingStarted.WhileSubscribed(STOP_TIMEOUT_MS), null)+ val sessionStartedAt: StateFlow<Long?> = AutoSessionState.sessionStartedAt .stateIn(viewModelScope, SharingStarted.WhileSubscribed(STOP_TIMEOUT_MS), null)
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 4e8ac39118..3f1058b186 100644--- a/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt+++ b/auto/src/main/java/com/vayunmathur/auto/service/ProjectionService.kt@@ -38,6 +38,7 @@ class ProjectionService : Service() { if (running) return START_STICKY running = true startForeground(NOTIFICATION_ID, notification())+ publishCredentialExpiry() worker = thread(name = "ma-auto-projection") { serve() } return START_STICKY }@@ -103,6 +104,23 @@ class ProjectionService : Service() { private var video: VideoSinkChannel? = null + /**+ * Seeds the credential-expiry flow once per service start, off the pump thread.+ *+ * Reads the shipped leaf through the public asset constant, so a rotation that+ * swaps the PEMs updates the session card with no code change. On parse+ * failure the flow stays null (unknown) instead of failing the service.+ */+ private fun publishCredentialExpiry() {+ runCatching {+ assets.open(GalCredential.CERT_ASSET).use { it.readBytes().decodeToString() }+ }.onSuccess { certPem ->+ AutoSessionState.onCredentialExpiry(GalCredential.daysRemaining(certPem))+ }.onFailure {+ Log.w(TAG, "could not read GAL leaf expiry", it)+ }+ }+ /** * Opens the next not-yet-attempted advertised service, in the HU's wire order. *
auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt b/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.ktindex 1b2b269a5d..609fb7e3b3 100644--- a/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt+++ b/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt@@ -39,6 +39,7 @@ fun AutoScreen(viewModel: AutoViewModel) { avgEncodeLatencyUs = viewModel.avgEncodeLatencyUs.collectAsStateWithLifecycle().value, encoderDrains = viewModel.encoderDrains.collectAsStateWithLifecycle().value, surfaceValid = viewModel.surfaceValid.collectAsStateWithLifecycle().value,+ credentialDaysLeft = viewModel.credentialDaysLeft.collectAsStateWithLifecycle().value, sessionStartedAt = viewModel.sessionStartedAt.collectAsStateWithLifecycle().value, ) val scrollBehavior = appBarScrollBehavior()@@ -89,6 +90,8 @@ data class SessionSnapshot( val encoderDrains: Long, /** Whether the virtual display + encoder input surface pair is up. */ val surfaceValid: Boolean,+ /** Whole days until the shipped GAL leaf expires; null until the service seeds it. */+ val credentialDaysLeft: Long?, val sessionStartedAt: Long?, )
auto/src/main/java/com/vayunmathur/auto/ui/SessionCard.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/ui/SessionCard.kt b/auto/src/main/java/com/vayunmathur/auto/ui/SessionCard.ktindex 61d986e523..66e0a943dc 100644--- a/auto/src/main/java/com/vayunmathur/auto/ui/SessionCard.kt+++ b/auto/src/main/java/com/vayunmathur/auto/ui/SessionCard.kt@@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableLongStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier+import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import com.vayunmathur.auto.R import com.vayunmathur.library.ui.Card@@ -106,10 +107,54 @@ fun SessionCard(session: SessionSnapshot, modifier: Modifier = Modifier) { }, ) SessionElapsedRow(sessionStartedAt = session.sessionStartedAt)+ CredentialRow(daysLeft = session.credentialDaysLeft) } } } +/**+ * GAL leaf expiry: quiet count while far out, escalating warnings at 90/30/7 days,+ * expired notice at zero. Thresholds live here next to the rows they drive so a+ * rotation of the warning policy is one edit.+ */+@Composable+private fun CredentialRow(daysLeft: Long?) {+ if (daysLeft == null) {+ ListItem(+ headlineContent = { Text(stringResource(R.string.session_credential)) },+ supportingContent = { Text(stringResource(R.string.session_credential_unknown)) },+ )+ return+ }+ val text = when {+ daysLeft < 0 -> stringResource(R.string.session_credential_expired)+ daysLeft <= CRITICAL_DAYS -> pluralStringResource(+ R.plurals.session_credential_critical,+ daysLeft.coerceToQuantity(),+ daysLeft,+ )+ daysLeft <= URGENT_DAYS -> pluralStringResource(+ R.plurals.session_credential_urgent,+ daysLeft.coerceToQuantity(),+ daysLeft,+ )+ daysLeft <= WARNING_DAYS -> pluralStringResource(+ R.plurals.session_credential_warning,+ daysLeft.coerceToQuantity(),+ daysLeft,+ )+ else -> pluralStringResource(+ R.plurals.session_credential_days,+ daysLeft.coerceToQuantity(),+ daysLeft,+ )+ }+ ListItem(+ headlineContent = { Text(stringResource(R.string.session_credential)) },+ supportingContent = { Text(text) },+ )+}+ /** * Live age of the last head-unit ack, recomposing each second from the wall-clock * timestamp; a dash while no ack has arrived. Reuses the session clock pattern so@@ -161,3 +206,19 @@ private fun formatElapsed(millis: Long): String { val totalSeconds = (millis.coerceAtLeast(0) / 1000).toInt() return "%d:%02d".format(totalSeconds / 60, totalSeconds % 60) }++/** Days of GAL leaf validity left at which the session card starts warning. */+private const val WARNING_DAYS = 90L++/** Days left at which the warning turns urgent. */+private const val URGENT_DAYS = 30L++/** Days left at which the warning names re-extraction explicitly. */+private const val CRITICAL_DAYS = 7L++/**+ * Quantity for the day-count plurals. Count is always non-negative here (expiry+ * is handled above) and far below [Int.MAX_VALUE]; the clamp is belt-and-braces+ * against a raw `toInt` silently wrapping on absurd input.+ */+private fun Long.coerceToQuantity(): Int = coerceIn(0, Int.MAX_VALUE.toLong()).toInt()
auto/src/main/res/values/strings.xml
diff --git a/auto/src/main/res/values/strings.xml b/auto/src/main/res/values/strings.xmlindex 2e7eeca1c2..a25bab70fd 100644--- a/auto/src/main/res/values/strings.xml+++ b/auto/src/main/res/values/strings.xml@@ -79,6 +79,38 @@ <string name="session_surface_valid">Valid</string> <!-- Shown on the session card when the render pair is down or not yet up. --> <string name="session_surface_invalid">Down</string>+ <!-- Heading of the row showing how long the GAL client certificate is still valid. -->+ <string name="session_credential">Certificate</string>+ <!-- Shown on the session card while the GAL leaf expiry has not been read yet,+ for example before the projection service starts. -->+ <string name="session_credential_unknown">Expiry unknown</string>+ <!-- Days of GAL leaf validity left, shown while comfortably far from expiry.+ %1$d is whole days remaining. -->+ <plurals name="session_credential_days">+ <item quantity="one"><xliff:g example="120" id="days">%1$d</xliff:g> day left</item>+ <item quantity="other"><xliff:g example="120" id="days">%1$d</xliff:g> days left</item>+ </plurals>+ <!-- Warning shown on the session card once the GAL leaf has 90 or fewer days left.+ %1$d is whole days remaining. -->+ <plurals name="session_credential_warning">+ <item quantity="one">Renew soon — <xliff:g example="45" id="days">%1$d</xliff:g> day left</item>+ <item quantity="other">Renew soon — <xliff:g example="45" id="days">%1$d</xliff:g> days left</item>+ </plurals>+ <!-- Urgent warning shown on the session card once the GAL leaf has 30 or fewer+ days left. %1$d is whole days remaining. -->+ <plurals name="session_credential_urgent">+ <item quantity="one">Expiring — <xliff:g example="12" id="days">%1$d</xliff:g> day left</item>+ <item quantity="other">Expiring — <xliff:g example="12" id="days">%1$d</xliff:g> days left</item>+ </plurals>+ <!-- Final warning shown on the session card in the last 7 days of GAL leaf+ validity. %1$d is whole days remaining. -->+ <plurals name="session_credential_critical">+ <item quantity="one">Expires in <xliff:g example="3" id="days">%1$d</xliff:g> day — re-extract the credential</item>+ <item quantity="other">Expires in <xliff:g example="3" id="days">%1$d</xliff:g> days — re-extract the credential</item>+ </plurals>+ <!-- Shown on the session card once the GAL leaf has expired. Projection stops+ working until the credential is rotated; see the handoff rotation runbook. -->+ <string name="session_credential_expired">Expired — projection needs a new credential</string> <!-- Heading of the row showing how long the session has been active. --> <string name="session_elapsed">Session time</string> <!-- Shown when there is no active session to time. -->