Android Client / Server on TLS v1.2

后端 未结 1 432
再見小時候
再見小時候 2021-02-02 05:03

I\'m trying my to create TLS v1.2 communication between a server and android client. I established a TLS v1.0 connection with any problem, but I cannot get v1.2. This is server

相关标签:
1条回答
  • 2021-02-02 05:13

    Kind of late to be answering this, but maybe someone else will need an answer.

    I have run into the same issue. No matter whether you provide TLSv1.2 to the SSLContext.init() method, some Android versions that I've tried do not enable TLS 1.2. You must enable that on your client socket using setEnabledProtocols() just as you do for your server socket. For me, I did this in a custom SSLSocketFactory I created:

    public class MySSLSocketFactory extends SSLSocketFactory
                                    throws NoSuchAlgorithmException {
    
        private SSLContext mSSLContext;
    
        public MySSLSocketFactory(KeyManager km) {
            ...
            mSSLContext = SSLContext.getInstance("TLSv1.2");
            ...
            mSSLContext.init(new KeyManager[] {km}, null, null);
            ...
        }
    
        @Override
        public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
                        throws IOException {
            SSLSocket s = (SSLSocket)mSSLContext.getSocketFactory().createSocket(socket, host, port, autoClose);
            s.setEnabledProtocols(new String[] {"TLSv1.2"} );
            return s;
        }
    
        ...
    }
    
    0 讨论(0)
提交回复
热议问题