2

trying to access https://localhost:5000/ that has my own self signed certificate through android studio (with kotlin), and I keep getting the error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Ive made the certificate using openssl through a guide i found here using method 2

I have tried adding an network_security_config.xml file that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">https://10.0.2.2:5000/</domain>
        <trust-anchors>
            <certificates src="@raw/my_ca"/>
            <certificates src="user"/>
            <certificates src="system"/>
        </trust-anchors>
    </domain-config>
</network-security-config>

and I have made inside of res a folder called raw and put inside of it my_ca.pem, (which i converted from crt using openssl x509 -in server.crt -out server.pem -outform PEM and renamed to my_ca.pem)

I also tried adding that certificate on the android studio settings, or allowing all untrusted sites, the code to the html request is as simple as i found:

URL("https://10.0.2.2:5000/").readText()

, it is inside an AsyncTask class, but all the class does is this request

Im accessing 10.0.2.2 and not 127.0.0.1 because from what i understood, its the way to access the local mchine through te emulator, and the erver code is a very simple python-flask code that returns a simple string

eitan 03
  • 93
  • 7

1 Answers1

0

So I figured it out, altough i did enable self signed certificate on android studio, I didnt enable them on kotlin, so the error came from kotlin and not android studio, a quick copy-paste from this answer

has solved it, altough I dont understand a thing from it, and if someone could send me a refrence to some sort of explantion or a tutorial for it that would be wonderful.

eitan 03
  • 93
  • 7