How to get charles proxy work with Android 7 nougat? - android

Android 7 introduced some changes to the way certificates are handled (http://android-developers.blogspot.com/2016/07/changes-to-trusted-certificate.html) and somehow I cannot make my Charles proxy work any more.
My network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<debug-overrides>
<trust-anchors>
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
I'm running in debug mode. But no matter what, I get javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found..
Needless to say, I did install a pfx certificate from Settings -> Security -> Install from storage. The certificate shows in User Credentials but not in Trusted credentials -> User. On my lollipop device, the certificates are listed there.
I'm using okhttp3 as HTTP library.
Any idea what I am doing wrong ?

The solution is do not use .p12, just navigate with Chrome (with configured proxy on wifi) to http://charlesproxy.com/getssl and install downloaded .pem file.
I had exactly the same problem on my Nexus 5X running Android 7.0.
There was previously exported .p12 from Charles 3.11.5 (Help->SSL Proxying->Export Charles Root certificate and Private key). When I tried to install .p12 from phone (Settings->Security->Install from storage) it appears only under "User credentials" and never at "Trusted credentials", and of course SSL with Charles proxy did not work.
The total "how-to" for Android 7.0 would be like that:
Configure WiFi + proxy (how Charles requires it). Connect it.
On device, navigate with Chrome to http://charlesproxy.com/getssl, accept request for download .pem, then press "open", it launches "Certificate installer" app. Use it to install the certificate as "VPN and apps".
Put the attribute android:networkSecurityConfig="#xml/network_security_config" to <application> at Manifest.xml
Create res/xml/network_security_config.xml with content from the first post (it is totally correct).
Launch Charles and app and have fun.
P.S. Check date/time on the device. It should be correct.

Based on the troubleshooting thread of comments for the OP, the answer is to install just the proxy's CA cert as trusted, not its cert + private key.
The issue was caused by two factors:
Installing not just the MiTM proxy's CA cert but also its private key (thus enabling VPN apps on the device to decrypt/MiTM network traffic from other apps). You don't need the MiTM proxy's private key on the device.
Android Nougat change in behavior of the Settings -> Security -> Install from storage flow for files which contain a private key in addition to cert(s). This change in behavior unmasked the above issue.
Prior to Nougat, the Settings -> Security -> Install from storage flow for files containing a private key in addition to certs erroneously installed the certs as trusted for server authentication (e.g., HTTPS, TLS, thus making your MiTM succeed), in addition to being correctly installed as client certs used for authenticating this Android device to servers. In Nougat, the bug was fixed and these certs are no longer installed as trusted for server authentication. This prevents client authentication credentials from affecting (weaking) the security of connections to servers. In your scenario, this prevents your MiTM from succeeding.
What complicates matters is that the Settings -> Security -> Install from storage does not provide an explicit way for the user to specify whether they are installing a client authentication credential (private key + cert chain) or a server authentication trust anchor (just a CA cert -- no private key needed). As a result, the Settings -> Security -> Install from storage flow guesses whether it's dealing with client/user authentication credential or server authentication trust anchor by assuming that, if a private key is specified, it must be a client/user authentication credential. In your case, it incorrectly assumed that you are installing a client/user authentication credential rather than a server authentication trust anchor.
P. S. With regards to your Network Security Config, you should probably configure the app to also trust "system" trust anchors in debug mode (debug-overrides section). Otherwise debug builds of the app won't work unless connections are MiTM'd by a proxy whose CA cert is installed as trusted on the Android device.

I also had the same error and tried every way until I read the following message which was key: "The certificate shows in User Credentials but not in Trusted credentials".
So the problem was how to make the certificate appear there and these were the steps I followed:
Download the certificate in the emulator from http://chls.pro/ssl
Install the certificate & Trust
Setting app -> Security -> Encryption & Credentials -> Install a Certificate -> Select CA Certificate option
Select Install Anyway
Select Charles Proxy Certificate that you downloaded on your storage
Verify that you're trusted the certificate
Open Trusted Credentials -> User Tab and you can see your certificate here
Start intercepting HTTPS Traffic

For me SSL proxy was not working in release build variant. In debug worked.

I'm on Android 7.1.1, here's how I setup on my device (OnePlus One) - without the change of manifest (I was targeting API 21 for my app):
In Charles Proxy:
Help > SSL Proxying > Install Charles Root Certificate on a Mobile Device or Remote Browser. This steps gives you the proxy IP and port number and also the link to where you should download charles proxy SSL.
On your phone:
Wifi Settings > Modify Network > Advanced Options. Set Proxy to Manual and enter the IP and Port number you received from Charles into Proxy hostname and Proxy port respectively.
(OPTIONAL) You may or may not be able to access the chls.pro/ssl link provided by Charles earlier. On my device, I was always notified that I had no network connection. I added the charlesproxy.com to the Bypass proxy for field.
On your browser, go to the link in step 3 and download whatever certificate necessary (if it doesn't work on Chrome, download Dolphin Browser).You can name your certificate with whatever name.
Back on Charles Proxy:
You should get the prompt to either Allow or Deny your phone to use the proxy if your settings is defaulted to prompt you for remote connections.
You can now use Charles on Nougat 7.1.1.

Related

Installing Charles proxy certificate on Samsung [duplicate]

I have followed instructions on how to add fiddler certificate on android emulator, using both nox and memu emulators, as well as my android phone running marshmallow, I set the WiFi proxy to point to my PC over the local network, when I open a website using a web browser, things work fine, I receive the warning, I choose to proceed and the connection is successfully tunneled and decrypted using fiddler.
But, when I try to use other apps, connections fail! I see the tunnel connections, and then connection fails. My bet is, it's due to the invalid HTTPS certificate, so my question is, is there a way for me to install fiddler to the trusted authorities so connecting to it will go through without the warning? So I can finally debug HTTPS traffic from and to those apps.
I found similar questions here on SO, but none of them were exactly the same as mine, nor did they have the right answers, so I'm not sure if this question does in fact qualify as a duplicate.
Thanks
On modern Android devices using apps developed for target API Level 24 (Android 7) or higher sniffing traffic is not that simple anymore. The target API level of an app is defined it's AndroidManifest.xml file in the entry <uses-sdk android:targetSdkVersion="??"/>.
The main problem is that if you install the Fiddler root CA certificate in Android it is marked as user certificate (not system certificate). And unless explicitly configured in an app those user certificates are not trusted.
One of those rare apps that respect user CA certificates is Chrome. So using Chrome for testing if the proxy and the installed root CA certificate works is a bad idea, as it may only work in Chrome but not for apps.
Note that some apps further use certificate pinning (leaf or root CA pinning). Therefore even if the Fiddler root CA certificate is installed as system certificate the app won't trust this certificate as it fails on the certificate pinning.
Certificate pinning is also a web site feature, hence some sites save a certificate hash in the web browser cache that pins the site to a certain certificate. In such a case clearing the browser cache is usually removing those pinning data.
Rooted devices
If your device is rooted you can try to install the Fiddler root CA certificate as system certificate. The Mitmproxy documentation contains a how-to for manually installing the mitmproxy certificate.
If you have rooted the phone using Magisk, there is a Magisk module that seems to be able to install user certificates automatically as system certificates: https://github.com/NVISO-BE/MagiskTrustUserCerts
Alternatively you can install Magisk + Edxposed + TrustMeAlready Xposed module. This allows to disable certificate checking system wide - WARNING: this eliminates the security of SSL/TLS against active attacks, for all apps on the phone. Therefore only do this on a device you use just for hacking!
Also possible is installing and run Frida-Server on the device and hook into the app you are interested to modify the SSL/TLS certificate checking at run-time. AFAIK the Frida based framework Objection has some scripts to do so.
Non-rooted device
On a non-rooted device there is only the option to modify the application before you install it onto the device. Note that some apps will detect that they have been modified and will refuse to work.
To let the app trust user certificates you have to modify network_security_config.xml (see e.g. here) included in the app. You can use apktool to decompile/recompile the app. Don't forget to re-sign the recompiled/repackaged app e.g. using apksigner from Android SDK.
There are some tools available that automate the decompiling , modification and signing like apk-mitm.
There is also the possibility to modify an app by including the Frida gadget for Android into the app. This would allow to use Frida for this specific app on a non-rooted device.

Charles SSL Proxy works for chrome but not for the apps

I'm using Nexus 5X device running Android 7. I failed to setup the proxy using the recent instructions from Charles Proxy documentation. I installed certificate, but wifi settings or nugat are extended. I can set charles as a certificate but that won't let me connect to that wifi (authentication problem). So I leave it as "don't check correctness". I don't even know if that's relevant.
The thing is when I try to sniff on my app https calls I see SSLHandshake: Received fatal alert: certificate_unknown
However if I run a web client using chrome on the same device - I can read calls to the same api.
The bottom line is it works for a browser but not for my app. I checked on other apps aswell. Same output.
The reason I ask here is because maybe I have to add some unsafe client to my retrofit api setup - hopefully not.
Here is how you need to configure you apk in order to make CharlesProxy work in Android 7.
Android
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 ... >
<applicationandroid:networkSecurityConfig="#xml/network_security_config" ... >
...
</application>
</manifest>
Here you can find more details:
https://www.charlesproxy.com/documentation/using-charles/ssl-certificates/
In Charles, select Help -> SSL Proxying -> Install Charles Root Certificates in IOS Simulators, close the iOS Simulator and restart the simulator. It should work now.

How to install CharlesProxy ssl cerificate in Android

I am connecting Mobile device with System via Proxy and capturing calls made in the mobile devices.
When "https" requests are captured, I am not able to get response from it.
Getting following error in System:-
No request was made. Possibly the SSL certificate was rejected.
Client Process: java
You may need to configure your browser or application to trust the Charles Root Certificate. See SSL Proxying in the Help menu.
Note: I have installed charles proxy ceritificate on system and also imported certificate in Mozilla Firefox. I am able to get response for "https" from Mozilla browser on System
I have loaded charlesproxy.com/getssl on mobile. It says "Certificate is already installed on your device"
When you downloaded the certificate from charlesproxy.com/getssl, was your mobile device connected via the Charlesproxy instance that you're trying to set up?
The more recent versions of Charlesproxy create a custom certificate, so the SSL proxying setup will only work if your device was being proxied at the moment when you installed the certificate. If it wasn't, you may want to delete it and install it again while connected via Charles.
I also like to restart charles and reboot the mobile device after installing a certificate. Maybe it's superstitious, but I've had cases where the SSL calls only worked after the reboot.
Installing ssl certificate on the device will only help with browser ssl logs, to trace ssl data of apps you will have to do the following.
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>
Source: https://www.charlesproxy.com/documentation/using-charles/ssl-certificates/
For what it's worth I always had problems connecting my Personal Android phone to charles proxy despite lots of troubleshooting - I would always get errors that my network had or the error in the OP.
I went into my phone's User Credentials System setting. I had 20 or so charles certs from previous attempts and other machines i've installed over the past two years - i deleted them all and things started working again. I hope that helps someone.

Charles ssl certificate download failed "due to network failures"

The Charles SSL/HTTPS proxying was working fine on my Samsung Galaxy S5 phone.
I remove the certificate while not debugging because the phone warns me about the connection being monitored by a third party.
Now when I attempt to re-download the certificate from http://www.charlesproxy.com/getssl/ I get a charles-proxy-ssl-proxying-certificate.pem download failed due to network failures error:
The phone is set up to use the Charles proxy. HTTP traffic can be inspected in Charles.
I'm running Charles 3.11.4 but I've also tested with 3.11.2. The phone is running Android 5.0
I tested with an LG Nexus 5 and the certificate downloaded and installed without any problems.
As a workaround, type this into your address bar and press Go.
data:text/html,<a href=http://www.charlesproxy.com/getssl/>Save This Link
Long-press on the link that appears and choose Save Link. Then open the certificate you downloaded.
It's Chrome Mobile - try a different browser, Dolphin worked fine.
Yet another thing Google broke in Chrome Mobile.
I manually worked around this issue by:
Exporting the Charles certificate (Help > SSL Proxying > Export Charles Root Certificate and Private Key...) and setting a suitable password
Copying the certificate to Google Drive
Disabling the Manual Proxy setting on the Android device
On the Android device going to Settings > Security > Install from storage
Selecting the Google Drive account containing the certificate
Selecting the certificate file and entering the password
Selecting "VPN and Apps" for "Credential use"
The certificate was then loaded into the system-wide User credential storage and I was able to successfully SSL proxy the app I'm currently working on.
I did it very simply.
Go to URL http://charlesproxy.com/getssl/
In Charles, you should see a response from the server with the certificate.
Like in this screen:
http://i.stack.imgur.com/pe3z7.png
Copy this text in txt file, and save it like *.cer
Attach *.cer to email, and send it to a device.
On your phone, you should click on the attached file and install the certificate.
Profit!)
I was also getting charles-ssl-certificate-download-failed-due-to-network-failures error. I had updated charles to version 3.11.5 and then installed charles certificate on my mobile device.
It worked like a charm. I guess either in earlier version my browser was not configured to use charles proxy. Or there might be some issue in previous charles version.
Hope it helps :)
After a lot of struggle and swears, I found the problem that was going on with my Charles. I was getting network errors/failures due to long connections
It seems this was a problem from the additional connections created from my virtual machines. For anyone still stuck on this, to solve, instead of setting the IP in the Help-SSL Proxying-Install charles root ceritificate on a mobile device or remote browser, set your actual IP from windows. To get this, navigate to Network and Sharing centre - click on your current connection - Details - and then use the IP under IPv4 Address. Then use the HTTP port as configured in Charles.
It works to me by exporting SSL certificate to a file and copy this file to mobile device. Then install it from phone.
Check this post:
http://go4test.blogspot.ca/2016/10/charles-proxy-failed-due-to-network.html
similar as Evgeniy Melnikov suggested.
Exporting the Charles certificate (Help > SSL Proxying > Export Charles Root Certificate and Private Key...) and setting a suitable password
from where the cert is saved at #1, attach to an email and send to an account which is accessible from the mobile.
in the mobile mail client download the attached cert file (to Downlaod folder).
in the mobile Setting > Security > install from storage, (or in some emulator Settings > Security > install from SD card) goto Downlaod folder and clicking on the downloaded cert file.
Selecting the certificate file and entering the password.
Selecting "VPN and Apps" for "Credential use"
after the cert is installed on the device, change the wifi settings to point to the machine the Charles in stalled and running.

