2

I have an app which connect to a SOAP webservice through a https connection by using KSOAP2 library.

Now I am accepting all certificates with following code:

public static void createTrustManager(){
    TrustManager[] trustAllCerts = createTrustAllCerts();

    // Install the all-trusting trust manager
    try{       
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    }
    catch (NoSuchAlgorithmException exception){}
    catch (KeyManagementException exception){}
}

public static TrustManager[] createTrustAllCerts() {
    // Create a trust manager that does not validate certificate chains
    X509TrustManager trustManager = createX509TrustManager();
    return new TrustManager[]{trustManager};
}

public static X509TrustManager createX509TrustManager() {
    X509TrustManager trustManager = new X509TrustManager(){
        public X509Certificate[] getAcceptedIssuers() { 

            return null; 

        }
        public void checkClientTrusted(X509Certificate[] certs, String authType) { SSLUtilities.checkClientTrusted = true;}
        public void checkServerTrusted(X509Certificate[] certs, String authType) { SSLUtilities.checkServerTrusted = true;}
    };
    return trustManager;
}

But now I need to only consider certificate involving the https connection I have. I didn't find how to solve it. Can someone help me?

0 Answers0