Handshake fail on Lollipop

最后都变了- 提交于 2019-12-03 21:26:44

I had the same problem. I found a link https://code.google.com/p/android/issues/detail?id=88313 where I found a code:

public class MySSLSocketFactory extends SSLSocketFactory {
        SSLContext sslContext = SSLContext.getInstance("TLS");

        ...

        @Override
        public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
            final SSLSocket sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
            sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
            return sslSocket;
        }

        @Override
        public Socket createSocket() throws IOException {
            final SSLSocket sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket();
            sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
            return sslSocket;
        }
}

You can use code of MySSLSocketFactory from the link you've provided but you need to override two methods createSocket as I've wrote above. Also it's not the best solution you can have some security issue later, because for connection it can use some old cipher algorithm.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!