Charles proxy fails on SSL Connect Method

I have Android 4.3 forced to use Charles proxy via IPTABLES.
The charles certificate is installed on the phone.
I am able to capture normal SSL traffic like https websites in the browser.
All POST and GET methods seem to work fine.
In a particular app, it fails when using the SSL CONNECT method.
URL: https://XX.XX.XXX.XXX/
Status: Failed
Failure: SSLHandshake: Received fatal alert: unknown_ca
Response Code: - Protocol: HTTP/1.0
Method: CONNECT
From iOS 10.3 you also need to go to Settings > General > About > Certificate Trust Settings and trust Charles certificate.
You can face with this problem at some applications like Facebook or Instagram.
Charles certificate doesn't work at some new apps because they are using a technique named as SSL-PINNING. First of all you have to break ssl-pinning system of application or you can instal old version of application then it sometimes works but we need a new solution about ssl pinning in order to record traffic for this kind of applications.
as #Berkay Yıldız says, it probably using ssl/certificate pinning.
how to fix/avoid/disable ssl pinning?
the whole logic is:
LEVEL 1: for normal http:
core logic:
PC:Mac/Windows
Charles set http proxy
set port
app use Charles proxy
inside Wifi, set
host IP
port
Note:
computer side, MUST use wired network, NOT wireless, otherwise mobile side network not usable
LEVEL 2: for encrypted https:
PC
install Charles root certificate
Mac:use Key Chain to trust Charles Root CA
Charles
Enable SSL Proxying
set location filter for your specific api address
phone
app
install Charles Root CA
Note: type should select: VPN and Application
NOT select:WLAN
makesure certificate install successfully
Trusted Credentials -> User, can see installed Charles certificate
LEVEL 3: for SPECIAL https which using ssl pinning:
Phone:
make sure root or jailbreak
Android:has rooted
for later to install tool: Xposed
iOS:has jail break
for later to install tool: Cydia
then install plugin/tool, capable of avoid/disable ssl pinning
Android:
JustTrustMe (based on Xposed)
Android-SSL-TrustKiller (Cydia Substrate)
iOS:
SSL Kill Switch 2 (based on Cydia)
old version:iOS SSL Kill Switch (based on Cydia)
more detailed summary please refer my post (written in Chinese): 1 and 2
Some folks my end up here with android N Devices that won't do SSL over charles even after installing the cert - now on http://chls.pro/ssl
In N - you need to also add an xml file and security config. This post goes into more details: How to get charles proxy work with Android 7 nougat?
I have met the same problem. And after installing the latest certificate, it is solved.
On your phone, visit http://charlesproxy.com/getssl to download the cert. Upon downloading the cert in android, it will prompt you to install the cert, give the cert a name and continue. It should now work.
Note: The sshould be similar on an iPhone
I got the following error when I was trying to install the cert on my Nexus 6p, Android 6.0. (I followed the instructions in charles and downloaded the cert via http://chls.pro/ssl.):
Couldn't install because the certificate file couldn't be read.
The solution to this problem was to install via:
Settings > Security > Install from storage
After navigating to the cert file and installing it everything worked as expected.
On this link http://www.charlesproxy.com/documentation/using-charles/ssl-certificates/ you have all the information you need on properly installing the Charles certificate.
After installing it you'll get rid of the "SSLHandshake: Received fatal alert: unknown_ca" error.
If you get this with an app using facebook login on an android phone, I got around it by uninstalling the fb app. Then the mobile fb web is used instead and I can charles everything. With the fb app installed the fb api fails with SSL error.
On Samsung phones, you should install the certificate by navigating to Biometrics and security/Other security settings/Install from device storage/CA Certificate.
I am using Charles 4.2.5 and Nexus 6P on Android 8.1.
One cannot use Charles to track https on my mobile phone.
Plz note that after Android N, we cannot capture normal SSL traffic of others'app.
Here is the official website of Charles.
https://www.charlesproxy.com/documentation/using-charles/ssl-certificates/
Android 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:
Then add a reference to this file in your app's manifest, as follows:
...

Categories

Resources