1 5 6 package com.sun.enterprise.tools.admingui.util; 7 8 import java.security.NoSuchAlgorithmException ; 9 import java.security.KeyManagementException ; 10 11 import javax.net.ssl.HttpsURLConnection; 12 import java.security.cert.X509Certificate ; 13 import javax.net.ssl.SSLContext; 14 import javax.net.ssl.HostnameVerifier; 15 import javax.net.ssl.SSLSession; 16 import javax.net.ssl.X509TrustManager; 17 18 import com.sun.appserv.management.client.TrustAnyTrustManager; 19 20 21 27 public class JSSE { 28 29 60 public static void trustAnyServerCertificate() throws NoSuchAlgorithmException , KeyManagementException { 61 SSLContext sslc = SSLContext.getInstance("SSLv3"); 62 final X509TrustManager[] tms = TrustAnyTrustManager.getInstanceArray(); 63 sslc.init(null, tms, null); 64 if (sslc != null) { 65 HttpsURLConnection.setDefaultSSLSocketFactory(sslc.getSocketFactory()); 66 } 67 if(HttpsURLConnection.getDefaultHostnameVerifier() instanceof AcceptAnyHostName) { 68 return; 69 } 70 HostnameVerifier hv = new AcceptAnyHostName(); 71 HttpsURLConnection.setDefaultHostnameVerifier(hv); 72 } 73 74 private static class AcceptAnyHostName implements HostnameVerifier{ 75 public boolean verify(String s, SSLSession ssl) { 76 return true; 77 } 78 } 79 80 81 } 82 | Popular Tags |