Skip to content

Commit 1faec0f

Browse files
committed
Add an Appmattus (with OkHttp) CT-checked request
This seems to be the most common case of Appmattus, which is actually quite widely used. It's not really certificate pinning, but certificate transparency has better real world use cases, and causes equal problems for MitM interception, so it's well worth including here as a test case. Appmattus can be used in multiple scenarios, but OkHttp seems most recommended and popular, and should be representative of most cases anyway.
1 parent 9164428 commit 1faec0f

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ dependencies {
6262
implementation 'com.android.volley:volley:1.2.0'
6363
implementation 'com.datatheorem.android.trustkit:trustkit:1.1.3'
6464
implementation 'androidx.preference:preference-ktx:1.1.1'
65-
}
65+
implementation 'com.appmattus.certificatetransparency:certificatetransparency-android:2.5.18'
66+
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.android.volley.toolbox.BasicNetwork
1717
import com.android.volley.toolbox.HurlStack
1818
import com.android.volley.toolbox.NoCache
1919
import com.android.volley.toolbox.StringRequest
20+
import com.appmattus.certificatetransparency.certificateTransparencyInterceptor
2021
import com.datatheorem.android.trustkit.TrustKit
2122
import kotlinx.coroutines.Dispatchers
2223
import kotlinx.coroutines.GlobalScope
@@ -254,6 +255,31 @@ class MainActivity : AppCompatActivity() {
254255
}
255256
}
256257

258+
fun sendAppmattusCTChecked(view: View) {
259+
GlobalScope.launch(Dispatchers.IO) {
260+
onStart(R.id.appmattus_ct_checked)
261+
try {
262+
val appmattusInterceptor = certificateTransparencyInterceptor()
263+
val client = OkHttpClient.Builder().apply {
264+
addNetworkInterceptor(appmattusInterceptor)
265+
}.build()
266+
val request = Request.Builder()
267+
.url("https://sha256.badssl.com")
268+
.build()
269+
270+
client.newCall(request).execute().use { response ->
271+
println("URL: ${request.url}")
272+
println("Response Code: ${response.code}")
273+
}
274+
275+
onSuccess(R.id.appmattus_ct_checked)
276+
} catch (e: Throwable) {
277+
println(e)
278+
onError(R.id.appmattus_ct_checked, e.toString())
279+
}
280+
}
281+
}
282+
257283
// Manually pinned by building an SSLContext that trusts only the correct certificate, and then
258284
// connecting with the native HttpsUrlConnection API:
259285
fun sendCustomContextPinned(view: View) {

app/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
android:onClick="sendTrustKitPinned"
5959
android:text="TrustKit pinned request" />
6060

61+
<Button
62+
android:id="@+id/appmattus_ct_checked"
63+
android:layout_width="match_parent"
64+
android:layout_height="wrap_content"
65+
android:onClick="sendAppmattusCTChecked"
66+
android:text="Appmattus CT-checked request" />
67+
6168
<Button
6269
android:id="@+id/custom_context_pinned"
6370
android:layout_width="match_parent"

0 commit comments

Comments
 (0)