1

Here is my code for Volley:

class VolleyService {
    public RequestQueue volley(Context context) {
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {

            try {
                ProviderInstaller.installIfNeeded(context);
            } catch (GooglePlayServicesRepairableException e) {
                Log.e("Test321", "PlayServices not installed");
            } catch (GooglePlayServicesNotAvailableException e) {
                Log.e("Test321", "Google Play Services not available.");
            }

            HttpStack stack = null;
            try {
                stack = new HurlStack(null, new TLSSocketFactory());  // WORKS FINE TILL HERE
            } catch (KeyManagementException | NoSuchAlgorithmException e) {
                e.printStackTrace();
                stack = new HurlStack();
            }
            return Volley.newRequestQueue(context, stack);
        } else {
            return Volley.newRequestQueue(context);
        }
    }

    private class TLSSocketFactory extends SSLSocketFactory {

        private SSLSocketFactory internalSSLSocketFactory;

        TLSSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
            SSLContext context = SSLContext.getInstance("TLS");
            context.init(null, null, null);
            internalSSLSocketFactory = context.getSocketFactory();
        }

        @Override
        public String[] getDefaultCipherSuites() {
            return internalSSLSocketFactory.getDefaultCipherSuites();
        }

        @Override
        public String[] getSupportedCipherSuites() {
            return internalSSLSocketFactory.getSupportedCipherSuites();
        }

        @Override
        public Socket createSocket() throws IOException {
            return enableTLSOnSocket(internalSSLSocketFactory.createSocket());
        }

        @Override
        public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
            return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose));
        }

        @Override
        public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
            return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
        }

        @Override
        public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
            return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort));
        }

        @Override
        public Socket createSocket(InetAddress host, int port) throws IOException {
            return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
        }

        @Override
        public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
            return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort));
        }

        private Socket enableTLSOnSocket(Socket socket) {
            if (socket != null && (socket instanceof SSLSocket)) {
                ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.1", "TLSv1.2"});
            }
            return socket;
        }
    }
}

It calls TLSSocketFactory class and then no outcome. Can anybody help me to fix this?

No reference please.

Fresco
  • 343
  • 3
  • 13

1 Answers1

0

It seems you have only new TLS version support configured on your server. Some Android 4.4.4 devices do not support TLS 1.2: https://github.com/ssllabs/ssllabs-scan/issues/258

You need to enable support of older TLS versions (TLS 1.1 for example) on your webserver.

Anton Malyshev
  • 8,686
  • 2
  • 27
  • 45
  • Here is it: `com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.` – Fresco Feb 19 '18 at 15:32
  • Probably it just can't verify the server certificate then, look at https://stackoverflow.com/questions/6825226/trust-anchor-not-found-for-android-ssl-connection – Anton Malyshev Feb 19 '18 at 15:35