androidreact-nativenginxexpossl-certificate

react-native java.security.cert.CertPathValidatorException: Trust anchor for certification path not found


My React Native mobile application suddenly cannot connect with the backend. (only android version, iOS works without any problem). Also I can request the API without problem by using the browser.

This just suddenly happened, when the problem start where were no changes in the server side or in the mobile application, but all android apps stop to connect to the server.

The exception in the mobile application says: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

I have reviewed every answer in Stack Overflow but nothing works so far. These are the main points:

In the mobile:

Some relevant dependencies version are:

"dependencies": {
    ...
    "axios": "^1.1.3",
    "expo": "^44.0.0",
    "expo-cli": "^5.4.3",
    "react": "17.0.1",
    "react-native": "0.64.3",
    "react-native-gesture-handler": "~2.1.0",
    ...
  },

In the server:

Given all this test it seems to be a server side problem, but no other device have problem with it, only android; Also I test the certificate and its OK

I also test the certificate with this website https://www.ssllabs.com/sstest

And this was the result

SSL Test

I will be grateful for any clue you can give me.

Regards!


Solution

  • I managed to make the application connect with my API successfully, but I'm still researching the origin of the problem.

    More context:

    It seems to be a problem of the library axios (specifically axiosinstance). Its weird because I didn't change anything in the android app, it just suddenly stopped to work. (in all the android devices at the same time).

    And just doing tests I realized that axiosinstance fail by doing the request (with the exception that I already showed you), but in an inexplicable way if the first request pointing to my API that I do in the app is by using axios it works perfectly, and after that axiosinstance is capable to perform any request to my API without fail.

    I know it sounds weird, but now my app is working again.

    By other Side, just to let you know, I also tested an android app called API Tester v5.6 and it fails connecting to my API giving me the same exception, but it last version API Tester 5.7 (which was released just some days ago) works without problem.

    I also tried to connect to my API with ApiClient v2.4.7 and it fails with the same exception.

    Again, I don't understand what is the real problem but definitely is not the certificate.

    Anyway, now you know, maybe I should post this problem to the axios guys?

    Regards!