Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Charles with Android: SSL handshake with client failed: An unknown issue occurred processing the certificate (certificate_unknown)

My Environment

  • Android 12 LG Velvet

  • Charles 4.6.5

  • MacOS Ventura 13.6.3

  • My App (I want to see https traffic of this app with charles)

  • I installed charles certificate in my phone enter image description here

  • I configured charles ssl proxy enter image description here

The Issue

I can not use https in MyApp (plus, all the android app except browsers) enter image description here

P.S.

I tested with browser (MS Edge for android). I could access Internet. I could see the traffic through charles and it was https. I can use browsers, but all other apps doesn't work. (youtube, play store doesn't work)

Question

  • Only browsers working fine. (when I remove the certificate, then browsers can not use https) how to make other apps (youtube, play store and "MyApp") to use Charles certificate?
like image 597
Jerry Avatar asked Sep 02 '25 17:09

Jerry


1 Answers

I found the missing piece!

https://www.charlesproxy.com/documentation/using-charles/ssl-certificates/

As of Android N, you need to add configuration to your app in order to have it trust the SSL certificates generated by Charles SSL Proxying. This means that you can only use SSL Proxying with apps that you control.

In order to configure your app to trust Charles, you need to add a Network Security Configuration File to your app. This file can override the system default, enabling your app to trust user installed CA certificates (e.g. the Charles Root Certificate). You can specify that this only applies in debug builds of your application, so that production builds use the default trust profile.

Add a file res/xml/network_security_config.xml to your app:

<network-security-config> 
  <debug-overrides> 
    <trust-anchors> 
      <!-- Trust user added CAs while debuggable only -->
      <certificates src="user" /> 
    </trust-anchors> 
  </debug-overrides> 
</network-security-config>

Then add a reference to this file in your app's manifest, as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config" ... >
        ...
    </application>
</manifest>

So I need to

  1. add above configuration
  2. build the debug build
like image 122
Jerry Avatar answered Sep 05 '25 08:09

Jerry