I made an app where you can login and do some things. The problem is in the login: when it send a request to my API, it throws an error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. Android 2.3 but the SSL is working (I had to use ZeroSSL). For a temp fix, I had to accept all SSL certificates. All this was working until I uploaded the app to Google Play Console where Google said that there were vulnerabilities: TrustManager and HostnameVerifier.

Now the question is: why is the app throwing the error? The SSL is working everywhere, only in the app is not working. How can I fix so I can upload to Google Play Store?

The code in the login java file is the following: `HttpsTrustManager.allowAllSSL(); // Construct the URL with the GET parameters URL urlObj = new URL(url + "?email=" + username + "&password=" + password + "&hwid=" + hwid);

            // Open a connection to the URL
            HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();

            // Set the request method to GET
            con.setRequestMethod("GET");

            // Get the response code
            int responseCode = con.getResponseCode();
            System.out.println("Response Code : " + responseCode);

            // Read the response from the server
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            // Extract the "status" parameter from the response JSON
            JSONObject jresponse = null;
            try {
                jresponse = new JSONObject(response.toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
            String status = null;
            try {
                status = jresponse.getString("status");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (status.equals("success")) {
                userLogged =
                        new LoggedInUser(
                                java.util.UUID.randomUUID().toString(),
                                username);
                return new Result.Success<>(userLogged);

            } else if (status.equals("error")) {
                try {
                    return new Result.Error(new IOException(jresponse.getString("message")));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

}`

And the "allowAllSSL" is from there: way to Ignore ssl certificate using HttpsURLConnection

I double checked the validity of the SSL, but from my side everything is fine. The SSL is issued from ZeroSSL. The api is using NodeJS and .cert files to add the certificate to the express server.

0

There are 0 best solutions below