Ksoap2 ile SSL connection

Merhabalar yaptıgım bir uygulamada ssl baglantısı kurmam gerekıyor kullandıgım webservice, soap oldugu için ksoap2 kutuphanesini kullanıyorum. Internette araştırdım ama düzgün bir kaynaga ulaşamadım elinizde ksoap ile ssl connection yapabilcegimi anlatan bir döküman var mı ya da ksoap olmak zorunda degıl baska bir yöntem varsa bildiğiniz onuda uygulayabilirim. Teşekkurler

    0

    Gorkem Karadogan

    29 Nisan 2014

    
    
    
    	/*-----Below code is for trust connection with ssl-------*/
    	  final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
    	     public boolean verify(String hostname, SSLSession session) {
    	       return true;
    	     }
    	   };
    
    
    	   private static void trustAllHosts()
    	   {
    	     // Create a trust manager that does not validate certificate chains
    	     TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager()
    	     {
    	       public java.security.cert.X509Certificate[] getAcceptedIssuers()
    	       {
    	         return new java.security.cert.X509Certificate[]{};
    	       }
    
    
    	       public void checkClientTrusted(X509Certificate[] chain,
    	                       String authType) throws CertificateException {
    	       }
    
    
    	       public void checkServerTrusted(X509Certificate[] chain,
    	                       String authType) throws CertificateException {
    	       }
    	     }};
    
    
    	     // Install the all-trusting trust manager
    	     try {
    	       SSLContext sc = SSLContext.getInstance("TLS");
    	       sc.init(null, trustAllCerts, new java.security.SecureRandom());
    	       HttpsURLConnection
    	           .setDefaultSSLSocketFactory(sc.getSocketFactory());
    	     } catch (Exception e) {
    	       e.printStackTrace();
    	     }
    	   }
    	 
    	 
    	  private static TrustManager[] trustManagers;
    
    
    	   public static class _FakeX509TrustManager implements
    	       javax.net.ssl.X509TrustManager {
    	     private static final X509Certificate[] _AcceptedIssuers =
    	         new X509Certificate[]{};
    
    
    	     public void checkClientTrusted(X509Certificate[] arg0, String arg1)
    	         throws CertificateException {
    	     }
    
    
    	     public void checkServerTrusted(X509Certificate[] arg0, String arg1)
    	         throws CertificateException {
    	     }
    
    
    	     public boolean isClientTrusted(X509Certificate[] chain) {
    	       return (true);
    	     }
    
    
    	     public boolean isServerTrusted(X509Certificate[] chain) {
    	       return (true);
    	     }
    
    
    	     public X509Certificate[] getAcceptedIssuers() {
    	       return (_AcceptedIssuers);
    	     }
    	   }
    	   
    	   public static void allowAllSSL() {
    
    
    	     javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new
    	         HostnameVerifier() {
    	           public boolean verify(String hostname, SSLSession
    	               session) {
    	             return true;
    	           }
    	         });
    
    
    	     javax.net.ssl.SSLContext context = null;
    
    
    	     if (trustManagers == null) {
    	       trustManagers = new javax.net.ssl.TrustManager[]{new
    	           _FakeX509TrustManager()};
    	     }
    
    
    	     try {
    	       context = javax.net.ssl.SSLContext.getInstance("TLS");
    	       context.init(null, trustManagers, new SecureRandom());
    	     } catch (NoSuchAlgorithmException e) {
    
    
    	     } catch (KeyManagementException e) {
    
    
    	     }
    
    
    	     javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
    	   }
    	  /*---------------End code for ssl trust connection--------*/
    
    
    	

    Bu soruya cevap vermek için üye olmanız veya giriş yapmanız gerekmektedir.