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