11

When I'm using the fetch function in my react native apps, things work as expected on iOS, but gives an error in android. The error is 'TypeError: Network request failed'. Doing a bit of debugging, I found that the cause of the error seems to be the following: 'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found'.

How come this works in iOS and not on android, and how do I best fix it? Is the fault in react-native, or somewhere deeper?

Jesper Lugner
  • 195
  • 3
  • 12
  • 1
    It's probably a server certificate issue. What is the server from where are you trying to fetch? Make sure you check your server's ssl certificate with this website https://www.digicert.com/help/ or with running. openssl s_client -debug -connect www.thedomaintocheck.com:443 – Orlando Jul 05 '16 at 06:38
  • they are two separate devices. iOS might have trust established. – vijayst Aug 07 '16 at 08:50
  • If you're using Expo, see my answer here: https://stackoverflow.com/a/70775576/4350421. Hope it helps :) – silentsurfer Jan 19 '22 at 18:24

1 Answers1

4

There is a few workarounds for this issue mentioned here: Trust Anchor not found for Android SSL Connection

However, if you are the server owner. I would suggest to review your server ssl certificate. I think that was because of missing CA certificate in your pem file. What I have done for my site is I created fullchain.pem by concating content of file.crt and file.ca-bundle as that order.

Then I configure nginx (my server behind nginx) with: ssl_certificate /etc/nginx/ssl/fullchain.pem;

The original document: https://www.digicert.com/ssl-certificate-installation-nginx.htm

Hope that helps

Community
  • 1
  • 1
tenolife.com
  • 326
  • 2
  • 8