@@ -294,15 +294,19 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
294294 app.trackEvent(" Button" , " start-vpn" )
295295 val vpnIntent = VpnService .prepare(this )
296296 Log .i(TAG , if (vpnIntent != null ) " got intent" else " no intent" )
297+ val vpnNotConfigured = vpnIntent != null
297298
298- if (vpnIntent != null ) {
299+ if (! isCertTrusted(config)) {
300+ // The cert isn't trusted, and the VPN may need setup, so there'll be a series of prompts
301+ // here. Explain them beforehand, so users understand what's going on.
299302 withContext(Dispatchers .Main ) {
300303 MaterialAlertDialogBuilder (this @MainActivity)
301304 .setTitle(" Enable interception" )
302305 .setIcon(R .drawable.ic_info_circle)
303306 .setMessage(
304- " To intercept traffic from this device, you need to activate HTTP Toolkit's " +
305- " VPN and trust its HTTPS certificate. " +
307+ " To intercept traffic from this device, you need to " +
308+ (if (vpnNotConfigured) " activate HTTP Toolkit's VPN and " else " " ) +
309+ " trust your HTTP Toolkit's certificate authority. " +
306310 " \n\n " +
307311 " Please accept the following prompts to allow this." +
308312 if (! isDeviceSecured())
@@ -312,11 +316,21 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
312316 else " To trust the certificate, your device PIN will be required."
313317 )
314318 .setPositiveButton(" Ok" ) { _, _ ->
315- startActivityForResult(vpnIntent, START_VPN_REQUEST )
319+ if (vpnNotConfigured) {
320+ startActivityForResult(vpnIntent, START_VPN_REQUEST )
321+ } else {
322+ onActivityResult(START_VPN_REQUEST , RESULT_OK , null )
323+ }
316324 }
317325 .show()
318326 }
327+ } else if (vpnNotConfigured) {
328+ // In this case the VPN needs setup, but the cert is trusted already, so it's
329+ // a single confirmation. Pretty clear, no need to explain. This happens if the
330+ // VPN/app was removed from the device in the past, or when using injected system certs.
331+ startActivityForResult(vpnIntent, START_VPN_REQUEST )
319332 } else {
333+ // VPN is trusted & cert setup already, lets get to it.
320334 onActivityResult(START_VPN_REQUEST , RESULT_OK , null )
321335 }
322336
0 commit comments