SSL Certificate on Android not beeing used by Chromium - android

I am currently trying to reach my own web-service via Chromium on Android 8.1
I have installed the Certificate for the Server, but when I try to reach my service I get a "Your connection is not private" Error.
To install the CA I have downloaded it via Chrome on my desktop and pushed it via USB to my phone.
I then went to Settings -> Security & Location -> Encryption & credentials -> Install from storage and installed it.
The Phone is in the same network as the server is and it knows the FQDN and IP of the server
Edit 1:
To clarify further: it's a self-signed Cert, so the certification-path contains only one certificate, that of the server

Related

Trust Anchor not found for Android under proxy connection

I developed a simple Android app using Expo SDK that communicates with my server via HTTPS (using Axios if it matters). I have bought the domain and use a LetsEncrypt certificate configurated in NGINX that has an A+ score in the Qualys SSL Test. The app works well with most of my clients except one that uses it under a network proxy that I don't have access to.
Every time the app tries to request the servers I get the error:
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Which according to this article https://developer.android.com/training/articles/security-ssl?hl=en-us can happen when "The CA that issued the server certificate was unknown", "The server certificate wasn't signed by a CA, but was self signed", "The server configuration is missing an intermediate CA" which is not the case since it works with every other client.
This client uses Android 8.1 and I've already checked in “Encryption & credentials” settings that "DST Root CA X3" (which is the anchor for LetsEncrypt) is listed as a trusted root certificate in the devices.
For test purposes, I also have developed a version of my app that does not use HTTPS and it works fine even under the proxy connection.
Am I missing something here? What else could be causing this problem? Any ideas on how to replicate it? Thank you!

Use mkcert certificate for local testing of PWA

I'm trying to setup a local dev environment for a PWA I'm working on.
I have installed mkcert on my Mac and am able to host a https://localhost version on my computer.
Now I'd like to open the page on my Android phone. On the mkcert github it says:
Mobile devices
For the certificates to be trusted on mobile devices,
you will have to install the root CA. It's the rootCA.pem file in the
folder printed by mkcert -CAROOT.
On iOS, you can either use AirDrop, email the CA to yourself, or serve
it from an HTTP server. After installing it, you must enable full
trust in it. Note: earlier versions of mkcert ran into an iOS bug, if
you can't see the root in "Certificate Trust Settings" you might have
to update mkcert and regenerate the root.
For Android, you will have to install the CA and then enable user
roots in the development build of your app. See this StackOverflow
answer.
https://github.com/FiloSottile/mkcert
I installed the rootCA.pem on my phone. The part about "enabling user roots" doesn't apply, since this is not an app.
But when I open the page on my phone using https://[my-local-network-ip]:1234 I get a warning, that the certificate can't be trusted.
How can I trust the certificate so I can locally test the PWA on my phone?
I know you've probably moved on from this question, as it's almost a year on. However, I would like to share how I was able to test my PWA locally in a secure context.
Not making any assumptions about what framework / packaging / build system you're using:
Generate a certificate & key using mkcert. If you are hosting your PWA locally & want to access it over your local IP address i.e. 192.168.1.x:3000 you also need to tell mkcert to generate a certificate that covers that IP address:
mkcert localhost 192.168.1.17
// The certificate is at "./localhost+1.pem" and the key at "./localhost+1-key.pem" ✅
Important note: most routers dynamically assign local IP addresses, so it's worthwhile assigning a static IP.
Install your RootCA from mkcert onto your iOS or Android device. Follow the instructions in the mkcert docs
Serve your generated certificates with your web server of choice. I use Create React App. You can see my answer about PWAs in secure context here
I agree with your goal - running a local TLS based setup can be useful in terms of productivity and early troubleshooting.
Your problem is DNS based and you need to access the TLS secured URL via the host name.
The only way you'll get DNS to match up on the Android side is to use an HTTP proxy, while running either an emulator or a device connected via USB.
In a nutshell I would do this:
Issue your cert to a more real world domain name such as mycompany.com
Add this domain name to DNS on your Mac book
Install a free proxy such as proxyman on the Mac
Configure the Android emulator or device to use the proxy (you will also need to trust the proxy's cert on Android and the Mac)
Then browse to https://mycompany.com from Android
Full details are available in my write up

How to get charles proxy work with Android 7 nougat?

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.

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