android: certificate failures found behind OkHttp 5's fast fallback; release-key check reads apksigner 37 (#8533)
release / go (push) Successful in 1m46s
release / web (push) Successful in 1m11s
release / integration (push) Successful in 2m33s
release / govulncheck (push) Successful in 18s
release / android (push) Successful in 4m52s
release / Build signed APK (push) Successful in 5m4s
release / Build + push container image (push) Successful in 17s

Run 11511 failed in two places.

ServerProbe: OkHttp 5 tries a host's addresses in parallel. When all of
them fail it throws one failure and attaches the others as suppressed
exceptions. For localhost, the refused ::1 connection was thrown, and the
certificate error from 127.0.0.1 was only attached, so the probe said
"Couldn't reach" instead of naming the certificate. A real server with
both IPv4 and IPv6 addresses would hit the same. isCertificateFailure now
searches suppressed exceptions as well as causes, up to 16 in all.

Release-key check: apksigner from build-tools 37 labels signers by
signature scheme ("V3.0 Signer: certificate SHA-256 digest: ...") instead
of "Signer #1 certificate ...". The step's grep matched nothing, and
pipefail ended it with no message. The step now collects every
certificate SHA-256 digest whatever the label, and still requires exactly
one distinct digest, equal to the release key's. I checked the parsing on
both label formats, on two keys and on no output: it passes our key in
either format and fails the other two cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 15:28:20 -05:00
co-authored by Claude Opus 5.5
parent 3a7bd2b04d
commit f32fe95179
2 changed files with 28 additions and 8 deletions
+7 -3
View File
@@ -560,10 +560,14 @@ jobs:
signer="$(ls "$sdk"/build-tools/*/apksigner 2>/dev/null | sort -V | tail -1 || true)" signer="$(ls "$sdk"/build-tools/*/apksigner 2>/dev/null | sort -V | tail -1 || true)"
test -n "$signer" || { echo "::error::no apksigner under '$sdk/build-tools'"; exit 1; } test -n "$signer" || { echo "::error::no apksigner under '$sdk/build-tools'"; exit 1; }
certs="$("$signer" verify --print-certs app/build/outputs/apk/release/app-release.apk)" certs="$("$signer" verify --print-certs app/build/outputs/apk/release/app-release.apk)"
printf '%s\n' "$certs" | grep -E '^Signer #[0-9]+ certificate (DN|SHA-256 digest)' # apksigner's signer label varies between versions: "Signer #1
# One signer, and it is ours. A second signer would be a lineage or # certificate ..." before build-tools 37, "V3.0 Signer: certificate
# ..." from 37 on. So the digests are read without relying on it.
printf '%s\n' "$certs" | grep -E 'certificate (DN|SHA-256 digest):' || true
# One signer, and it is ours: exactly one distinct SHA-256 across
# every scheme apksigner reports. A second key would be a lineage or
# a mistake; either way not something to ship unexamined. # a mistake; either way not something to ship unexamined.
digests="$(printf '%s\n' "$certs" | sed -n 's/^Signer #[0-9]* certificate SHA-256 digest: //p')" digests="$(printf '%s\n' "$certs" | sed -n 's/^.*certificate SHA-256 digest: //p' | sort -u)"
if [ "$digests" != "$RELEASE_CERT_SHA256" ]; then if [ "$digests" != "$RELEASE_CERT_SHA256" ]; then
if printf '%s' "$certs" | grep -q 'CN=Android Debug'; then if printf '%s' "$certs" | grep -q 'CN=Android Debug'; then
echo "::error::the release APK is signed with a debug key" echo "::error::the release APK is signed with a debug key"
@@ -171,10 +171,26 @@ class ServerProbe internal constructor(
// (hostname) or as an SSLHandshakeException caused by a // (hostname) or as an SSLHandshakeException caused by a
// CertificateException or CertPathValidatorException (trust). A port // CertificateException or CertPathValidatorException (trust). A port
// with no TLS fails the handshake too, but with no such cause. // with no TLS fails the handshake too, but with no such cause.
private fun isCertificateFailure(e: IOException): Boolean = //
generateSequence<Throwable>(e) { it.cause } // OkHttp tries a host's addresses in parallel (fast fallback). When
.take(MAX_CAUSE_DEPTH) // all of them fail it throws one failure and attaches the rest as
.any { it is SSLPeerUnverifiedException || it is GeneralSecurityException } // suppressed, so the certificate error can sit behind a refused
// connection to the host's other address. Both causes and suppressed
// exceptions are searched.
private fun isCertificateFailure(e: IOException): Boolean {
val seen = mutableSetOf<Throwable>()
val pending = ArrayDeque<Throwable>().apply { add(e) }
var found = false
while (!found && pending.isNotEmpty() && seen.size < MAX_EXCEPTIONS_SEARCHED) {
val t = pending.removeFirst()
if (seen.add(t)) {
found = t is SSLPeerUnverifiedException || t is GeneralSecurityException
t.cause?.let { pending.addLast(it) }
pending.addAll(t.suppressed)
}
}
return found
}
private suspend fun Call.await(): Response = private suspend fun Call.await(): Response =
suspendCancellableCoroutine { continuation -> suspendCancellableCoroutine { continuation ->
@@ -201,6 +217,6 @@ class ServerProbe internal constructor(
private companion object { private companion object {
const val SETUP_STATUS_PATH = "/api/auth/setup-status" const val SETUP_STATUS_PATH = "/api/auth/setup-status"
const val CALL_TIMEOUT_MILLIS = 8_000L const val CALL_TIMEOUT_MILLIS = 8_000L
const val MAX_CAUSE_DEPTH = 8 const val MAX_EXCEPTIONS_SEARCHED = 16
} }
} }