1

I have created my own SSLSocketFactory as explained in this question

private SSLSocketFactory newSslSocketFactory() {
    try {
        // Get an instance of the Bouncy Castle KeyStore format
        KeyStore trusted = KeyStore.getInstance("BKS");
        // Get theraw resource, which contains the keystore with
        // your trusted certificates (root and any intermediate certs)
        Context context = this.activity;
        Resources _resources = context.getResources();
        InputStream in = _resources.openRawResource(R.raw.mystore);
        try {
            // Initialize the keystore with the provided trusted certificates
            // Also provide the password of the keystore
            trusted.load(in, "mypassword".toCharArray());
        } finally {
            in.close();
        }
        // Pass the keystore to the SSLSocketFactory. The factory is responsible
        // for the verification of the server certificate.
        SSLSocketFactory sf = new SSLSocketFactory(trusted);
        // Hostname verification from certificate

        sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
        return sf;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}

Actually i need to set this SSLSocketFactory on the HttpsURLConnection before connecting. But when i try to set it on HttpsURLConnection by calling

(HttpsURLConnection )connection.setSSLSocketFactory(trusted); 

At this point am facing cast class error between 2 packages org.apache.http.conn.ssl.SSLSocketFactory and javax.net.ssl.SSLSocketFactory.

How to solve this?

Community
  • 1
  • 1
Tajpeer H
  • 11
  • 2

1 Answers1

0

Am not getting any exception with the above piece of code.

But the problem is that, when am trying to set the SSLSocketFactory on the HttpsURLConnection using:

(HttpsURLConnection )connection.setSSLSocketFactory(trusted) 

It is showing "The method setSSLSocketFactory(SSLSocketFactory) in the type HttpsURLConnection is not applicable for the arguments(SSLSocketFactory)".

Because the method setSSLSocketFactory is there in both the packages.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
Tajpeer H
  • 11
  • 2