|
| 1 | +package io.flutter.plugins.videoplayer; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.net.InetAddress; |
| 5 | +import java.net.Socket; |
| 6 | +import java.security.KeyManagementException; |
| 7 | +import java.security.NoSuchAlgorithmException; |
| 8 | +import javax.net.ssl.SSLContext; |
| 9 | +import javax.net.ssl.SSLSocket; |
| 10 | +import javax.net.ssl.SSLSocketFactory; |
| 11 | + |
| 12 | +public class CustomSSLSocketFactory extends SSLSocketFactory { |
| 13 | + private SSLSocketFactory sslSocketFactory; |
| 14 | + |
| 15 | + public CustomSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException { |
| 16 | + SSLContext context = SSLContext.getInstance("TLS"); |
| 17 | + context.init(null, null, null); |
| 18 | + sslSocketFactory = context.getSocketFactory(); |
| 19 | + } |
| 20 | + |
| 21 | + @Override |
| 22 | + public String[] getDefaultCipherSuites() { |
| 23 | + return sslSocketFactory.getDefaultCipherSuites(); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public String[] getSupportedCipherSuites() { |
| 28 | + return sslSocketFactory.getSupportedCipherSuites(); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public Socket createSocket() throws IOException { |
| 33 | + return enableProtocols(sslSocketFactory.createSocket()); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public Socket createSocket(Socket s, String host, int port, boolean autoClose) |
| 38 | + throws IOException { |
| 39 | + return enableProtocols(sslSocketFactory.createSocket(s, host, port, autoClose)); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public Socket createSocket(String host, int port) throws IOException { |
| 44 | + return enableProtocols(sslSocketFactory.createSocket(host, port)); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public Socket createSocket(String host, int port, InetAddress localHost, int localPort) |
| 49 | + throws IOException { |
| 50 | + return enableProtocols(sslSocketFactory.createSocket(host, port, localHost, localPort)); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public Socket createSocket(InetAddress host, int port) throws IOException { |
| 55 | + return enableProtocols(sslSocketFactory.createSocket(host, port)); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) |
| 60 | + throws IOException { |
| 61 | + return enableProtocols(sslSocketFactory.createSocket(address, port, localAddress, localPort)); |
| 62 | + } |
| 63 | + |
| 64 | + private Socket enableProtocols(Socket socket) { |
| 65 | + if (socket instanceof SSLSocket) { |
| 66 | + ((SSLSocket) socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"}); |
| 67 | + } |
| 68 | + return socket; |
| 69 | + } |
| 70 | +} |
0 commit comments