@@ -20,6 +20,9 @@ import com.appmattus.certificatetransparency.certificateTransparencyInterceptor
20
20
import com.appmattus.certificatetransparency.certificateTransparencyTrustManager
21
21
import com.appmattus.certificatetransparency.installCertificateTransparencyProvider
22
22
import com.datatheorem.android.trustkit.TrustKit
23
+ import io.flutter.embedding.engine.FlutterEngine
24
+ import io.flutter.embedding.engine.dart.DartExecutor
25
+ import io.flutter.plugin.common.MethodChannel
23
26
import kotlinx.coroutines.DelicateCoroutinesApi
24
27
import kotlinx.coroutines.Dispatchers
25
28
import kotlinx.coroutines.GlobalScope
@@ -49,6 +52,9 @@ const val LETS_ENCRYPT_R3_INTERM_PK_SHA256 = "jQJTbIh0grw0/1TkHSumWb+Fs0Ggogr621
49
52
@Suppress(" UNUSED_PARAMETER" )
50
53
@DelicateCoroutinesApi
51
54
class MainActivity : AppCompatActivity () {
55
+
56
+ private var flutterEngine: FlutterEngine ? = null
57
+
52
58
override fun onCreate (savedInstanceState : Bundle ? ) {
53
59
super .onCreate(savedInstanceState)
54
60
setContentView(R .layout.activity_main)
@@ -62,6 +68,17 @@ class MainActivity : AppCompatActivity() {
62
68
- " *.badssl.com"
63
69
+ " rsa4096.badssl.com"
64
70
}
71
+
72
+ // Prepare the flutter engine:
73
+ flutterEngine = FlutterEngine (this )
74
+ flutterEngine!! .dartExecutor.executeDartEntrypoint(
75
+ DartExecutor .DartEntrypoint .createDefault()
76
+ )
77
+ }
78
+
79
+ override fun onDestroy () {
80
+ super .onDestroy()
81
+ flutterEngine?.destroy()
65
82
}
66
83
67
84
private fun onStart (@IdRes id : Int ) {
@@ -478,6 +495,29 @@ class MainActivity : AppCompatActivity() {
478
495
}
479
496
}
480
497
498
+ fun sendFlutterRequest (view : View ) {
499
+ onStart(R .id.flutter_request)
500
+
501
+ val channel = MethodChannel (flutterEngine!! .dartExecutor.binaryMessenger, " tech.httptoolkit.pinning_demo.flutter_channel" )
502
+
503
+ println (" Calling Dart method from Kotlin..." )
504
+ channel.invokeMethod(" sendRequest" , " https://ecc384.badssl.com/" , object : MethodChannel .Result {
505
+ override fun success (result : Any? ) {
506
+ println (" Success from Dart: $result " )
507
+ onSuccess(R .id.flutter_request)
508
+ }
509
+
510
+ override fun error (errorCode : String , errorMessage : String? , errorDetails : Any? ) {
511
+ println (" Error: $errorCode - $errorMessage " )
512
+ onError(R .id.flutter_request, errorMessage ? : " Unknown error" )
513
+ }
514
+
515
+ override fun notImplemented () {
516
+ println (" Method not implemented on Dart side." )
517
+ }
518
+ })
519
+ }
520
+
481
521
// Manually pinned at the lowest level: creating a raw TLS connection, disabling all checks,
482
522
// and then directly analysing the certificate that's received after connection, before doing
483
523
// HTTP by just writing & reading raw strings. Not a good idea, but the hardest to unpin!
0 commit comments