Guest User

Untitled

a guest
Nov 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. class TLS12SocketFactory extends SSLSocketFactory {
  2.  
  3. public static final String TLS_1_2 = "TLSv1.2";
  4.  
  5. private static final String[] TLS_1_2_ONLY = { TLS_1_2 };
  6.  
  7. private final SSLSocketFactory delegate;
  8.  
  9. public TLS12SocketFactory(SSLSocketFactory base) {
  10. this.delegate = base;
  11. }
  12.  
  13. @Override
  14. public String[] getDefaultCipherSuites() {
  15. return delegate.getDefaultCipherSuites();
  16. }
  17.  
  18. @Override
  19. public String[] getSupportedCipherSuites() {
  20. return delegate.getSupportedCipherSuites();
  21. }
  22.  
  23. @Override
  24. public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
  25. return patch(delegate.createSocket(s, host, port, autoClose));
  26. }
  27.  
  28. @Override
  29. public Socket createSocket(String host, int port) throws IOException {
  30. return patch(delegate.createSocket(host, port));
  31. }
  32.  
  33. @Override
  34. public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
  35. throws IOException {
  36. return patch(delegate.createSocket(host, port, localHost, localPort));
  37. }
  38.  
  39. @Override
  40. public Socket createSocket(InetAddress host, int port) throws IOException {
  41. return patch(delegate.createSocket(host, port));
  42. }
  43.  
  44. @Override
  45. public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
  46. throws IOException {
  47. return patch(delegate.createSocket(address, port, localAddress, localPort));
  48. }
  49.  
  50. private Socket patch(Socket s) {
  51. if (s instanceof SSLSocket) ((SSLSocket) s).setEnabledProtocols(TLS_1_2_ONLY);
  52. return s;
  53. }
  54. }
Add Comment
Please, Sign In to add comment