Skip to content

Commit 073542f

Browse files
authored
Merge pull request #7 from CDuPlooy/main
Cleartext + Cleartext & Ignore proxy request
2 parents f50abea + 552740e commit 073542f

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import java.io.BufferedInputStream
3636
import java.io.BufferedReader
3737
import java.io.InputStreamReader
3838
import java.io.PrintWriter
39+
import java.net.HttpURLConnection
40+
import java.net.Proxy
3941
import java.net.URL
4042
import java.security.KeyStore
4143
import java.security.cert.Certificate
@@ -128,6 +130,42 @@ class MainActivity : AppCompatActivity() {
128130
}
129131
}
130132

133+
fun sendHttpRequest(view: View) {
134+
GlobalScope.launch(Dispatchers.IO) {
135+
onStart(R.id.http_request)
136+
try {
137+
val mURL = URL("http://amiusing.httptoolkit.tech")
138+
with(mURL.openConnection() as HttpURLConnection) {
139+
println("URL: ${this.url}")
140+
println("Response Code: ${this.responseCode}")
141+
}
142+
143+
onSuccess(R.id.http_request)
144+
} catch (e: Throwable) {
145+
println(e)
146+
onError(R.id.http_request, e.toString())
147+
}
148+
}
149+
}
150+
151+
fun sendIgnoreProxyHttpRequest(view: View) {
152+
GlobalScope.launch(Dispatchers.IO) {
153+
onStart(R.id.ignore_proxy_http_request)
154+
try {
155+
val mURL = URL("http://amiusing.httptoolkit.tech")
156+
with(mURL.openConnection(Proxy.NO_PROXY) as HttpURLConnection) {
157+
println("URL: ${this.url}")
158+
println("Response Code: ${this.responseCode}")
159+
}
160+
161+
onSuccess(R.id.ignore_proxy_http_request)
162+
} catch (e: Throwable) {
163+
println(e)
164+
onError(R.id.ignore_proxy_http_request, e.toString())
165+
}
166+
}
167+
}
168+
131169
fun sendUnpinned(view: View) {
132170
GlobalScope.launch(Dispatchers.IO) {
133171
onStart(R.id.unpinned)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@
2323
app:layout_constraintStart_toStartOf="parent"
2424
app:layout_constraintTop_toTopOf="parent">
2525

26+
<Button
27+
android:id="@+id/http_request"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:onClick="sendHttpRequest"
31+
android:text="Plain HTTP request" />
32+
33+
<Button
34+
android:id="@+id/ignore_proxy_http_request"
35+
android:layout_width="match_parent"
36+
android:layout_height="wrap_content"
37+
android:onClick="sendIgnoreProxyHttpRequest"
38+
android:text="Plain ignore-proxy HTTP request" />
39+
40+
<View
41+
android:layout_width="match_parent"
42+
android:layout_height="1dp"
43+
android:layout_marginTop="10dp"
44+
android:layout_marginBottom="10dp"
45+
android:background="@android:color/darker_gray"/>
46+
2647
<Button
2748
android:id="@+id/unpinned"
2849
android:layout_width="match_parent"

app/src/main/res/xml/network_security_config.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<network-security-config>
33

44
<!-- We use amiusing.httptoolkit.tech for unpinned requests -->
5-
5+
<domain-config cleartextTrafficPermitted="true">
6+
<domain includeSubdomains="false">amiusing.httptoolkit.tech</domain>
7+
</domain-config>
68
<!-- We use ecc384.badssl.com for manual pinning, defined in code -->
79

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

0 commit comments

Comments
 (0)