0

It is spring based web app, using below method to accept all SSL certificates. This method works and I get results back,but it does not seems great. Please suggest. The endpoint( url) SSL has a verisign certificate)

private void prepareHttpsConnnection() throws NoSuchAlgorithmException,
            KeyManagementException {
        System.setProperty("https.proxyHost", proxyHost);
        System.setProperty("https.proxyPort", proxyPort);
        System.setProperty("jsse.enableSNIExtension", enableSNIExte`enter code here`nsion);
        SSLContext sslContext;

        sslContext = SSLContext.getInstance("SSL");

        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                // System.out.println("getAcceptedIssuers =============");
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs,
                    String authType) {
                // System.out.println("checkClientTrusted =============");
            }

            public void checkServerTrusted(X509Certificate[] certs,
                    String authType) {
                // System.out.println("checkServerTrusted =============");
            }
        } }, new SecureRandom());

        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext
                .getSocketFactory());

        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        });

    }
Java User
  • 127
  • 3
  • 9
  • possible duplicate of [Trusting all certificates using HttpClient over HTTPS](http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https) – Nathan Tuggy Apr 07 '15 at 01:36
  • 1
    If the endpoint you are calling has a verisign certification, none of the TrustManager, ssl socket factory or host name verifier code should be necessary. The jre trusts "public" keystores by default. – Brett Okken Apr 07 '15 at 03:21

0 Answers0