SSL Connection Error While making a connection

1

I am totally new on this and after some research, trying to make a SSL/TLS connection with server to allow SOAP call outside defined network. I am using OKHttp3 library to make the call and sharing a .P12 file with private key and setting a SSL Socket Factory as shown below

setupKeyCert(context);    
 final OkHttpClient client = new OkHttpClient();
    client.newBuilder()
            .connectTimeout(30, TimeUnit.SECONDS)
            .sslSocketFactory(sslContext.getSocketFactory(), mainX509TrustManager);

and setting keystone and Trust Manager in

setupKeyCert()

as

try {
            KeyStore keyStore = KeyStore.getInstance("PKCS12");
            KeyManagerFactory keyManagerFactory = null;
            if(buildEnvironment == "prod")
            {
                keyStore.load(context.getAssets().open(Constants.CERT_PROD_FILE), password);

                keyManagerFactory = KeyManagerFactory.getInstance("X509");
                keyManagerFactory.init(keyStore, Constants.CERT_PROD_VALUE.toCharArray());

            } else
            {
                keyStore.load(context.getAssets().open(Constants.CERT_FILE), Constants.CERT_VALUE.toCharArray());
                keyManagerFactory = KeyManagerFactory.getInstance("X509");
                keyManagerFactory.init(keyStore, Constants.CERT_VALUE.toCharArray());
            }
            KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();

            //Adding TrustManagerFactory
            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init(keyStore);
            TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
            if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
                throw new IllegalStateException("Unexpected default trust managers:"
                        + Arrays.toString(trustManagers));
            }
            mainX509TrustManager = (X509TrustManager) trustManagers[0];


            sslContext = SSLContext.getInstance("TLSv1.2");
            sslContext.init(keyManagers, null, null);
        } catch (FileNotFoundException f)
        {
            Log.e("Excption File", String.valueOf(f));
        } catch (Exception i)
        {
            Log.e(TAG, "Exception", i);
        }

Where Constant.CERT_PROD_FILE refers to constant string which contain file name. When debugging or making call, I am getting below error

javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x8a163cc0: Failure in SSL library, usually a protocol error error:10000410:SSL routines:OPENSSL_internal:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:610 0x9f7e3d00:0x00000001)

I am not sure what am I missing and I have tried different solution including bug related to android 7 issue but it's still not working. I tried to debug and can only see the above error, so not sure if the issue is with server or client. Thanks for help in advance.

android
ssl
tls1.2
okhttp3
asked on Stack Overflow Oct 17, 2018 by Julian

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0