2

In my application, I have integrated two libraries i.e. chat and video calling...The problem is when I open video library first, then both chat and video calling libraries are working fine but when I open the chat library first, and then open the video, it leads to an exception...I think it is a problem with sockets with default trustmangers..

Sample code I am using in video calling library to create sslcontext

trustManagers = new TrustManager[]{new X509TrustManager() {
                @Override
                public void checkClientTrusted(X509Certificate[] chain, String authType)
                        throws CertificateException {
                }

                @Override
                public void checkServerTrusted(X509Certificate[] chain, String authType)
                        throws CertificateException {
                }

                @Override
                public X509Certificate[] getAcceptedIssuers() {
                    return new X509Certificate[0];
                   }
                }
            };

            try {

                sslContext = SSLContext.getInstance("TLS");
                sslContext.init(null, trustManagers, null);
            } catch (NoSuchAlgorithmException | KeyManagementException e) {
                e.printStackTrace();
            }

The exception I got this: java.lang.IllegalStateException: Unable to extract the trust manager on AndroidPlatform, sslSocketFactory is class org.conscrypt.OpenSSLSocketFactoryImpl...Please help any one.

A_C
  • 905
  • 6
  • 18
raviteja
  • 67
  • 1
  • 13

1 Answers1

1

In my case it happened on emulator API 16 when I used https://stackoverflow.com/a/50264472/2914140 in this way:

val sslcontext: SSLContext = SSLContext.getInstance("TLSv1.2")
sslcontext.init(null, null, null)
val tlsSocketFactory = TLSSocketFactory()

val okHttpClient = OkHttpClient().newBuilder()
    .sslSocketFactory(tlsSocketFactory)
    .build()

When I add a trustManager parameter to sslSocketFactory method, the exception disappears. But a problem with SSL connection doesn't disappear.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • have you found a solution ? I'm in the same situation – Wael Fadl Ãllåh Mar 30 '20 at 08:26
  • @WaelFadlÃllåh, sorry, I removed a similar code from the application, because a system administrator fixed an issue on a server (as I understood, he fixed a certificate chain). But I can see what did before. When the problem appeared, I couldn't launch requests and couldn't download images with Glade. – CoolMind Mar 30 '20 at 09:29
  • @WaelFadlÃllåh, in my case another problem happened, see https://stackoverflow.com/a/60507560/2914140. Also I see that https://stackoverflow.com/a/51285550/2914140 and https://stackoverflow.com/a/50640113/2914140 helped me (a year ago), but later I removed https://stackoverflow.com/a/50640113/2914140. – CoolMind Mar 30 '20 at 09:37
  • 3
    @WaelFadlÃllåh, so, in the first link (https://stackoverflow.com/a/60507560/2914140) I wrote: `.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)`. – CoolMind Mar 30 '20 at 09:51
  • can you point me to where I can study more about this matter ( sslSocketFactory)in depth – Wael Fadl Ãllåh Mar 30 '20 at 10:10
  • @WaelFadlÃllåh, sorry, I don't know, maybe https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/ssl-socket-factory/ or https://stackoverflow.com/questions/31002159/now-that-sslsocketfactory-is-deprecated-on-android-what-would-be-the-best-way-t can help. – CoolMind Mar 30 '20 at 11:32