Advertisement
Guest User

Untitled

a guest
Aug 20th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2015 RDX
  3.  *
  4.  * This program is free software: you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation, either version 3 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17. package neembuu.uploader.utils;
  18.  
  19. /**
  20.  *
  21.  * @author Paralytic
  22.  */
  23.  
  24. import javax.net.ssl.*;
  25. import java.security.cert.CertificateException;
  26. import java.security.cert.X509Certificate;
  27. import javax.net.ssl.HttpsURLConnection;
  28.  
  29. public class SSLCertificateValidation {
  30.  
  31.     public static void disable() {
  32.         try {
  33.             SSLContext sslc = SSLContext.getInstance("TLS");
  34.             TrustManager[] trustManagerArray = { new NullX509TrustManager() };
  35.             sslc.init(null, trustManagerArray, null);
  36.             HttpsURLConnection.setDefaultSSLSocketFactory(sslc.getSocketFactory());
  37.             HttpsURLConnection.setDefaultHostnameVerifier(new NullHostnameVerifier());
  38.         } catch(Exception e) {
  39.             e.printStackTrace();
  40.         }
  41.     }
  42.  
  43.     private static class NullX509TrustManager implements X509TrustManager {
  44.         public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  45.             System.out.println();
  46.         }
  47.         public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  48.             System.out.println();
  49.         }
  50.         public X509Certificate[] getAcceptedIssuers() {
  51.             return new X509Certificate[0];
  52.         }
  53.     }
  54.  
  55.     private static class NullHostnameVerifier implements HostnameVerifier {
  56.         public boolean verify(String hostname, SSLSession session) {
  57.             return true;
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement