Disabling Certificate Validation in an HTTPS Connection : HTTPS « Security « Java Tutorial






import java.net.URL;
import java.security.cert.X509Certificate;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class Main {
  public static void main(String[] argv) throws Exception {
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
        return null;
      }

      public void checkClientTrusted(X509Certificate[] certs, String authType) {
      }

      public void checkServerTrusted(X509Certificate[] certs, String authType) {
      }
    } };

    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

    URL url = new URL("https://hostname/index.html");
  }
}








36.45.HTTPS
36.45.1.HTTPS Client
36.45.2.HTTPS Server
36.45.3.HTTPS Server using the JSSE
36.45.4.Certification for HTTPS
36.45.5.HTTPS Server Proxy
36.45.6.Use HTTPS Server to transfer File
36.45.7.HTTPS Server Authentication
36.45.8.Https Socket Client
36.45.9.Disabling Certificate Validation in an HTTPS Connection