Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help ! ! ! ! ! ! com.android.org.conscrypt.OpenSSLSessionImpl cannot be cast to com.android.org.conscrypt.SSLSessionImpl #363

Closed
SteveMobile opened this issue Jan 7, 2016 · 5 comments

Comments

@SteveMobile
Copy link

Help ! ! ! ! ! !
java.lang.ClassCastException: com.android.org.conscrypt.OpenSSLSessionImpl cannot be cast to com.android.org.conscrypt.SSLSessionImpl
01-07 21:22:40.320 29089-31249/com.ringcentral.glip W/System.err: at com.android.org.conscrypt.ClientHandshakeImpl.findSessionToResume(ClientHandshakeImpl.java:596)
01-07 21:22:40.320 29089-31249/com.ringcentral.glip W/System.err: at com.android.org.conscrypt.ClientHandshakeImpl.start(ClientHandshakeImpl.java:74)
01-07 21:22:40.320 29089-31249/com.ringcentral.glip W/System.err: at com.android.org.conscrypt.SSLEngineImpl.beginHandshake(SSLEngineImpl.java:118)
01-07 21:22:40.320 29089-31249/com.ringcentral.glip W/System.err: at com.android.org.conscrypt.SSLEngineImpl.wrap(SSLEngineImpl.java:587)
01-07 21:22:40.320 29089-31249/com.ringcentral.glip W/System.err: at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:462)
01-07 21:22:40.320 29089-31249/com.ringcentral.glip W/System.err: at org.java_websocket.SSLSocketChannel2.wrap(SSLSocketChannel2.java:141)
01-07 21:22:40.320 29089-31249/com.ringcentral.glip W/System.err: at org.java_websocket.SSLSocketChannel2.(SSLSocketChannel2.java:74)
01-07 21:22:40.330 29089-31249/com.ringcentral.glip W/System.err: at org.java_websocket.client.DefaultSSLWebSocketClientFactory.wrapChannel(DefaultSSLWebSocketClientFactory.java:40)
01-07 21:22:40.330 29089-31249/com.ringcentral.glip W/System.err: at org.java_websocket.client.WebSocketClient.interruptableRun(WebSocketClient.java:242)
01-07 21:22:40.330 29089-31249/com.ringcentral.glip W/System.err: at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:219)
01-07 21:22:40.330 29089-31249/com.ringcentral.glip W/System.err: at java.lang.Thread.run(Thread.java:841)

the code
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}

        public void checkClientTrusted(X509Certificate[] chain,
                                       String authType) throws CertificateException {
        }

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

    KeyManager[] keyManager = null;
    try {
        final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        factory.init(keyStore, null);
        keyManager = factory.getKeyManagers();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnrecoverableKeyException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    }

    try {
        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManager, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
        SocketIO.setDefaultSSLSocketFactory(sslContext);
    } catch (Exception e) {
        e.printStackTrace();
    }
@SteveMobile
Copy link
Author

I'm check the android source code ,ClientHandshakeImpl :
private SSLSessionImpl findSessionToResume() ,
ClientSessionContext context = parameters.getClientSessionContext();
SSLSessionImpl session= (SSLSessionImpl) context.getSession(host, port);

context.getSession(host, port) //return opensslsessionimpl , how to change the session to sslsessionimpl

@vinod1054
Copy link

same problem with me

@marci4
Copy link
Collaborator

marci4 commented Apr 15, 2017

Hello @SteveMobile and @vinod1054,

is this still an issue with the current version 1.3.2?

Greetings
marci4

@marci4
Copy link
Collaborator

marci4 commented Sep 6, 2017

No update for months.
Closing issue!

Greetings
marci4

@marci4 marci4 closed this as completed Sep 6, 2017
@sanat51289
Copy link

sanat51289 commented Apr 15, 2019

@marci4 I'm seeing this issue as well, when I use your library on Android SDK 19 (Which doesnt support TLS 1.2 by default). I have tried enabling TLS 1.2 as well but it doesnt seem to work.
It happens when we call the wrap method from the constructor of SSLSocketChannel2 which then calls wrap on sslEngine

    private synchronized ByteBuffer wrap(ByteBuffer b) throws SSLException {
        this.outCrypt.compact();
        **this.engineResult = this.sslEngine.wrap(b, this.outCrypt);**
        this.outCrypt.flip();
        return this.outCrypt;
    }

Any suggestions on how to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants