From 79ee50f46bfedd217bc224cdb4f93b677dffffdf Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 11:05:35 +0000 Subject: [PATCH 1/2] test(transport): Accept the JDK's own rejection of distrusted eMudhra CAs Runner image ubuntu26/20261122.9 ships Temurin 21.0.13+2, which rejects the eMudhra intermediate during the handshake with SSLHandshakeException before DistrustedCertificates runs. Expect SSLException, which covers both, and keep asserting that no request reaches the server. Co-Authored-By: Roman Zavarnitsyn --- .../io/sentry/transport/DistrustedCertificatesTest.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt b/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt index b50cd113c38..5a6063c18d9 100644 --- a/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt +++ b/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt @@ -19,6 +19,7 @@ import java.security.cert.X509Certificate import java.security.spec.ECGenParameterSpec import java.security.spec.ECParameterSpec import java.security.spec.ECPrivateKeySpec +import javax.net.ssl.SSLException import javax.net.ssl.SSLPeerUnverifiedException import javax.net.ssl.SSLSocketFactory import kotlin.test.Test @@ -97,7 +98,9 @@ class DistrustedCertificatesTest { false, ) - assertFailsWith { send(trusting(emSignRoot)) } + // JDKs whose blocked.certs lists this CA reject the handshake before DistrustedCertificates + // runs. + assertFailsWith { send(trusting(emSignRoot)) } assertThat(server.requestCount).isEqualTo(0) } @@ -107,7 +110,9 @@ class DistrustedCertificatesTest { // Like Android, which completes the chain from intermediates it cached on earlier connections. server.useHttps(serverCertificates(leafIssuedBy(distrustedCa)), false) - assertFailsWith { send(trusting(distrustedCa.certificate)) } + // JDKs whose blocked.certs lists this CA reject the handshake before DistrustedCertificates + // runs. + assertFailsWith { send(trusting(distrustedCa.certificate)) } assertThat(server.requestCount).isEqualTo(0) } From 2ed683429d733580387709444e2009c103ce890b Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 11:41:09 +0000 Subject: [PATCH 2/2] test(transport): Trust any chain so only DistrustedCertificates can reject it With the JDK's own chain validation in the way, the transport tests also passed without our check on JDKs that block the eMudhra CAs themselves. --- .../transport/DistrustedCertificatesTest.kt | 57 +++++++++++++++---- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt b/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt index 5a6063c18d9..9a227d2d848 100644 --- a/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt +++ b/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt @@ -19,9 +19,11 @@ import java.security.cert.X509Certificate import java.security.spec.ECGenParameterSpec import java.security.spec.ECParameterSpec import java.security.spec.ECPrivateKeySpec -import javax.net.ssl.SSLException +import javax.net.ssl.SSLContext +import javax.net.ssl.SSLEngine import javax.net.ssl.SSLPeerUnverifiedException import javax.net.ssl.SSLSocketFactory +import javax.net.ssl.X509ExtendedTrustManager import kotlin.test.Test import kotlin.test.assertFailsWith import okhttp3.mockwebserver.MockResponse @@ -98,21 +100,17 @@ class DistrustedCertificatesTest { false, ) - // JDKs whose blocked.certs lists this CA reject the handshake before DistrustedCertificates - // runs. - assertFailsWith { send(trusting(emSignRoot)) } + assertFailsWith { send(trustingAnyChain()) } assertThat(server.requestCount).isEqualTo(0) } @Test - fun `does not send the envelope when the client completes the chain with a distrusted CA the server left out`() { - // Like Android, which completes the chain from intermediates it cached on earlier connections. + fun `does not send the envelope when the server leaves out the distrusted CA`() { + // Android completes such a chain from intermediates it cached on earlier connections. server.useHttps(serverCertificates(leafIssuedBy(distrustedCa)), false) - // JDKs whose blocked.certs lists this CA reject the handshake before DistrustedCertificates - // runs. - assertFailsWith { send(trusting(distrustedCa.certificate)) } + assertFailsWith { send(trustingAnyChain()) } assertThat(server.requestCount).isEqualTo(0) } @@ -130,7 +128,7 @@ class DistrustedCertificatesTest { server.enqueue(MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AFTER_REQUEST)) server.enqueue(MockResponse()) - val result = send(trusting(emSignRoot, trustedCa.certificate)) + val result = send(trustingAnyChain()) assertThat(result.isSuccess).isFalse() assertThat(server.requestCount).isEqualTo(1) @@ -161,6 +159,13 @@ class DistrustedCertificatesTest { .build() .sslSocketFactory() + /** + * Skips the JDK's own chain validation, which on some JDKs rejects the eMudhra CAs too, so that + * only [DistrustedCertificates] can reject the handshake. + */ + private fun trustingAnyChain(): SSLSocketFactory = + SSLContext.getInstance("TLS").apply { init(null, arrayOf(TrustAnyChain), null) }.socketFactory + private fun certificate(resource: String): X509Certificate = javaClass.classLoader!!.getResourceAsStream(resource)!!.use { CertificateFactory.getInstance("X.509").generateCertificate(it) as X509Certificate @@ -176,6 +181,38 @@ class DistrustedCertificatesTest { .generatePrivate(ECPrivateKeySpec(BigInteger.valueOf(value), secp384r1)) } + private object TrustAnyChain : X509ExtendedTrustManager() { + override fun checkClientTrusted(chain: Array, authType: String) = Unit + + override fun checkClientTrusted( + chain: Array, + authType: String, + socket: Socket, + ) = Unit + + override fun checkClientTrusted( + chain: Array, + authType: String, + engine: SSLEngine, + ) = Unit + + override fun checkServerTrusted(chain: Array, authType: String) = Unit + + override fun checkServerTrusted( + chain: Array, + authType: String, + socket: Socket, + ) = Unit + + override fun checkServerTrusted( + chain: Array, + authType: String, + engine: SSLEngine, + ) = Unit + + override fun getAcceptedIssuers(): Array = emptyArray() + } + /** Presents the certificates of [first] on the first connection and of [then] on later ones. */ private class PerConnectionSocketFactory( private val first: SSLSocketFactory,