Skip to content

Commit 04fa423

Browse files
committed
Directly trust the LE R3 pin too, to fix manual case
Seems that badssl.com has had some changes and no longer includes ISRG. The OkHTTP case seems to check the full chain (presumably from local stores) but that's complicated to do ourselves. This seems like a reasonable short-term fix, and it's easy to patch up later on now that we know what's going on.
1 parent 8168356 commit 04fa423

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/src/main/java/tech/httptoolkit/pinning_demo/MainActivity.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ import java.security.cert.CertificateFactory
4040
import java.security.cert.X509Certificate
4141
import javax.net.ssl.*
4242

43-
const val LETS_ENCRYPT_ROOT_SHA256 = "C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M="
43+
// We check for both the long-term root & intermediate, because some servers don't seem to
44+
// include the ISRG in the chain (assuming it's in our trust store). Unfortunately the R3
45+
// intermediate cert will expire in September 2025, but we may have our own testserver by then.
46+
const val LETS_ENCRYPT_ISRG_X1_ROOT_PK_SHA256 = "C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M="
47+
const val LETS_ENCRYPT_R3_INTERM_PK_SHA256 = "jQJTbIh0grw0/1TkHSumWb+Fs0Ggogr621gT3PvPKG0="
4448

4549
@Suppress("UNUSED_PARAMETER")
4650
@DelicateCoroutinesApi
@@ -213,7 +217,8 @@ class MainActivity : AppCompatActivity() {
213217
try {
214218
val hostname = "ecc384.badssl.com"
215219
val certificatePinner = CertificatePinner.Builder()
216-
.add(hostname, "sha256/${LETS_ENCRYPT_ROOT_SHA256}")
220+
.add(hostname, "sha256/${LETS_ENCRYPT_ISRG_X1_ROOT_PK_SHA256}")
221+
.add(hostname, "sha256/${LETS_ENCRYPT_R3_INTERM_PK_SHA256}")
217222
.build()
218223

219224
val client = OkHttpClient.Builder()
@@ -456,7 +461,10 @@ class MainActivity : AppCompatActivity() {
456461

457462
val certs = socket.session.peerCertificates
458463

459-
if (!certs.any { cert -> doesCertMatchPin(LETS_ENCRYPT_ROOT_SHA256, cert) }) {
464+
if (!certs.any { cert ->
465+
doesCertMatchPin(LETS_ENCRYPT_ISRG_X1_ROOT_PK_SHA256, cert) ||
466+
doesCertMatchPin(LETS_ENCRYPT_R3_INTERM_PK_SHA256, cert)
467+
}) {
460468
socket.close() // Close the socket immediately without sending a request
461469
throw Error("Unrecognized cert hash.")
462470
}

0 commit comments

Comments
 (0)