Charles proxy in non debuggable flavour of Android app - android

First of all let me clarify that I know that this is a very bad practice and I will not push this change into my production code. But sometimes we need to debug some changes in non debuggable flavour of my application but all the https urls are failing with the following error
Client SSL handshake failed: An unknown issue occurred processing the certificate (certificate_unknown)
I have used the following network config files and added in my manifest file. This is working in debuggable flavour of the app but still not working in non-debuggable flavour.
<?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>
Is there any way I can use charles to monitor my network calls in the non-debuggable flavour of the android app ?

This one works for me:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="user" />
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
Source

When creating your release build that needs to debug using Charls, In the Manifest inside the application context. please add android:debuggable="true" after that try to build your release build and try to debug using Charls.
I have not tried this but this might work. According to the following link.
https://developer.android.com/training/articles/security-config.html

Related

FLUTTER App work from Apk but installing from Playstore does not work. Cannot access server

I have problem with my flutter app. It works from compiled APK file when I debug it. So then, I upload to playstore. When the release is approved. Then I install the app from playstore. However, it stucks on the loading. It seems cannot access the app directly.
Is the problem comes from this one
Here is my network_security_config
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">127.0.0.1</domain>
</domain-config>
</network-security-config>

React-native android does not build when i add networkSecurityConfig tag

As I found in this article.
I want to update my network security config to allow root certificates from the personal store of my android emulator.
but when I do this, I cant build my app anymore. The error message:
Unable to load script. Make sure you're either running a metro server
(run 'react-native-start') or that your bundle 'index.android.bundle'
is packaged correctly for release.
when i remove android:networkSecurityConfig="#xml/network_security_config" its all running fine again..
Does anyone know what to do? or has an other way of making changes to the security config?
okay, finally found it !! :)
React native does need clear text traffic for the build.. so the network security config file should contain: <base-config cleartextTrafficPermitted="true">
so i have a tag in src/debug/AndroidManifest.xml
<application tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning"
android:networkSecurityConfig="#xml/react_native_config" />
and created a file src/debug/res/xml/react_native_config.xml with:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="user"/>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>

Self signed certificated - java.security.NoSuchAlgorithmException: Error constructing implementation

I create my own CA authority for local deploy. And APIRest, web and app. So my certificates work well in web.
In android I been configure my network_security_config.xml like this way:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<trust-anchors>
<certificates src="#raw/myca"/>
<certificates src="system"/>
<certificates src="user"/>
</trust-anchors>
</domain-config>
</network-security-config>
When I run tns run android and I try to connect to my api the console show me this error:
"error": { JS: "originalStack": "Error: java.net.SocketException:
java.security.NoSuchAlgorithmException: Error constructing
implementation (algorithm: Default, provider: AndroidOpenSSL, class:
com.android.org.conscrypt.DefaultSSLContextImpl)\n at new
ZoneAwareError
(file:///data/data/org.nativescript.ngsample/files/app/vendor.js:91593:33)\n
at onRequestComplete
(file:///data/data/org.nativescript.ngsample/files/app/vendor.js:97990:34)\n
at Object.onComplete
(file:///node_modules/#nativescript/core/http/http-request/http-request.js:43:0)"
What could be the problem?
This was easy. My mistake was not read the documentation. I only need to change mi security_network_config.xml
<domain-config>
<domain includeSubdomains="true">192.168.1.67</domain>
<trust-anchors>
<certificates src="#raw/myca"/>
</trust-anchors>
</domain-config>

Charles Proxy not working for Android version above 7.0?

I am using Charles for intercepting request and response from a long time,but When I tried google pixel targeting Android Oreo, It keep giving me hand-shake exception. I was aware their certain changes has been done in Naught about network security. Any sort of help will be appreciated.
If you are facing issue using Charles on Device tar-getting above 7.0 in Android, follow these steps, as detailed in the Charles Proxy documentation
Add following line
android:networkSecurityConfig="#xml/network_security_config">
to your manifest file in Application Tag.
Create a xml folder with a file named network_security_config and paste following code in it.
<?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>
Note: Do not commit above to your branch if you have only single build flavours.
For People having different build flavours (debug/release/other) can use this for debug version and commit as well.
The other answer is correct as well, but according to the documentation the base-config xml tag is not needed at all. While this is not explicitly mentioned, their example does not include that tag.
This is the code on the Documentation site for "Configure CAs for debugging":
res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<certificates src="#raw/debug_cas"/>
</trust-anchors>
</debug-overrides>
</network-security-config>
Instead of specifying a specific certificate, we can just allow user-installed certs though, like in the other answer:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>

Charles Proxy + Android HTTPS

So here are some similar but outdated answers that might have helped me few years/months ago:
Why can't I see http or https traffic from Chrome Browser for Android on Charles Proxy?
How to get charles proxy work with Android 7 nougat?
I followed all of the instructions, I can read http requests fine, but not https requests. Still can't figure what I am doing wrong. There isn't much of my own to post since I have just followed the above guides.
I think the main issue is how do I force the app I am trying to debug to use my certificate? The manifest modifications don't seem to do the trick.
See this question which has updated answers for Charles 4 and Android 7.
You must install the cert from Charles help menu, and you must use Settings -> Security -> Install from storage on device.
Your app needs a network_security_config.xml
You must use a debuggable app
For those who look for more recent Android Release (8,9,10 or ++) + CharlesProxy 4.6
Can refer this guidethrough...
From Android N+, it requires extra steps to make it works.
1.Add res/xml/network_security_config.xml to your project.
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
<certificates src="system" />
</trust-anchors>
</debug-overrides>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<domain-config>
<!-- Make sure your URL Server here -->
<domain includeSubdomains="true">your_production_domain</domain>
<trust-anchors>
<certificates src="user"/>
<certificates src="system"/>
</trust-anchors>
</domain-config>
=> Make sure you replace your_production_domain with the domain that you would intercept
2.Add to AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="#xml/network_security_config" ... >
...
</application>
</manifest>
If you could not make it works, you can check out the sample code, which has all configuration.

Categories

Resources