Advertisement
udaffka

Untitled

Sep 22nd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public static class miTM implements TrustManager, X509TrustManager {
  2.  
  3. public X509Certificate[] getAcceptedIssuers() {
  4. return null;
  5. }
  6.  
  7. public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) {
  8. return true;
  9. }
  10.  
  11. public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) {
  12. return true;
  13. }
  14.  
  15. public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
  16. throws CertificateException {
  17. return;
  18. }
  19.  
  20. public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
  21. throws CertificateException {
  22. return;
  23. }
  24. }
  25.  
  26. private static HostnameVerifier hv = new HostnameVerifier() {
  27.  
  28. @Override
  29. public boolean verify(String arg0, SSLSession arg1) {
  30. return true;
  31. }
  32. };
  33.  
  34. private static void trustAllHttpsCertificates() throws Exception {
  35.  
  36. TrustManager[] trustAllCerts = new TrustManager[1];
  37. trustAllCerts[0] = new miTM();
  38.  
  39. SSLContext sc = SSLContext.getInstance("GostTLS");
  40.  
  41. sc.init(null, trustAllCerts, null);
  42.  
  43. HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  44. HttpsURLConnection.setDefaultHostnameVerifier(hv);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement