Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/src/main/java/tech/httptoolkit/pinning_demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import java.io.BufferedInputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.net.HttpURLConnection
import java.net.Proxy
import java.net.URL
import java.security.KeyStore
import java.security.cert.Certificate
Expand Down Expand Up @@ -128,6 +130,42 @@ class MainActivity : AppCompatActivity() {
}
}

fun sendHttpRequest(view: View) {
GlobalScope.launch(Dispatchers.IO) {
onStart(R.id.http_request)
try {
val mURL = URL("http://amiusing.httptoolkit.tech")
with(mURL.openConnection() as HttpURLConnection) {
println("URL: ${this.url}")
println("Response Code: ${this.responseCode}")
}

onSuccess(R.id.http_request)
} catch (e: Throwable) {
println(e)
onError(R.id.http_request, e.toString())
}
}
}

fun sendIgnoreProxyHttpRequest(view: View) {
GlobalScope.launch(Dispatchers.IO) {
onStart(R.id.ignore_proxy_http_request)
try {
val mURL = URL("http://amiusing.httptoolkit.tech")
with(mURL.openConnection(Proxy.NO_PROXY) as HttpURLConnection) {
println("URL: ${this.url}")
println("Response Code: ${this.responseCode}")
}

onSuccess(R.id.ignore_proxy_http_request)
} catch (e: Throwable) {
println(e)
onError(R.id.ignore_proxy_http_request, e.toString())
}
}
}

fun sendUnpinned(view: View) {
GlobalScope.launch(Dispatchers.IO) {
onStart(R.id.unpinned)
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<Button
android:id="@+id/http_request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendHttpRequest"
android:text="Plain HTTP request" />

<Button
android:id="@+id/ignore_proxy_http_request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendIgnoreProxyHttpRequest"
android:text="Plain ignore-proxy HTTP request" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@android:color/darker_gray"/>

<Button
android:id="@+id/unpinned"
android:layout_width="match_parent"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<network-security-config>

<!-- We use amiusing.httptoolkit.tech for unpinned requests -->

<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="false">amiusing.httptoolkit.tech</domain>
</domain-config>
<!-- We use ecc384.badssl.com for manual pinning, defined in code -->

<!-- We use sha256.badssl.com for normal config-defined pinning: -->
Expand Down
Loading