5

I am building an app in react-native and using axios package for post request. I get the error when axios post request in react-native android app. SSL certificate is signed with letsencrypt.

Https request is working with React-Native 0.47.2 but after upgrading to React-Native 0.55.0 it gives the certificate error.

Certificate is working in both desktop and mobile browsers as well as on application web portal but not working in android app.

Versions android: 8.0.0 React Native: 0.55.0

Error

"java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."

Abdul Kawee
  • 2,666
  • 1
  • 13
  • 26
zainhassan
  • 1,590
  • 5
  • 10

3 Answers3

3

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">10.0.2.2</domain><!-- Debug port -->
        <domain includeSubdomains="true">abc.online</domain>
        <trust-anchors>
            <certificates src="@raw/abc"/>
        </trust-anchors>
    </domain-config>
</network-security-config>

This works for me, 10.0.2.2 is the default number for the emulator to communicate with localhost on your machine. If you are using your phone, it should be another IP address.

enter image description here

Taazar
  • 1,547
  • 17
  • 27
Ming Li
  • 29
  • 1
  • 2
0

I have solved this issue using the following solution.

From Android 9(Pie) we need to set networkSecurityConfig into AndroidManifast.xml

<application android:networkSecurityConfig="@xml/network_security_config">

</application>

Now Create a new xml resource file with the name network_security_config.xml into value/xml folder. This Configuration applies to the base configuration, or the default security configuration, of the app and disables all clear text traffic.

<network-security-config>
  <domain-config cleartextTrafficPermitted="false">
    <domain includeSubdomains="true">172.16.33.1</domain>
  </domain-config>
</network-security-config>

For more information, you check the following links

https://codelabs.developers.google.com/codelabs/android-network-security-config/#3

https://developer.android.com/training/articles/security-config

https://medium.com/@son.rommer/fix-cleartext-traffic-error-in-android-9-pie-2f4e9e2235e6

Vishal Dhanotiya
  • 2,285
  • 1
  • 13
  • 31
-1

The meaning of that exception is that the domain name that you have used is stg server means it has private dns. Solution 1 So in that case ask your server guy to make a certificate file with ext. .cert for you. And after that install it on your device and then add dns1 and dns2 to your wifi.

Solution 2 Instead of using domain name as url use ip address of your server.it may solve this problem too

  • The meaning of that exception is that the signer of the certificate is not trusted by this client. Nothing to do with DNS whatsoever. – user207421 Mar 04 '20 at 09:29